# Upsert audience

PUT https://services.leadconnectorhq.com/ad-publishing/google/audiences

Create or update a Google Ads combined audience

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

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "HighLevel API",
    "version": "2021-07-28"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/ad-publishing/google/audiences": {
      "put": {
        "summary": "Upsert audience",
        "operationId": "upsertAudience",
        "description": "Create or update a Google Ads combined audience",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "2021-07-28"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpsertAudienceDTO"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Google Ads mutate results for the created or updated audience — an array, not the audience itself",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpsertAudienceResponse"
                }
              }
            }
          },
          "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": {
      "UpsertAudienceDTO": {
        "type": "object",
        "properties": {
          "locationId": {
            "type": "string",
            "description": "Location identifier",
            "example": "loc_abc123"
          },
          "resourceName": {
            "type": "string",
            "description": "Audience resource name",
            "example": "customers/123/audiences/456"
          },
          "name": {
            "type": "string",
            "description": "Audience name",
            "example": "My Audience"
          },
          "dimensions": {
            "description": "Audience dimensions",
            "example": {
              "isAgeUnknown": false,
              "ageRanges": [
                {
                  "minAge": 25,
                  "maxAge": 34
                }
              ],
              "genders": [
                "MALE",
                "FEMALE"
              ]
            },
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "isAgeUnknown": {
                    "type": "boolean",
                    "description": "Include unknown age",
                    "example": false
                  },
                  "ageRanges": {
                    "type": "array",
                    "description": "Age range filter. Only the first entry is applied. Google accepts fixed buckets, so `minAge` must be one of 18, 25, 35, 45, 55, 65 and `maxAge`, when supplied, one of 24, 34, 44, 54, 64; `minAge` must be less than `maxAge`. Omit `maxAge` for the open-ended 65+ bucket. Values outside these are rejected with 400. Note this is the user-list age shape and differs from the `AGE_RANGE_*` strings used for campaign demographic targeting.",
                    "items": {
                      "type": "object",
                      "properties": {
                        "minAge": {
                          "type": "number",
                          "description": "Lower bound of the age bucket, inclusive",
                          "enum": [
                            18,
                            25,
                            35,
                            45,
                            55,
                            65
                          ],
                          "example": 25
                        },
                        "maxAge": {
                          "type": "number",
                          "description": "Upper bound of the age bucket, inclusive. Omit for the open-ended 65+ bucket.",
                          "enum": [
                            24,
                            34,
                            44,
                            54,
                            64
                          ],
                          "example": 34
                        }
                      },
                      "required": [
                        "minAge"
                      ]
                    },
                    "example": [
                      {
                        "minAge": 25,
                        "maxAge": 34
                      }
                    ]
                  },
                  "genders": {
                    "type": "array",
                    "description": "Gender targets",
                    "example": [
                      "MALE",
                      "FEMALE"
                    ],
                    "items": {
                      "type": "string",
                      "enum": [
                        "MALE",
                        "FEMALE",
                        "UNDETERMINED"
                      ]
                    }
                  },
                  "parentalStatuses": {
                    "type": "array",
                    "description": "Parental status targets",
                    "example": [
                      "PARENT"
                    ],
                    "items": {
                      "type": "string",
                      "enum": [
                        "PARENT",
                        "NOT_A_PARENT",
                        "UNDETERMINED"
                      ]
                    }
                  },
                  "audienceSegments": {
                    "description": "Audience segment references used for targeting",
                    "example": {
                      "customAudiences": [
                        "customers/6776452901/customAudiences/456"
                      ],
                      "userLists": [
                        "customers/6776452901/userLists/9215680180"
                      ],
                      "userInterests": [
                        "customers/6776452901/userInterests/80351"
                      ]
                    },
                    "allOf": [
                      {
                        "type": "object",
                        "properties": {
                          "customAudiences": {
                            "description": "Resource names of custom audience segments",
                            "example": [
                              "customers/123/customAudiences/456"
                            ],
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          },
                          "userLists": {
                            "description": "Resource names of user lists (remarketing lists, customer match lists, etc.)",
                            "example": [
                              "customers/123/userLists/789"
                            ],
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          },
                          "userInterests": {
                            "description": "Resource names of user interest segments (in-market or affinity audiences)",
                            "example": [
                              "customers/123/userInterests/321"
                            ],
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          }
                        },
                        "title": "AudienceSegmentsDTO"
                      }
                    ]
                  }
                },
                "title": "AudienceDimensionDTO"
              }
            ]
          },
          "exclusionDimension": {
            "description": "Exclusion dimensions",
            "example": {
              "genders": [
                "UNDETERMINED"
              ]
            },
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "isAgeUnknown": {
                    "type": "boolean",
                    "description": "Include unknown age",
                    "example": false
                  },
                  "ageRanges": {
                    "type": "array",
                    "description": "Age range filter. Only the first entry is applied. Google accepts fixed buckets, so `minAge` must be one of 18, 25, 35, 45, 55, 65 and `maxAge`, when supplied, one of 24, 34, 44, 54, 64; `minAge` must be less than `maxAge`. Omit `maxAge` for the open-ended 65+ bucket. Values outside these are rejected with 400. Note this is the user-list age shape and differs from the `AGE_RANGE_*` strings used for campaign demographic targeting.",
                    "items": {
                      "type": "object",
                      "properties": {
                        "minAge": {
                          "type": "number",
                          "description": "Lower bound of the age bucket, inclusive",
                          "enum": [
                            18,
                            25,
                            35,
                            45,
                            55,
                            65
                          ],
                          "example": 25
                        },
                        "maxAge": {
                          "type": "number",
                          "description": "Upper bound of the age bucket, inclusive. Omit for the open-ended 65+ bucket.",
                          "enum": [
                            24,
                            34,
                            44,
                            54,
                            64
                          ],
                          "example": 34
                        }
                      },
                      "required": [
                        "minAge"
                      ]
                    },
                    "example": [
                      {
                        "minAge": 25,
                        "maxAge": 34
                      }
                    ]
                  },
                  "genders": {
                    "type": "array",
                    "description": "Gender targets",
                    "example": [
                      "MALE",
                      "FEMALE"
                    ],
                    "items": {
                      "type": "string",
                      "enum": [
                        "MALE",
                        "FEMALE",
                        "UNDETERMINED"
                      ]
                    }
                  },
                  "parentalStatuses": {
                    "type": "array",
                    "description": "Parental status targets",
                    "example": [
                      "PARENT"
                    ],
                    "items": {
                      "type": "string",
                      "enum": [
                        "PARENT",
                        "NOT_A_PARENT",
                        "UNDETERMINED"
                      ]
                    }
                  },
                  "audienceSegments": {
                    "description": "Audience segment references used for targeting",
                    "example": {
                      "customAudiences": [
                        "customers/6776452901/customAudiences/456"
                      ],
                      "userLists": [
                        "customers/6776452901/userLists/9215680180"
                      ],
                      "userInterests": [
                        "customers/6776452901/userInterests/80351"
                      ]
                    },
                    "allOf": [
                      {
                        "type": "object",
                        "properties": {
                          "customAudiences": {
                            "description": "Resource names of custom audience segments",
                            "example": [
                              "customers/123/customAudiences/456"
                            ],
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          },
                          "userLists": {
                            "description": "Resource names of user lists (remarketing lists, customer match lists, etc.)",
                            "example": [
                              "customers/123/userLists/789"
                            ],
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          },
                          "userInterests": {
                            "description": "Resource names of user interest segments (in-market or affinity audiences)",
                            "example": [
                              "customers/123/userInterests/321"
                            ],
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          }
                        },
                        "title": "AudienceSegmentsDTO"
                      }
                    ]
                  }
                },
                "title": "AudienceDimensionDTO"
              }
            ]
          }
        },
        "required": [
          "locationId",
          "name"
        ],
        "title": "UpsertAudienceDTO"
      },
      "UpsertAudienceResponse": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "resourceName": {
              "type": "string",
              "description": "Resource name of the affected record, as returned by the Google Ads mutate call",
              "example": "customers/6776452901/conversionActions/7086809727"
            }
          },
          "required": [
            "resourceName"
          ],
          "title": "GoogleMutateResultDTO"
        }
      },
      "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/google/audiences' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: 2021-07-28' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "locationId": "loc_abc123",
  "resourceName": "customers/123/audiences/456",
  "name": "My Audience",
  "dimensions": {
    "isAgeUnknown": false,
    "ageRanges": [
      {
        "minAge": 25,
        "maxAge": 34
      }
    ],
    "genders": [
      "MALE",
      "FEMALE"
    ]
  },
  "exclusionDimension": {
    "genders": [
      "UNDETERMINED"
    ]
  }
}'
```

**Node.js**

```javascript
const options = {
  method: 'PUT',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: '2021-07-28',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "locationId": "loc_abc123",
      "resourceName": "customers/123/audiences/456",
      "name": "My Audience",
      "dimensions": {
        "isAgeUnknown": false,
        "ageRanges": [
          {
            "minAge": 25,
            "maxAge": 34
          }
        ],
        "genders": [
          "MALE",
          "FEMALE"
        ]
      },
      "exclusionDimension": {
        "genders": [
          "UNDETERMINED"
        ]
      }
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/ad-publishing/google/audiences', 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/google/audiences"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "2021-07-28"
}

payload = {
    "locationId": "loc_abc123",
    "resourceName": "customers/123/audiences/456",
    "name": "My Audience",
    "dimensions": {
        "isAgeUnknown": false,
        "ageRanges": [
            {
                "minAge": 25,
                "maxAge": 34
            }
        ],
        "genders": [
            "MALE",
            "FEMALE"
        ]
    },
    "exclusionDimension": {
        "genders": [
            "UNDETERMINED"
        ]
    }
}

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/google/audiences',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'PUT',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: 2021-07-28',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "locationId": "loc_abc123",
  "resourceName": "customers/123/audiences/456",
  "name": "My Audience",
  "dimensions": {
    "isAgeUnknown": false,
    "ageRanges": [
      {
        "minAge": 25,
        "maxAge": 34
      }
    ],
    "genders": [
      "MALE",
      "FEMALE"
    ]
  },
  "exclusionDimension": {
    "genders": [
      "UNDETERMINED"
    ]
  }
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .put("https://services.leadconnectorhq.com/ad-publishing/google/audiences")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "2021-07-28")
  .header("Content-Type", "application/json")
  .body("{\"locationId\":\"loc_abc123\",\"resourceName\":\"customers/123/audiences/456\",\"name\":\"My Audience\",\"dimensions\":{\"isAgeUnknown\":false,\"ageRanges\":[{\"minAge\":25,\"maxAge\":34}],\"genders\":[\"MALE\",\"FEMALE\"]},\"exclusionDimension\":{\"genders\":[\"UNDETERMINED\"]}}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/ad-publishing/google/audiences"
  payload := strings.NewReader(`{
  "locationId": "loc_abc123",
  "resourceName": "customers/123/audiences/456",
  "name": "My Audience",
  "dimensions": {
    "isAgeUnknown": false,
    "ageRanges": [
      {
        "minAge": 25,
        "maxAge": 34
      }
    ],
    "genders": [
      "MALE",
      "FEMALE"
    ]
  },
  "exclusionDimension": {
    "genders": [
      "UNDETERMINED"
    ]
  }
}`)
  req, _ := http.NewRequest("PUT", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "2021-07-28")

  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/google/audiences")

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

request = Net::HTTP::Put.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "2021-07-28"
request["Content-Type"] = "application/json"
request.body = '{
  "locationId": "loc_abc123",
  "resourceName": "customers/123/audiences/456",
  "name": "My Audience",
  "dimensions": {
    "isAgeUnknown": false,
    "ageRanges": [
      {
        "minAge": 25,
        "maxAge": 34
      }
    ],
    "genders": [
      "MALE",
      "FEMALE"
    ]
  },
  "exclusionDimension": {
    "genders": [
      "UNDETERMINED"
    ]
  }
}'

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

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "2021-07-28"
}

$body = '{
  "locationId": "loc_abc123",
  "resourceName": "customers/123/audiences/456",
  "name": "My Audience",
  "dimensions": {
    "isAgeUnknown": false,
    "ageRanges": [
      {
        "minAge": 25,
        "maxAge": 34
      }
    ],
    "genders": [
      "MALE",
      "FEMALE"
    ]
  },
  "exclusionDimension": {
    "genders": [
      "UNDETERMINED"
    ]
  }
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/ad-publishing/google/audiences' -Method 'PUT' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
