> ## Documentation Index
> Fetch the complete documentation index at: https://developers.leadwaycrm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Upsert adset

> Create or update a Facebook ad set

Create or update a Facebook ad set

```http theme={null}
PUT https://services.leadconnectorhq.com/ad-publishing/facebook/adsets
```

## Autorización

<ParamField header="Authorization" type="string" required>
  Bearer token generado desde el portal Leadway. Ver [Autenticación](/authentication).
</ParamField>

<ParamField header="Version" type="string" required default="2021-07-28">
  Versión de la API.
</ParamField>

## Body

<ParamField body="id" type="string" default="adset_123">
  Ad set identifier
</ParamField>

<ParamField body="locationId" type="string" required default="loc_abc123">
  Account identifier
</ParamField>

<ParamField body="name" type="string" default="Targeting Group A">
  Ad set name
</ParamField>

<ParamField body="pageId" type="string" default="123456789">
  Facebook page ID
</ParamField>

<ParamField body="instagramActorId" type="string" default="ig_123">
  Instagram actor ID
</ParamField>

<ParamField body="messagingPlatforms" type="string">
  Messaging platforms Posibles valores: 'WHATSAPP', 'MESSENGER', 'INSTAGRAM\_DIRECT'
</ParamField>

<ParamField body="whatsappNumber" type="string" default="+1234567890">
  WhatsApp phone number
</ParamField>

<ParamField body="audience" type="object">
  Targeting audience configuration including geo-accounts, locales, placements, and custom audiences
</ParamField>

<ParamField body="budget" type="object">
  Ad set budget config
</ParamField>

<ParamField body="conversionLocation" type="string" default="website">
  Conversion account
</ParamField>

<ParamField body="customEventType" type="string" default="Purchase">
  Custom event type
</ParamField>

<ParamField body="pixelId" type="string" default="px_123">
  Conversion pixel ID
</ParamField>

<ParamField body="campaignId" type="string" required default="camp_123">
  Parent campaign ID
</ParamField>

## Respuestas

<Accordion title="200 - Response" />

<Accordion title="400 - Bad Request">
  ```json theme={null}
  {}
  ```
</Accordion>

<Accordion title="401 - Unauthorized">
  ```json theme={null}
  {}
  ```
</Accordion>

<Accordion title="422 - Unprocessable Entity">
  ```json theme={null}
  {}
  ```
</Accordion>

## Ejemplo

<CodeGroup>
  ```bash cURL theme={null}
  curl -X PUT 'https://services.leadconnectorhq.com/ad-publishing/facebook/adsets' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Version: 2021-07-28' \
    -H 'Content-Type: application/json' \
    -d '{
    "id": "adset_123",
    "locationId": "loc_abc123",
    "name": "Targeting Group A",
    "pageId": "123456789",
    "instagramActorId": "ig_123",
    "messagingPlatforms": "WHATSAPP",
    "whatsappNumber": "+1234567890",
    "conversionLocation": "website",
    "customEventType": "Purchase",
    "pixelId": "px_123",
    "campaignId": "camp_123"
  }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://services.leadconnectorhq.com/ad-publishing/facebook/adsets', {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${process.env.LEADWAY_TOKEN}`,
      Version: '2021-07-28',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({"id": "adset_123", "locationId": "loc_abc123", "name": "Targeting Group A", "pageId": "123456789", "instagramActorId": "ig_123", "messagingPlatforms": "WHATSAPP", "whatsappNumber": "+1234567890", "conversionLocation": "website", "customEventType": "Purchase", "pixelId": "px_123", "campaignId": "camp_123"}),
  });
  const data = await response.json();
  ```

  ```python Python theme={null}
  import os, requests
  response = requests.request(
      'PUT',
      'https://services.leadconnectorhq.com/ad-publishing/facebook/adsets',
      headers={
          'Authorization': f"Bearer {os.environ['LEADWAY_TOKEN']}",
          'Version': '2021-07-28',
          'Content-Type': 'application/json',
      },
      json={"id": "adset_123", "locationId": "loc_abc123", "name": "Targeting Group A", "pageId": "123456789", "instagramActorId": "ig_123", "messagingPlatforms": "WHATSAPP", "whatsappNumber": "+1234567890", "conversionLocation": "website", "customEventType": "Purchase", "pixelId": "px_123", "campaignId": "camp_123"},
  )
  data = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://services.leadconnectorhq.com/ad-publishing/facebook/adsets');
  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_CUSTOMREQUEST => 'PUT',
      CURLOPT_HTTPHEADER => [
          'Authorization: Bearer ' . getenv('LEADWAY_TOKEN'),
          'Version: 2021-07-28',
          'Content-Type: application/json',
      ],
      CURLOPT_POSTFIELDS => json_encode({'id': 'adset_123', 'locationId': 'loc_abc123', 'name': 'Targeting Group A', 'pageId': '123456789', 'instagramActorId': 'ig_123', 'messagingPlatforms': 'WHATSAPP', 'whatsappNumber': '+1234567890', 'conversionLocation': 'website', 'customEventType': 'Purchase', 'pixelId': 'px_123', 'campaignId': 'camp_123'}),
  ]);
  $data = json_decode(curl_exec($ch), true);
  ```
</CodeGroup>
