# Get Blog posts by Blog ID

GET https://services.leadconnectorhq.com/blogs/posts/all

The "Get Blog posts by Blog ID" API returns the blog posts for a given blog site. Use searchTerm to search across post title, description, url slug and category name.

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `blogs/posts.readonly`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | Yes | Sub-account (location) identifier whose posts are being listed |
| `limit` | number | Yes | Maximum number of records to return (0-50) |
| `offset` | number | Yes | Number of records to skip for pagination |
| `searchTerm` | string | No | Free-text search across post title, description, url slug and category name |
| `status` | string | No | Filter by publication status |
| `blogId` | string | Yes | Identifier of the blog site whose posts are being listed |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "HighLevel API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/blogs/posts/all": {
      "get": {
        "summary": "Get Blog posts by Blog ID",
        "operationId": "getBlogPostsByBlogId",
        "description": "The \"Get Blog posts by Blog ID\" API returns the blog posts for a given blog site. Use searchTerm to search across post title, description, url slug and category name.",
        "parameters": [
          {
            "name": "locationId",
            "required": true,
            "in": "query",
            "description": "Sub-account (location) identifier whose posts are being listed",
            "schema": {
              "example": "ve9EPM428h8vShlRW1KT",
              "type": "string"
            }
          },
          {
            "name": "limit",
            "required": true,
            "in": "query",
            "description": "Maximum number of records to return (0-50)",
            "schema": {
              "example": 10,
              "type": "number"
            }
          },
          {
            "name": "offset",
            "required": true,
            "in": "query",
            "description": "Number of records to skip for pagination",
            "schema": {
              "example": 0,
              "type": "number"
            }
          },
          {
            "name": "searchTerm",
            "required": false,
            "in": "query",
            "description": "Free-text search across post title, description, url slug and category name",
            "schema": {
              "example": "marketing",
              "type": "string"
            }
          },
          {
            "name": "status",
            "required": false,
            "in": "query",
            "description": "Filter by publication status",
            "schema": {
              "example": "PUBLISHED",
              "enum": [
                "ALL",
                "DRAFT",
                "PUBLISHED",
                "SCHEDULED",
                "SCHEDULE_FAILED",
                "ARCHIVED",
                "DELETED"
              ],
              "type": "string"
            }
          },
          {
            "name": "blogId",
            "required": true,
            "in": "query",
            "description": "Identifier of the blog site whose posts are being listed",
            "schema": {
              "example": "lMOzIQZne5m6zQ528sT6",
              "type": "string"
            }
          },
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BlogPostGetResponseWrapperDTO"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NotFoundDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "Location-Access": [
              "blogs/posts.readonly"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency (OR) Private Integration Token of Agency.",
        "type": "http"
      },
      "Agency-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "BlogPostGetResponseWrapperDTO": {
        "type": "object",
        "properties": {
          "blogs": {
            "description": "Blog posts matching the query",
            "example": [
              {
                "_id": "66c381b38be80858b9af62b6",
                "title": "How to grow your agency",
                "status": "PUBLISHED"
              }
            ],
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "categories": {
                  "example": [
                    "659ecabc4a37969a2b7cc370",
                    "6683abde331c041f32c07aee"
                  ],
                  "description": "Array of category IDs associated with the blog post",
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "tags": {
                  "example": [
                    "Apple",
                    "Banana"
                  ],
                  "description": "Array of tags associated with the blog post",
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "archived": {
                  "type": "boolean",
                  "example": false,
                  "description": "Indicates whether the blog post is archived"
                },
                "_id": {
                  "type": "string",
                  "example": "66c381b38be80858b9af62b6",
                  "description": "Unique identifier of the blog post"
                },
                "title": {
                  "type": "string",
                  "example": "Banana is good source of energy",
                  "description": "Title of the blog post"
                },
                "description": {
                  "type": "string",
                  "example": "Description",
                  "description": "Description of the blog post"
                },
                "imageUrl": {
                  "type": "string",
                  "example": "https://storage.googleapis.com/blog-assets/fACm0Ojm5oC70G3DcFmE/media/66b5aa3b1745b2713a8d033f.jpeg",
                  "description": "URL of the image associated with the blog post"
                },
                "status": {
                  "type": "string",
                  "example": "PUBLISHED",
                  "description": "Publication status of the blog post"
                },
                "locationId": {
                  "type": "string",
                  "example": "fACm0Ojm5oC70G3DcFmE",
                  "description": "Identifier of the location associated with the blog post"
                },
                "imageAltText": {
                  "type": "string",
                  "example": "alt",
                  "description": "Alternative text for the blog post image"
                },
                "blogId": {
                  "type": "string",
                  "example": "ZiMMOp3ZEdnsZ4qPAjW0",
                  "description": "Unique identifier of the blog"
                },
                "urlSlug": {
                  "type": "string",
                  "example": "banana-good-energy",
                  "description": "URL slug for the blog post"
                },
                "canonicalLink": {
                  "type": "string",
                  "example": "https://blog.example.com/post/test-8384",
                  "description": "Canonical link of the blog post"
                },
                "author": {
                  "type": "string",
                  "example": "659ec9634a3796e4e47cc360",
                  "description": "Identifier of the author of the blog post"
                },
                "publishedAt": {
                  "type": "string",
                  "example": "2024-08-19T17:14:57.000Z",
                  "description": "Timestamp when the blog post was published"
                },
                "createdAt": {
                  "type": "string",
                  "example": "2024-08-19T17:32:35.362Z",
                  "description": "Timestamp when the blog post was created"
                },
                "updatedAt": {
                  "type": "string",
                  "example": "2024-08-19T17:32:36.182Z",
                  "description": "Timestamp when the blog post was last updated"
                },
                "currentVersion": {
                  "type": "string",
                  "example": "66c381b38be80858b9af62b7",
                  "description": "Identifier of the current version of the blog post"
                },
                "isAiGenerated": {
                  "type": "boolean",
                  "example": false,
                  "description": "Indicates whether the blog post was generated using AI assistance"
                },
                "isAIGenerated": {
                  "type": "boolean",
                  "example": false,
                  "description": "Deprecated. Use `isAiGenerated` instead. Kept for backwards compatibility.",
                  "deprecated": true
                }
              },
              "required": [
                "categories",
                "tags",
                "archived",
                "_id",
                "title",
                "description",
                "imageUrl",
                "status",
                "locationId",
                "imageAltText",
                "blogId",
                "urlSlug",
                "canonicalLink",
                "author",
                "publishedAt",
                "createdAt",
                "updatedAt",
                "currentVersion",
                "isAiGenerated",
                "isAIGenerated"
              ],
              "title": "BlogPostResponseDTO"
            }
          },
          "count": {
            "type": "number",
            "description": "Total number of blog posts matching the query, ignoring limit/offset",
            "example": 42
          }
        },
        "required": [
          "blogs",
          "count"
        ],
        "title": "BlogPostGetResponseWrapperDTO"
      },
      "BadRequestDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 400
          },
          "message": {
            "type": "string",
            "example": "Bad Request"
          }
        },
        "title": "BadRequestDTO"
      },
      "UnauthorizedDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 401
          },
          "message": {
            "type": "string",
            "example": "Invalid token: access token is invalid"
          },
          "error": {
            "type": "string",
            "example": "Unauthorized"
          }
        },
        "title": "UnauthorizedDTO"
      },
      "NotFoundDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "description": "HTTP status code for not found",
            "example": 404
          },
          "message": {
            "type": "string",
            "description": "Error message describing the not found failure",
            "example": "Not Found"
          },
          "error": {
            "type": "string",
            "description": "Error type identifier",
            "example": "The requested resource was not found"
          }
        },
        "title": "NotFoundDTO"
      }
    }
  }
}
```

## HighLevel SDK Examples

**Node.js** (`@gohighlevel/api-client`)

```javascript
import HighLevel from '@gohighlevel/api-client';

const ghl = new HighLevel({
  privateIntegrationToken: '<PRIVATE_INTEGRATION_TOKEN>'
});

const response = await ghl.blogs.getBlogPostsByBlogId({ locationId: '<LOCATIONID>', limit: '<LIMIT>', offset: '<OFFSET>', blogId: '<BLOGID>' });
console.log(response);
```

**Python** (`gohighlevel-api-client`)

```python
from highlevel import HighLevel

client = HighLevel(
    private_integration_token='<PRIVATE_INTEGRATION_TOKEN>'
)

response = await client.blogs.get_blog_posts_by_blog_id(locationId='<LOCATIONID>', limit='<LIMIT>', offset='<OFFSET>', blogId='<BLOGID>')
print(response)
```

**PHP** (`gohighlevel/api-client`)

```php
<?php
require_once 'vendor/autoload.php';

use HighLevel\HighLevel;
use HighLevel\HighLevelConfig;

$config = new HighLevelConfig([
    'privateIntegrationToken' => '<PRIVATE_INTEGRATION_TOKEN>'
]);
$ghl = new HighLevel($config);

$response = $ghl->blogs->getBlogPostsByBlogId(['locationId' => '<LOCATIONID>', 'limit' => '<LIMIT>', 'offset' => '<OFFSET>', 'blogId' => '<BLOGID>']);
echo json_encode($response, JSON_PRETTY_PRINT);
```

## Code Examples

**cURL**

```bash
curl -L -X GET 'https://services.leadconnectorhq.com/blogs/posts/all?locationId=<LOCATIONID>&limit=<LIMIT>&offset=<OFFSET>&blogId=<BLOGID>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3'
```

**Node.js**

```javascript
const options = {
  method: 'GET',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3'
  }
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/blogs/posts/all?locationId=<LOCATIONID>&limit=<LIMIT>&offset=<OFFSET>&blogId=<BLOGID>', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/blogs/posts/all"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

params = {
    "locationId": "<LOCATIONID>",
    "limit": "<LIMIT>",
    "offset": "<OFFSET>",
    "blogId": "<BLOGID>"
}

response = requests.get(url, params=params, headers=headers)
print(response.json())
```

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/blogs/posts/all?locationId=<LOCATIONID>&limit=<LIMIT>&offset=<OFFSET>&blogId=<BLOGID>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
  ],
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .get("https://services.leadconnectorhq.com/blogs/posts/all?locationId=<LOCATIONID>&limit=<LIMIT>&offset=<OFFSET>&blogId=<BLOGID>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
)

func main() {
  url := "https://services.leadconnectorhq.com/blogs/posts/all?locationId=<LOCATIONID>&limit=<LIMIT>&offset=<OFFSET>&blogId=<BLOGID>"
  req, _ := http.NewRequest("GET", url, nil)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/blogs/posts/all?locationId=<LOCATIONID>&limit=<LIMIT>&offset=<OFFSET>&blogId=<BLOGID>")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/blogs/posts/all?locationId=<LOCATIONID>&limit=<LIMIT>&offset=<OFFSET>&blogId=<BLOGID>' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
