# Upload CSV

POST https://services.leadconnectorhq.com/social-media-posting/{locationId}/csv

Upload a CSV file containing social media posts for bulk scheduling

## Authentication

Send `Authorization: Bearer <token>` using:

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

## Parameters

### Header Parameters

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

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | Yes | Location ID (also known as Sub-Account ID) for the business location. |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/social-media-posting/{locationId}/csv": {
      "post": {
        "summary": "Upload CSV",
        "operationId": "uploadCsv",
        "description": "Upload a CSV file containing social media posts for bulk scheduling",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "locationId",
            "required": true,
            "in": "path",
            "description": "Location ID (also known as Sub-Account ID) for the business location.",
            "schema": {
              "example": "ve9EPM428h8vShlRW1KT",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/UploadCsvDto"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadFileResponseDTO"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request - File is required or CSV validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadCsvError400"
                }
              }
            }
          },
          "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/csv.write"
            ]
          }
        ]
      }
    }
  },
  "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": {
      "UploadCsvDto": {
        "type": "object",
        "properties": {
          "file": {
            "type": "string",
            "format": "binary",
            "description": "CSV file to upload containing social media posts",
            "example": "sample.csv"
          }
        },
        "required": [
          "file"
        ]
      },
      "UploadFileResponseDTO": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "description": "Success or Failure",
            "example": true
          },
          "statusCode": {
            "type": "number",
            "description": "Status Code",
            "example": 201
          },
          "message": {
            "type": "string",
            "description": "Message",
            "example": "Uploaded CSV"
          },
          "results": {
            "description": "Requested Results",
            "example": {
              "filePath": "omaDY3RbWtTP511e/social-import/d23d68c2-82c0-1db6e2.csv",
              "rowsCount": 6,
              "fileName": "sample.csv",
              "fileSize": 1024,
              "csvFileType": "basic"
            },
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "filePath": {
                    "type": "string",
                    "description": "File path of uploaded CSV",
                    "example": "omaDY3RbWtTP511e/social-import/d23d68c2-82c0-1db6e2.csv"
                  },
                  "rowsCount": {
                    "type": "number",
                    "description": "Number of rows in the CSV",
                    "example": 6
                  },
                  "fileName": {
                    "type": "string",
                    "description": "Name of the uploaded file",
                    "example": "CSV Import Sample - CSV Import Sample.csv"
                  },
                  "fileSize": {
                    "type": "number",
                    "description": "Size of the file in bytes",
                    "example": 1024
                  },
                  "csvFileType": {
                    "type": "string",
                    "description": "CSV file type",
                    "example": "basic",
                    "enum": [
                      "basic",
                      "advance"
                    ]
                  }
                },
                "title": "UploadFileResponseSchema"
              }
            ]
          }
        },
        "required": [
          "success",
          "statusCode",
          "message"
        ],
        "title": "UploadFileResponseDTO"
      },
      "UploadCsvError400": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "status": {
                "type": "number",
                "description": "HTTP Status",
                "example": 400
              },
              "options": {
                "type": "object",
                "description": "Options",
                "example": {}
              },
              "message": {
                "type": "string",
                "description": "Error message",
                "example": "File is required"
              },
              "name": {
                "type": "string",
                "description": "Exception name",
                "example": "BadRequestException"
              },
              "error": {
                "type": "string",
                "description": "Error type",
                "example": "Bad Request"
              },
              "statusCode": {
                "type": "number",
                "description": "Status Code",
                "example": 400
              },
              "traceId": {
                "type": "string",
                "description": "Trace ID for debugging",
                "example": "376a2de3-a3a4-4588-a6b5-bafe828f614b"
              }
            },
            "required": [
              "status",
              "message",
              "name",
              "error",
              "statusCode"
            ],
            "title": "CSVFileRequiredBadRequestDTO"
          },
          {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "description": "Error code for CSV processing errors",
                "enum": [
                  "CSV_EMPTY_FILE",
                  "CSV_INVALID_FORMAT",
                  "CSV_HEADERS_NOT_MATCHING",
                  "CSV_MISSING_HEADERS",
                  "CSV_MISSING_REQUIRED_ROWS",
                  "CSV_UNSUPPORTED_EXTENSION",
                  "CSV_NO_VALID_POST",
                  "CSV_PROCESSING_ERROR"
                ],
                "example": "CSV_HEADERS_NOT_MATCHING"
              },
              "message": {
                "type": "string",
                "description": "Error message describing the CSV validation error",
                "example": "CSV headers are not identical to sample file."
              },
              "fileType": {
                "type": "string",
                "description": "File type detected",
                "example": "CSV",
                "enum": [
                  "CSV",
                  "XLSX"
                ]
              },
              "csvFileType": {
                "type": "string",
                "description": "CSV file type",
                "example": "basic",
                "enum": [
                  "basic",
                  "advance"
                ]
              },
              "missingHeaders": {
                "type": "string",
                "description": "Comma-separated list of missing headers from the file",
                "example": "postAtSpecificTime (YYYY-MM-DD HH:mm:ss), content, link (OGmetaUrl)"
              }
            },
            "required": [
              "code",
              "message"
            ],
            "title": "CSVErrorResponseDTO"
          }
        ]
      },
      "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 POST 'https://services.leadconnectorhq.com/social-media-posting/<locationId>/csv' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: multipart/form-data' \
  --data-raw '{
  "file": "sample.csv"
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'multipart/form-data'
  },
  body: JSON.stringify({
      "file": "sample.csv"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/social-media-posting/<locationId>/csv', 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}/csv"

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

payload = {
    "file": "sample.csv"
}

response = requests.post(url, json=payload, 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>/csv',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: multipart/form-data',
  ],
  CURLOPT_POSTFIELDS => '{
  "file": "sample.csv"
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/social-media-posting/<locationId>/csv")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "multipart/form-data")
  .body("{\"file\":\"sample.csv\"}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/social-media-posting/<locationId>/csv"
  payload := strings.NewReader(`{
  "file": "sample.csv"
}`)
  req, _ := http.NewRequest("POST", url, payload)
  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>/csv")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "file": "sample.csv"
}'

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

**PowerShell**

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

$body = '{
  "file": "sample.csv"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/social-media-posting/<locationId>/csv' -Method 'POST' -Headers $headers -Body $body -ContentType 'multipart/form-data'
$response | ConvertTo-Json
```
