# Get Accounts

GET https://services.leadconnectorhq.com/social-media-posting/{locationId}/accounts

Get list of accounts and groups

## Authentication

Send `Authorization: Bearer <token>` using:

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

## Parameters

### Header Parameters

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

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | Yes | Location Id |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/social-media-posting/{locationId}/accounts": {
      "get": {
        "summary": "Get Accounts",
        "operationId": "getAccounts",
        "description": "Get list of accounts and groups",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "locationId",
            "required": true,
            "in": "path",
            "description": "Location Id",
            "schema": {
              "example": "ve9EPM428h8vShlRW1KT",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountsListResponseDTO"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "422": {
            "description": "Unprocessable Entity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnprocessableDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "Location-Access": [
              "socialplanner/account.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": {
      "AccountsListResponseDTO": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "description": "Success or Failure",
            "example": true
          },
          "statusCode": {
            "type": "number",
            "description": "Status Code",
            "example": 200
          },
          "message": {
            "type": "string",
            "description": "Message",
            "example": "Fetched Accounts"
          },
          "results": {
            "description": "Requested Results",
            "example": {
              "accounts": [
                {
                  "id": "aF3KhyL8JIuBwzK3m7Ly_Lx1EI6YIgQYMQi0ytFXv_12554616564525983496",
                  "name": "Sample Account",
                  "platform": "google"
                }
              ],
              "groups": [
                {
                  "id": "6284c43d519161e96cc09c13",
                  "name": "Primary"
                }
              ]
            },
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "accounts": {
                    "description": "Array of connected social media accounts",
                    "example": [
                      {
                        "id": "aF3KhyL8JIuBwzK3m7Ly_Lx1EI6YIgQYMQi0ytFXv_12554616564525983496",
                        "name": "Sample Account",
                        "platform": "google",
                        "type": "location"
                      }
                    ],
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "Unique identifier for the connected account",
                          "example": "aF3KhyL8JIuBwzK3m7Ly_Lx1EI6YIgQYMQi0ytFXv_12554616564525983496"
                        },
                        "oauthId": {
                          "type": "string",
                          "description": "OAuth provider account identifier",
                          "example": "aF3KhyL8JIuBwzK3m7Ly"
                        },
                        "profileId": {
                          "type": "string",
                          "description": "Profile identifier from the social media platform",
                          "example": "aF3KhyL8JIuBwzK3m7Ly"
                        },
                        "name": {
                          "type": "string",
                          "description": "Display name of the account",
                          "example": "Sample Account"
                        },
                        "platform": {
                          "type": "string",
                          "description": "platform must be one of the following values: google, facebook, instagram, linkedin, tiktok",
                          "example": "google"
                        },
                        "type": {
                          "type": "string",
                          "description": "Type of account (e.g., location, page, profile)",
                          "example": "location"
                        },
                        "expire": {
                          "type": "string",
                          "description": "Token expiration date and time",
                          "example": "2024-03-11T19:29:59.785Z"
                        },
                        "isExpired": {
                          "type": "boolean",
                          "description": "Indicates if the account token has expired",
                          "example": false
                        },
                        "meta": {
                          "type": "object",
                          "description": "Additional metadata for the account",
                          "example": {
                            "hasGoogleUpdated": true,
                            "canDelete": true
                          }
                        },
                        "locationId": {
                          "type": "string",
                          "description": "Sub-account this connected account belongs to",
                          "example": "ve9EPM428h8vShlRW1KT"
                        },
                        "active": {
                          "type": "boolean",
                          "description": "Whether the connection is active. Unlike isExpired, this is the raw flag and does not fold in token expiry",
                          "example": true
                        },
                        "connectionSource": {
                          "type": "string",
                          "description": "Which service the account was connected through",
                          "example": "social_media_posting",
                          "enum": [
                            "integration",
                            "social_media_posting"
                          ]
                        },
                        "facebookIgnoreMessages": {
                          "type": "boolean",
                          "description": "Always true. Social Planner has no per-page setting to suppress direct-message sync, so this is a constant Integrations asked us to send rather than a field read off the account. Consumed by Integrations when mapping these accounts onto their own connected-page shape",
                          "example": true
                        }
                      },
                      "title": "GetAccountSchema"
                    }
                  },
                  "groups": {
                    "description": "Array of account groups",
                    "example": [
                      {
                        "id": "6284c43d519161e96cc09c13",
                        "name": "Primary",
                        "accountIds": [
                          "6494063f4260855c1c5776b5_mhoUgTPkz19vjF5Qu7Av_2774080328752823730"
                        ]
                      }
                    ],
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "Group Id",
                          "example": "6284c43d519161e96cc09c13"
                        },
                        "name": {
                          "type": "string",
                          "description": "name of group",
                          "example": "Primary"
                        },
                        "accountIds": {
                          "description": "Array of account IDs belonging to this group",
                          "example": [
                            "6494063f4260855c1c5776b5_mhoUgTPkz19vjF5Qu7Av_2774080328752823730"
                          ],
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        }
                      },
                      "required": [
                        "id",
                        "name",
                        "accountIds"
                      ],
                      "title": "GetGroupSchema"
                    }
                  },
                  "total": {
                    "type": "number",
                    "description": "Number of accounts returned. This endpoint is not paginated, so it is the length of `accounts`",
                    "example": 2
                  }
                },
                "title": "AccountsListResponseSchema"
              }
            ]
          }
        },
        "required": [
          "success",
          "statusCode",
          "message"
        ],
        "title": "AccountsListResponseDTO"
      },
      "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"
      },
      "UnprocessableDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 422
          },
          "message": {
            "example": [
              "Unprocessable Entity"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "error": {
            "type": "string",
            "example": "Unprocessable Entity"
          }
        },
        "title": "UnprocessableDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X GET 'https://services.leadconnectorhq.com/social-media-posting/<locationId>/accounts' \
  -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/social-media-posting/<locationId>/accounts', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/social-media-posting/{locationId}/accounts"

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

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

**PHP**

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

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/social-media-posting/<locationId>/accounts',
  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/social-media-posting/<locationId>/accounts")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/social-media-posting/<locationId>/accounts"
  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/social-media-posting/<locationId>/accounts")

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/social-media-posting/<locationId>/accounts' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
