> ## 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 campaign

> Create or update a Facebook campaign

Create or update a Facebook campaign

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

## 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="camp_123">
  Campaign identifier
</ParamField>

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

<ParamField body="name" type="string" default="Summer Campaign">
  Campaign name
</ParamField>

<ParamField body="objective" type="string" default="LEAD_GENERATION">
  Campaign objective Posibles valores: 'OUTCOME\_LEADS', 'OUTCOME\_TRAFFIC', 'OUTCOME\_ENGAGEMENT', 'OUTCOME\_SALES'
</ParamField>

<ParamField body="specialAdCategories" type="string">
  Special ad categories Posibles valores: 'EMPLOYMENT', 'CREDIT', 'FINANCIAL\_PRODUCTS\_SERVICES', 'HOUSING', 'ISSUES\_ELECTIONS\_POLITICS', 'ONLINE\_GAMBLING\_AND\_GAMING', 'NONE'
</ParamField>

<ParamField body="source" type="string" default="facebook">
  Campaign data source
</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/campaigns' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Version: 2021-07-28' \
    -H 'Content-Type: application/json' \
    -d '{
    "id": "camp_123",
    "locationId": "loc_abc123",
    "name": "Summer Campaign",
    "objective": "LEAD_GENERATION",
    "specialAdCategories": "EMPLOYMENT",
    "source": "facebook"
  }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://services.leadconnectorhq.com/ad-publishing/facebook/campaigns', {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${process.env.LEADWAY_TOKEN}`,
      Version: '2021-07-28',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({"id": "camp_123", "locationId": "loc_abc123", "name": "Summer Campaign", "objective": "LEAD_GENERATION", "specialAdCategories": "EMPLOYMENT", "source": "facebook"}),
  });
  const data = await response.json();
  ```

  ```python Python theme={null}
  import os, requests
  response = requests.request(
      'PUT',
      'https://services.leadconnectorhq.com/ad-publishing/facebook/campaigns',
      headers={
          'Authorization': f"Bearer {os.environ['LEADWAY_TOKEN']}",
          'Version': '2021-07-28',
          'Content-Type': 'application/json',
      },
      json={"id": "camp_123", "locationId": "loc_abc123", "name": "Summer Campaign", "objective": "LEAD_GENERATION", "specialAdCategories": "EMPLOYMENT", "source": "facebook"},
  )
  data = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://services.leadconnectorhq.com/ad-publishing/facebook/campaigns');
  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': 'camp_123', 'locationId': 'loc_abc123', 'name': 'Summer Campaign', 'objective': 'LEAD_GENERATION', 'specialAdCategories': 'EMPLOYMENT', 'source': 'facebook'}),
  ]);
  $data = json_decode(curl_exec($ch), true);
  ```
</CodeGroup>
