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

> Create or update a Google Ads audience segment

Create or update a Google Ads audience segment

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

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

## Query parameters

<ParamField query="locationId" type="string" required default="HChooFuiyPpVYzeJ4HMe">
  Account identifier
</ParamField>

<ParamField query="type" type="string" required default="CUSTOM_SEGMENTS">
  Segment type
</ParamField>

## Body

<ParamField body="name" type="string" required default="My Segment">
  Segment name
</ParamField>

<ParamField body="description" type="string" default="Target audience segment">
  Segment description
</ParamField>

<ParamField body="members" type="object[]">
  Segment members — keywords, URLs, or apps that define the custom segment

  <Expandable title="cada item">
    <ParamField body="memberType" type="string" required default="KEYWORD">
      Member type Posibles valores: 'KEYWORD', 'URL', 'APP'
    </ParamField>

    <ParamField body="keyword" type="string" default="marketing">
      Keyword value
    </ParamField>

    <ParamField body="url" type="string" default="https://example.com">
      URL value
    </ParamField>

    <ParamField body="app" type="string" default="com.example.app">
      App identifier
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="status" type="string" default="ENABLED">
  Segment status
</ParamField>

<ParamField body="type" type="string" default="CUSTOM_SEGMENTS">
  Segment type
</ParamField>

<ParamField body="id" type="string" default="seg_123">
  Segment identifier
</ParamField>

<ParamField body="membershipStatus" type="string" default="OPEN">
  Membership status
</ParamField>

<ParamField body="ruleBasedUserList" type="object">
  Rule-based user list config
</ParamField>

<ParamField body="membershipLifeSpan" type="number" default="30">
  Membership life span
</ParamField>

<ParamField body="seedUserListIds" type="string[]">
  Seed user list IDs
</ParamField>

<ParamField body="countryCodes" type="string[]">
  Country codes
</ParamField>

<ParamField body="expansionLevel" type="string" default="BALANCED">
  Expansion level Posibles valores: 'BALANCED', 'BROAD', 'NARROW'
</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/google/segments' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Version: 2021-07-28' \
    -H 'Content-Type: application/json' \
    -d '{
    "name": "My Segment",
    "description": "Target audience segment",
    "members": [
      {
        "memberType": "KEYWORD",
        "keyword": "digital marketing"
      },
      {
        "memberType": "URL",
        "url": "https://example.com"
      },
      {
        "memberType": "APP",
        "app": "com.example.app"
      }
    ],
    "status": "ENABLED",
    "type": "CUSTOM_SEGMENTS",
    "id": "seg_123",
    "membershipStatus": "OPEN",
    "membershipLifeSpan": 30,
    "seedUserListIds": [
      "list_1"
    ],
    "countryCodes": [
      "US",
      "CA"
    ],
    "expansionLevel": "BALANCED"
  }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://services.leadconnectorhq.com/ad-publishing/google/segments', {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${process.env.LEADWAY_TOKEN}`,
      Version: '2021-07-28',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({"name": "My Segment", "description": "Target audience segment", "members": [{"memberType": "KEYWORD", "keyword": "digital marketing"}, {"memberType": "URL", "url": "https://example.com"}, {"memberType": "APP", "app": "com.example.app"}], "status": "ENABLED", "type": "CUSTOM_SEGMENTS", "id": "seg_123", "membershipStatus": "OPEN", "membershipLifeSpan": 30, "seedUserListIds": ["list_1"], "countryCodes": ["US", "CA"], "expansionLevel": "BALANCED"}),
  });
  const data = await response.json();
  ```

  ```python Python theme={null}
  import os, requests
  response = requests.request(
      'PUT',
      'https://services.leadconnectorhq.com/ad-publishing/google/segments',
      headers={
          'Authorization': f"Bearer {os.environ['LEADWAY_TOKEN']}",
          'Version': '2021-07-28',
          'Content-Type': 'application/json',
      },
      json={"name": "My Segment", "description": "Target audience segment", "members": [{"memberType": "KEYWORD", "keyword": "digital marketing"}, {"memberType": "URL", "url": "https://example.com"}, {"memberType": "APP", "app": "com.example.app"}], "status": "ENABLED", "type": "CUSTOM_SEGMENTS", "id": "seg_123", "membershipStatus": "OPEN", "membershipLifeSpan": 30, "seedUserListIds": ["list_1"], "countryCodes": ["US", "CA"], "expansionLevel": "BALANCED"},
  )
  data = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://services.leadconnectorhq.com/ad-publishing/google/segments');
  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({'name': 'My Segment', 'description': 'Target audience segment', 'members': [{'memberType': 'KEYWORD', 'keyword': 'digital marketing'}, {'memberType': 'URL', 'url': 'https://example.com'}, {'memberType': 'APP', 'app': 'com.example.app'}], 'status': 'ENABLED', 'type': 'CUSTOM_SEGMENTS', 'id': 'seg_123', 'membershipStatus': 'OPEN', 'membershipLifeSpan': 30, 'seedUserListIds': ['list_1'], 'countryCodes': ['US', 'CA'], 'expansionLevel': 'BALANCED'}),
  ]);
  $data = json_decode(curl_exec($ch), true);
  ```
</CodeGroup>
