# Batch update audience members

PUT https://services.leadconnectorhq.com/ad-publishing/facebook/custom-audience/{customAudienceId}/member/batch

Add or remove members in bulk from a Facebook custom audience, sourced from a CSV or one or more smart lists — at least one of `csvPath` or `smartlistIds` is required. The work is queued rather than performed inline, so the acknowledgement confirms only that the job was accepted; nothing about the outcome is reported here. Unlike the single-member endpoints this one answers with `{ success: true }` rather than a status-and-message body.

## Authentication

Send `Authorization: Bearer <token>` using:

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

## Parameters

### Header Parameters

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

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `customAudienceId` | string | Yes | Custom audience identifier |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "HighLevel API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/ad-publishing/facebook/custom-audience/{customAudienceId}/member/batch": {
      "put": {
        "summary": "Batch update audience members",
        "operationId": "batchUpdateAudienceMembers",
        "description": "Add or remove members in bulk from a Facebook custom audience, sourced from a CSV or one or more smart lists — at least one of `csvPath` or `smartlistIds` is required. The work is queued rather than performed inline, so the acknowledgement confirms only that the job was accepted; nothing about the outcome is reported here. Unlike the single-member endpoints this one answers with `{ success: true }` rather than a status-and-message body.",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "customAudienceId",
            "required": true,
            "in": "path",
            "description": "Custom audience identifier",
            "schema": {
              "example": "23851234567890123",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateCustomAudienceBatchDTO"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledgement that the bulk update was queued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FacebookSuccessResponseDTO"
                }
              }
            }
          },
          "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"
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InternalServerErrorDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": [
              "adPublishing.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": {
      "UpdateCustomAudienceBatchDTO": {
        "type": "object",
        "properties": {
          "locationId": {
            "type": "string",
            "description": "Location identifier",
            "example": "loc_abc123"
          },
          "csvPath": {
            "type": "string",
            "description": "CSV file path",
            "example": "/uploads/audience.csv"
          },
          "operationType": {
            "type": "string",
            "description": "Batch operation type",
            "example": "ADD",
            "enum": [
              "ADD",
              "REMOVE",
              "REPLACE"
            ]
          },
          "smartlistIds": {
            "description": "Smartlist IDs array",
            "example": [
              "list_1",
              "list_2"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "dynamicAudience": {
            "type": "string",
            "description": "Dynamic audience flag",
            "example": "true"
          }
        },
        "required": [
          "locationId",
          "operationType"
        ],
        "title": "UpdateCustomAudienceBatchDTO"
      },
      "FacebookSuccessResponseDTO": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "description": "True when the operation succeeded",
            "example": true
          }
        },
        "required": [
          "success"
        ],
        "title": "FacebookSuccessResponseDTO"
      },
      "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"
      },
      "InternalServerErrorDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "description": "HTTP status code for an unexpected server error",
            "example": 500
          },
          "message": {
            "type": "string",
            "description": "Error message describing the server failure",
            "example": "Internal Server Error"
          }
        },
        "title": "InternalServerErrorDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X PUT 'https://services.leadconnectorhq.com/ad-publishing/facebook/custom-audience/<customAudienceId>/member/batch' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "locationId": "loc_abc123",
  "csvPath": "/uploads/audience.csv",
  "operationType": "ADD",
  "smartlistIds": [
    "list_1",
    "list_2"
  ],
  "dynamicAudience": "true"
}'
```

**Node.js**

```javascript
const options = {
  method: 'PUT',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "locationId": "loc_abc123",
      "csvPath": "/uploads/audience.csv",
      "operationType": "ADD",
      "smartlistIds": [
        "list_1",
        "list_2"
      ],
      "dynamicAudience": "true"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/ad-publishing/facebook/custom-audience/<customAudienceId>/member/batch', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/ad-publishing/facebook/custom-audience/{customAudienceId}/member/batch"

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

payload = {
    "locationId": "loc_abc123",
    "csvPath": "/uploads/audience.csv",
    "operationType": "ADD",
    "smartlistIds": [
        "list_1",
        "list_2"
    ],
    "dynamicAudience": "true"
}

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

**PHP**

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

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/ad-publishing/facebook/custom-audience/<customAudienceId>/member/batch',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'PUT',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "locationId": "loc_abc123",
  "csvPath": "/uploads/audience.csv",
  "operationType": "ADD",
  "smartlistIds": [
    "list_1",
    "list_2"
  ],
  "dynamicAudience": "true"
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .put("https://services.leadconnectorhq.com/ad-publishing/facebook/custom-audience/<customAudienceId>/member/batch")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"locationId\":\"loc_abc123\",\"csvPath\":\"/uploads/audience.csv\",\"operationType\":\"ADD\",\"smartlistIds\":[\"list_1\",\"list_2\"],\"dynamicAudience\":\"true\"}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/ad-publishing/facebook/custom-audience/<customAudienceId>/member/batch"
  payload := strings.NewReader(`{
  "locationId": "loc_abc123",
  "csvPath": "/uploads/audience.csv",
  "operationType": "ADD",
  "smartlistIds": [
    "list_1",
    "list_2"
  ],
  "dynamicAudience": "true"
}`)
  req, _ := http.NewRequest("PUT", 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/ad-publishing/facebook/custom-audience/<customAudienceId>/member/batch")

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

request = Net::HTTP::Put.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "locationId": "loc_abc123",
  "csvPath": "/uploads/audience.csv",
  "operationType": "ADD",
  "smartlistIds": [
    "list_1",
    "list_2"
  ],
  "dynamicAudience": "true"
}'

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

**PowerShell**

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

$body = '{
  "locationId": "loc_abc123",
  "csvPath": "/uploads/audience.csv",
  "operationType": "ADD",
  "smartlistIds": [
    "list_1",
    "list_2"
  ],
  "dynamicAudience": "true"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/ad-publishing/facebook/custom-audience/<customAudienceId>/member/batch' -Method 'PUT' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
