# Start OAuth Flow (Step 1 of 3)

GET https://services.leadconnectorhq.com/social-media-posting/oauth/{platform}/start

## OAuth Connection Flow - Step 1: Initiate OAuth

This is the first step in the 3-step OAuth flow to connect a social media account:

1. **Start OAuth** (this endpoint) → User authenticates with the platform
2. **Get Accounts** → Retrieve available pages/channels to connect
3. **Attach Account** → Connect the selected account to your location

### How to Use

Open this API in a browser window (not via cURL) with the required query parameters. The user will be redirected to the platform's OAuth login screen.

### Receiving the OAuth Response

After successful authentication, the OAuth window will post a message back to your application. Listen for this message to get the `accountId` needed for the next step.

```javascript
window.addEventListener('message', function(e) {
  if (e.data && e.data.page === 'social_media_posting') {
    const { actionType, page, platform, placement, accountId, reconnectAccounts } = e.data;
    // Use accountId for Step 2: GET /oauth/{locationId}/{platform}/accounts/{accountId}
  }
}, false);
```

### Event Data Response

| Field | Type | Example | Description |
|-------|------|---------|-------------|
| actionType | string | "close" | The action type |
| page | string | "social-media-posting" | Source page identifier |
| platform | string | "facebook" | The OAuth platform |
| placement | string | "placement" | Placement context |
| accountId | string | "658a9b6833b91e0ecb8f3958" | **Use this for Step 2** |
| reconnectAccounts | string[] | ["658a9b...", "efd2da..."] | Accounts that need reconnection |

### Next Step

Use the `accountId` from the response to call:
```
GET /social-media-posting/oauth/{locationId}/{platform}/accounts/{accountId}
```

### Platform Notes

- **bluesky**: Currently not supported, will return an error
- **tiktok-business**: Uses a separate business OAuth flow

## Authentication

Send `Authorization: Bearer <token>` using:

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

## Parameters

### Header Parameters

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

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `platform` | string | Yes | Social media platform to connect. Each platform has specific account types: - **google**: Google Business Profile locations - **facebook**: Facebook Pages - **instagram**: Instagram Professional Accounts (Business/Creator) - **linkedin**: LinkedIn Pages and Profiles - **tiktok**: TikTok Creator Accounts - **tiktok-business**: TikTok Business Center Accounts - **youtube**: YouTube Channels - **pinterest**: Pinterest Business Accounts - **threads**: Threads Profiles - **bluesky**: Bluesky Accounts (currently not supported) |

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | Yes | Location Id |
| `userId` | string | Yes | User Id |
| `page` | string | No | Page |
| `reconnect` | string | No | Reconnect |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/social-media-posting/oauth/{platform}/start": {
      "get": {
        "summary": "Start OAuth Flow (Step 1 of 3)",
        "operationId": "startOauthFlowStep1Of3",
        "description": "## OAuth Connection Flow - Step 1: Initiate OAuth\n\nThis is the first step in the 3-step OAuth flow to connect a social media account:\n\n1. **Start OAuth** (this endpoint) → User authenticates with the platform\n2. **Get Accounts** → Retrieve available pages/channels to connect\n3. **Attach Account** → Connect the selected account to your location\n\n### How to Use\n\nOpen this API in a browser window (not via cURL) with the required query parameters. The user will be redirected to the platform's OAuth login screen.\n\n### Receiving the OAuth Response\n\nAfter successful authentication, the OAuth window will post a message back to your application. Listen for this message to get the `accountId` needed for the next step.\n\n```javascript\nwindow.addEventListener('message', function(e) {\n  if (e.data && e.data.page === 'social_media_posting') {\n    const { actionType, page, platform, placement, accountId, reconnectAccounts } = e.data;\n    // Use accountId for Step 2: GET /oauth/{locationId}/{platform}/accounts/{accountId}\n  }\n}, false);\n```\n\n### Event Data Response\n\n| Field | Type | Example | Description |\n|-------|------|---------|-------------|\n| actionType | string | \"close\" | The action type |\n| page | string | \"social-media-posting\" | Source page identifier |\n| platform | string | \"facebook\" | The OAuth platform |\n| placement | string | \"placement\" | Placement context |\n| accountId | string | \"658a9b6833b91e0ecb8f3958\" | **Use this for Step 2** |\n| reconnectAccounts | string[] | [\"658a9b...\", \"efd2da...\"] | Accounts that need reconnection |\n\n### Next Step\n\nUse the `accountId` from the response to call:\n```\nGET /social-media-posting/oauth/{locationId}/{platform}/accounts/{accountId}\n```\n\n### Platform Notes\n\n- **bluesky**: Currently not supported, will return an error\n- **tiktok-business**: Uses a separate business OAuth flow",
        "parameters": [
          {
            "name": "platform",
            "required": true,
            "in": "path",
            "description": "Social media platform to connect. Each platform has specific account types:\n- **google**: Google Business Profile locations\n- **facebook**: Facebook Pages\n- **instagram**: Instagram Professional Accounts (Business/Creator)\n- **linkedin**: LinkedIn Pages and Profiles\n- **tiktok**: TikTok Creator Accounts\n- **tiktok-business**: TikTok Business Center Accounts\n- **youtube**: YouTube Channels\n- **pinterest**: Pinterest Business Accounts\n- **threads**: Threads Profiles\n- **bluesky**: Bluesky Accounts (currently not supported)",
            "schema": {
              "example": "google",
              "type": "string"
            }
          },
          {
            "name": "locationId",
            "required": true,
            "in": "query",
            "description": "Location Id",
            "schema": {
              "example": "w37swmmLbA02zgqKPpxITe2",
              "type": "string"
            }
          },
          {
            "name": "userId",
            "required": true,
            "in": "query",
            "description": "User Id",
            "schema": {
              "example": "u37swmmLbA02zgqKPpxITe2",
              "type": "string"
            }
          },
          {
            "name": "page",
            "required": false,
            "in": "query",
            "description": "Page",
            "schema": {
              "example": "integration",
              "type": "string"
            }
          },
          {
            "name": "reconnect",
            "required": false,
            "in": "query",
            "description": "Reconnect",
            "schema": {
              "example": "true",
              "type": "string"
            }
          },
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          }
        ],
        "responses": {
          "302": {
            "description": "Redirect to the platform OAuth consent screen"
          },
          "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/oauth.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": {
      "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/oauth/<platform>/start?locationId=<LOCATIONID>&userId=<USERID>' \
  -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/oauth/<platform>/start?locationId=<LOCATIONID>&userId=<USERID>', 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/oauth/{platform}/start"

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

params = {
    "locationId": "<LOCATIONID>",
    "userId": "<USERID>"
}

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/social-media-posting/oauth/<platform>/start?locationId=<LOCATIONID>&userId=<USERID>',
  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/oauth/<platform>/start?locationId=<LOCATIONID>&userId=<USERID>")
  .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/oauth/<platform>/start?locationId=<LOCATIONID>&userId=<USERID>"
  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/oauth/<platform>/start?locationId=<LOCATIONID>&userId=<USERID>")

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/oauth/<platform>/start?locationId=<LOCATIONID>&userId=<USERID>' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
```
