# Upsert segment

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

Create or update a Google Ads audience segment

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

### Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `locationId` | string | Yes | Location identifier |
| `type` | string | Yes | Segment type |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "HighLevel API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/ad-publishing/google/segments": {
      "put": {
        "summary": "Upsert segment",
        "operationId": "upsertSegment",
        "description": "Create or update a Google Ads audience segment",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "locationId",
            "required": true,
            "in": "query",
            "description": "Location identifier",
            "schema": {
              "example": "HChooFuiyPpVYzeJ4HMe",
              "type": "string"
            }
          },
          {
            "name": "type",
            "required": true,
            "in": "query",
            "description": "Segment type",
            "schema": {
              "example": "CUSTOM_SEGMENTS",
              "enum": [
                "CUSTOM_SEGMENTS",
                "WEBSITE_VISITOR",
                "CUSTOMER_MATCH",
                "LOOKALIKE"
              ],
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpsertSegmentDTO"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The saved segment, shaped by the requested `type`: a custom audience for `CUSTOM_SEGMENTS`, or a Google user list for `DATA_SEGMENTS`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpsertSegmentResponse"
                }
              }
            }
          },
          "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": {
      "UpsertSegmentDTO": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "Segment name",
            "example": "My Segment"
          },
          "description": {
            "type": "string",
            "description": "Segment description",
            "example": "Target audience segment"
          },
          "members": {
            "description": "Segment members — keywords, URLs, or apps that define the custom segment",
            "example": [
              {
                "memberType": "KEYWORD",
                "keyword": "digital marketing"
              },
              {
                "memberType": "URL",
                "url": "https://example.com"
              },
              {
                "memberType": "APP",
                "app": "com.example.app"
              }
            ],
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "memberType": {
                  "type": "string",
                  "description": "Member type",
                  "example": "KEYWORD",
                  "enum": [
                    "KEYWORD",
                    "URL",
                    "APP"
                  ]
                },
                "keyword": {
                  "type": "string",
                  "description": "Keyword value",
                  "example": "marketing"
                },
                "url": {
                  "type": "string",
                  "description": "URL value",
                  "example": "https://example.com"
                },
                "app": {
                  "type": "string",
                  "description": "App identifier",
                  "example": "com.example.app"
                }
              },
              "required": [
                "memberType"
              ],
              "title": "MemberDTO"
            }
          },
          "status": {
            "type": "string",
            "description": "Segment status",
            "example": "ENABLED"
          },
          "type": {
            "type": "string",
            "description": "Google custom-audience type, used only when the `type` query parameter is `CUSTOM_SEGMENTS`. Defaults to `AUTO` when omitted. This is NOT the same field as the `type` query parameter, which selects which kind of segment to upsert — settable values here are `AUTO`, `INTEREST`, `PURCHASE_INTENT` and `SEARCH`.",
            "example": "AUTO"
          },
          "id": {
            "type": "string",
            "description": "Segment identifier",
            "example": "seg_123"
          },
          "membershipStatus": {
            "type": "string",
            "description": "Membership status",
            "example": "OPEN"
          },
          "ruleBasedUserList": {
            "description": "Rule-based user list config",
            "example": {
              "prepopulationStatus": "REQUESTED",
              "flexibleRuleUserList": {
                "inclusiveOperands": [
                  {
                    "lookbackWindowDays": 30,
                    "rule": {
                      "ruleItemGroups": [
                        {
                          "ruleItems": [
                            {
                              "name": "url__",
                              "stringRuleItem": {
                                "operator": "CONTAINS",
                                "value": "/products"
                              }
                            }
                          ]
                        }
                      ]
                    }
                  }
                ],
                "exclusiveOperands": [
                  {
                    "lookbackWindowDays": 30,
                    "rule": {
                      "ruleItemGroups": [
                        {
                          "ruleItems": [
                            {
                              "name": "url__",
                              "stringRuleItem": {
                                "operator": "CONTAINS",
                                "value": "/products"
                              }
                            }
                          ]
                        }
                      ]
                    }
                  }
                ]
              }
            },
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "prepopulationStatus": {
                    "type": "string",
                    "description": "Prepopulation status",
                    "enum": [
                      "REQUESTED"
                    ],
                    "example": "REQUESTED"
                  },
                  "flexibleRuleUserList": {
                    "description": "Flexible rule user list configuration",
                    "example": {
                      "inclusiveRuleOperator": "AND",
                      "inclusiveOperands": [
                        {
                          "lookbackWindowDays": 30,
                          "rule": {
                            "ruleItemGroups": [
                              {
                                "ruleItems": [
                                  {
                                    "name": "url__",
                                    "stringRuleItem": {
                                      "operator": "CONTAINS",
                                      "value": "/products"
                                    }
                                  }
                                ]
                              }
                            ]
                          }
                        }
                      ],
                      "exclusiveOperands": [
                        {
                          "lookbackWindowDays": 30,
                          "rule": {
                            "ruleItemGroups": [
                              {
                                "ruleItems": [
                                  {
                                    "name": "url__",
                                    "stringRuleItem": {
                                      "operator": "CONTAINS",
                                      "value": "/products"
                                    }
                                  }
                                ]
                              }
                            ]
                          }
                        }
                      ]
                    },
                    "allOf": [
                      {
                        "type": "object",
                        "properties": {
                          "inclusiveRuleOperator": {
                            "type": "string",
                            "description": "Operator for combining inclusive operands",
                            "example": "AND"
                          },
                          "inclusiveOperands": {
                            "description": "Inclusive rule operands",
                            "example": [
                              {
                                "lookbackWindowDays": 30,
                                "rule": {
                                  "ruleItemGroups": [
                                    {
                                      "ruleItems": [
                                        {
                                          "name": "url__",
                                          "stringRuleItem": {
                                            "operator": "CONTAINS",
                                            "value": "/products"
                                          }
                                        }
                                      ]
                                    }
                                  ]
                                }
                              }
                            ],
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "lookbackWindowDays": {
                                  "type": "number",
                                  "description": "Lookback window in days",
                                  "example": 30
                                },
                                "rule": {
                                  "description": "Rule definition",
                                  "example": {
                                    "ruleItemGroups": [
                                      {
                                        "ruleItems": [
                                          {
                                            "name": "url__",
                                            "stringRuleItem": {
                                              "operator": "CONTAINS",
                                              "value": "/products"
                                            }
                                          }
                                        ]
                                      }
                                    ]
                                  },
                                  "allOf": [
                                    {
                                      "type": "object",
                                      "properties": {
                                        "ruleItemGroups": {
                                          "description": "List of rule item groups",
                                          "example": [
                                            {
                                              "ruleItems": [
                                                {
                                                  "name": "url__",
                                                  "stringRuleItem": {
                                                    "operator": "CONTAINS",
                                                    "value": "/products"
                                                  }
                                                }
                                              ]
                                            }
                                          ],
                                          "type": "array",
                                          "items": {
                                            "type": "object",
                                            "properties": {
                                              "ruleItems": {
                                                "description": "List of rule items",
                                                "example": [
                                                  {
                                                    "name": "url__",
                                                    "stringRuleItem": {
                                                      "operator": "CONTAINS",
                                                      "value": "/products"
                                                    }
                                                  }
                                                ],
                                                "type": "array",
                                                "items": {
                                                  "type": "object",
                                                  "properties": {
                                                    "name": {
                                                      "type": "string",
                                                      "description": "Rule item name",
                                                      "enum": [
                                                        "url__",
                                                        "referrer__"
                                                      ],
                                                      "example": "url__"
                                                    },
                                                    "stringRuleItem": {
                                                      "description": "String rule item condition",
                                                      "example": {
                                                        "operator": "CONTAINS",
                                                        "value": "/products"
                                                      },
                                                      "allOf": [
                                                        {
                                                          "type": "object",
                                                          "properties": {
                                                            "operator": {
                                                              "type": "string",
                                                              "description": "Rule operator",
                                                              "example": "CONTAINS"
                                                            },
                                                            "value": {
                                                              "type": "string",
                                                              "description": "Rule value",
                                                              "example": "/products"
                                                            }
                                                          },
                                                          "required": [
                                                            "operator",
                                                            "value"
                                                          ],
                                                          "title": "StringRuleItemDTO"
                                                        }
                                                      ]
                                                    }
                                                  },
                                                  "required": [
                                                    "name",
                                                    "stringRuleItem"
                                                  ],
                                                  "title": "RuleItemDTO"
                                                }
                                              }
                                            },
                                            "required": [
                                              "ruleItems"
                                            ],
                                            "title": "RuleItemGroupDTO"
                                          }
                                        }
                                      },
                                      "required": [
                                        "ruleItemGroups"
                                      ],
                                      "title": "RuleDTO"
                                    }
                                  ]
                                }
                              },
                              "required": [
                                "lookbackWindowDays",
                                "rule"
                              ],
                              "title": "RuleOperandDTO"
                            }
                          },
                          "exclusiveOperands": {
                            "description": "Exclusive rule operands",
                            "example": [
                              {
                                "lookbackWindowDays": 30,
                                "rule": {
                                  "ruleItemGroups": [
                                    {
                                      "ruleItems": [
                                        {
                                          "name": "url__",
                                          "stringRuleItem": {
                                            "operator": "CONTAINS",
                                            "value": "/products"
                                          }
                                        }
                                      ]
                                    }
                                  ]
                                }
                              }
                            ],
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "lookbackWindowDays": {
                                  "type": "number",
                                  "description": "Lookback window in days",
                                  "example": 30
                                },
                                "rule": {
                                  "description": "Rule definition",
                                  "example": {
                                    "ruleItemGroups": [
                                      {
                                        "ruleItems": [
                                          {
                                            "name": "url__",
                                            "stringRuleItem": {
                                              "operator": "CONTAINS",
                                              "value": "/products"
                                            }
                                          }
                                        ]
                                      }
                                    ]
                                  },
                                  "allOf": [
                                    {
                                      "type": "object",
                                      "properties": {
                                        "ruleItemGroups": {
                                          "description": "List of rule item groups",
                                          "example": [
                                            {
                                              "ruleItems": [
                                                {
                                                  "name": "url__",
                                                  "stringRuleItem": {
                                                    "operator": "CONTAINS",
                                                    "value": "/products"
                                                  }
                                                }
                                              ]
                                            }
                                          ],
                                          "type": "array",
                                          "items": {
                                            "type": "object",
                                            "properties": {
                                              "ruleItems": {
                                                "description": "List of rule items",
                                                "example": [
                                                  {
                                                    "name": "url__",
                                                    "stringRuleItem": {
                                                      "operator": "CONTAINS",
                                                      "value": "/products"
                                                    }
                                                  }
                                                ],
                                                "type": "array",
                                                "items": {
                                                  "type": "object",
                                                  "properties": {
                                                    "name": {
                                                      "type": "string",
                                                      "description": "Rule item name",
                                                      "enum": [
                                                        "url__",
                                                        "referrer__"
                                                      ],
                                                      "example": "url__"
                                                    },
                                                    "stringRuleItem": {
                                                      "description": "String rule item condition",
                                                      "example": {
                                                        "operator": "CONTAINS",
                                                        "value": "/products"
                                                      },
                                                      "allOf": [
                                                        {
                                                          "type": "object",
                                                          "properties": {
                                                            "operator": {
                                                              "type": "string",
                                                              "description": "Rule operator",
                                                              "example": "CONTAINS"
                                                            },
                                                            "value": {
                                                              "type": "string",
                                                              "description": "Rule value",
                                                              "example": "/products"
                                                            }
                                                          },
                                                          "required": [
                                                            "operator",
                                                            "value"
                                                          ],
                                                          "title": "StringRuleItemDTO"
                                                        }
                                                      ]
                                                    }
                                                  },
                                                  "required": [
                                                    "name",
                                                    "stringRuleItem"
                                                  ],
                                                  "title": "RuleItemDTO"
                                                }
                                              }
                                            },
                                            "required": [
                                              "ruleItems"
                                            ],
                                            "title": "RuleItemGroupDTO"
                                          }
                                        }
                                      },
                                      "required": [
                                        "ruleItemGroups"
                                      ],
                                      "title": "RuleDTO"
                                    }
                                  ]
                                }
                              },
                              "required": [
                                "lookbackWindowDays",
                                "rule"
                              ],
                              "title": "RuleOperandDTO"
                            }
                          }
                        },
                        "required": [
                          "inclusiveOperands",
                          "exclusiveOperands"
                        ],
                        "title": "FlexibleRuleUserListDTO"
                      }
                    ]
                  }
                },
                "required": [
                  "flexibleRuleUserList"
                ],
                "title": "RuleBasedUserListDTO"
              }
            ]
          },
          "membershipLifeSpan": {
            "type": "number",
            "description": "Membership life span",
            "example": 30
          },
          "seedUserListIds": {
            "description": "Seed user list IDs",
            "example": [
              "list_1"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "countryCodes": {
            "description": "Country codes",
            "example": [
              "US",
              "CA"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "expansionLevel": {
            "type": "string",
            "description": "Expansion level",
            "example": "BALANCED",
            "enum": [
              "BALANCED",
              "BROAD",
              "NARROW"
            ]
          }
        },
        "required": [
          "name"
        ],
        "title": "UpsertSegmentDTO"
      },
      "UpsertSegmentResponse": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "resourceName": {
                "type": "string",
                "description": "Google Ads resource name",
                "example": "customers/6776452901/customAudiences/874396901"
              },
              "id": {
                "type": "string",
                "description": "Segment id",
                "example": "874396901"
              },
              "status": {
                "type": "string",
                "description": "Segment status",
                "example": "ENABLED"
              },
              "name": {
                "type": "string",
                "description": "Segment name",
                "example": "Running shoe shoppers"
              },
              "type": {
                "type": "string",
                "description": "Google custom-audience type. `AUTO` is the default applied when none is supplied on create.",
                "example": "AUTO"
              },
              "members": {
                "description": "Keywords, URLs and apps that define the segment",
                "example": [
                  {
                    "memberType": "KEYWORD",
                    "keyword": "running shoes",
                    "url": "www.example.com",
                    "app": "app.example.com"
                  }
                ],
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "memberType": {
                      "type": "string",
                      "description": "Which member field is populated on this entry",
                      "enum": [
                        "KEYWORD",
                        "URL",
                        "APP"
                      ],
                      "example": "KEYWORD"
                    },
                    "keyword": {
                      "type": "string",
                      "description": "Keyword, present when memberType is KEYWORD",
                      "example": "running shoes"
                    },
                    "url": {
                      "type": "string",
                      "description": "URL, present when memberType is URL",
                      "example": "www.example.com"
                    },
                    "app": {
                      "type": "string",
                      "description": "App identifier, present when memberType is APP",
                      "example": "app.example.com"
                    }
                  },
                  "required": [
                    "memberType"
                  ],
                  "title": "GoogleSegmentMemberDTO"
                }
              }
            },
            "required": [
              "resourceName",
              "id",
              "status",
              "name",
              "type",
              "members"
            ],
            "title": "GoogleSegmentDetailDTO"
          },
          {
            "type": "object",
            "properties": {
              "resourceName": {
                "type": "string",
                "description": "Google Ads resource name",
                "example": "customers/6776452901/userLists/9215680180"
              },
              "id": {
                "type": "string",
                "description": "User list id",
                "example": "9215680180"
              },
              "name": {
                "type": "string",
                "description": "User list name",
                "example": "Website visitors"
              },
              "type": {
                "type": "string",
                "description": "How the list is populated. Unlike the listing endpoint, this value is not remapped.",
                "enum": [
                  "CRM_BASED",
                  "RULE_BASED",
                  "LOOKALIKE",
                  "LOGICAL",
                  "EXTERNAL_REMARKETING",
                  "SIMILAR"
                ],
                "example": "RULE_BASED"
              },
              "description": {
                "type": "string",
                "description": "User list description",
                "example": "Visitors in the last 30 days"
              },
              "readOnly": {
                "type": "boolean",
                "description": "Whether the list can be edited through the API",
                "example": false
              },
              "accessReason": {
                "type": "string",
                "description": "Whether the account owns the list or it was shared in",
                "enum": [
                  "OWNED",
                  "SHARED"
                ],
                "example": "OWNED"
              },
              "sizeForDisplay": {
                "type": "string",
                "description": "Display-network size, returned as a string rather than a number",
                "example": "0"
              },
              "sizeForSearch": {
                "type": "string",
                "description": "Search-network size, returned as a string rather than a number",
                "example": "0"
              },
              "basicUserList": {
                "type": "object",
                "description": "Tag actions backing a basic list. Present for basic user lists only.",
                "additionalProperties": true,
                "example": {
                  "actions": [
                    {
                      "conversionAction": "customers/6776452901/conversionActions/7618389481"
                    }
                  ]
                }
              },
              "ruleBasedUserList": {
                "type": "object",
                "description": "Rule definition and pre-population status. Present for rule-based lists, and carries the flexible-rule operands when the list uses them.",
                "additionalProperties": true,
                "example": {
                  "prepopulationStatus": "FINISHED"
                }
              },
              "crmBasedUserList": {
                "type": "object",
                "description": "Source app for a CRM-based list. Present for CRM_BASED lists only.",
                "additionalProperties": true,
                "example": {
                  "uploadKeyType": "CONTACT_INFO",
                  "dataSourceType": "FIRST_PARTY"
                }
              },
              "logicalUserList": {
                "type": "object",
                "description": "Combination rules. Present for LOGICAL lists only.",
                "additionalProperties": true,
                "example": {
                  "rules": [
                    {
                      "operator": "ALL",
                      "ruleOperands": [
                        {
                          "userList": "customers/6776452901/userLists/9215680180"
                        }
                      ]
                    }
                  ]
                }
              },
              "lookalikeUserList": {
                "type": "object",
                "description": "Seed lists, country codes, and expansion level. Present for LOOKALIKE lists only.",
                "additionalProperties": true,
                "example": {
                  "seedUserListIds": [
                    "9215680180"
                  ],
                  "countryCodes": [
                    "US"
                  ],
                  "expansionLevel": "BALANCED"
                }
              },
              "extras": {
                "type": "object",
                "description": "This product's own record of the list, merged in when one exists locally. Absent for lists this service did not create.",
                "additionalProperties": true,
                "example": {
                  "locationId": "ve9EPM428h8vShlRW1KT",
                  "segmentId": "9215680180",
                  "source": "smartList"
                }
              }
            },
            "required": [
              "resourceName",
              "id",
              "name",
              "type"
            ],
            "title": "GoogleDataSegmentDetailDTO"
          }
        ]
      },
      "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/segments?locationId=<LOCATIONID>&type=<TYPE>' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "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": "AUTO",
  "id": "seg_123",
  "membershipStatus": "OPEN",
  "ruleBasedUserList": {
    "prepopulationStatus": "REQUESTED",
    "flexibleRuleUserList": {
      "inclusiveOperands": [
        {
          "lookbackWindowDays": 30,
          "rule": {
            "ruleItemGroups": [
              {
                "ruleItems": [
                  {
                    "name": "url__",
                    "stringRuleItem": {
                      "operator": "CONTAINS",
                      "value": "/products"
                    }
                  }
                ]
              }
            ]
          }
        }
      ],
      "exclusiveOperands": [
        {
          "lookbackWindowDays": 30,
          "rule": {
            "ruleItemGroups": [
              {
                "ruleItems": [
                  {
                    "name": "url__",
                    "stringRuleItem": {
                      "operator": "CONTAINS",
                      "value": "/products"
                    }
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  },
  "membershipLifeSpan": 30,
  "seedUserListIds": [
    "list_1"
  ],
  "countryCodes": [
    "US",
    "CA"
  ],
  "expansionLevel": "BALANCED"
}'
```

**Node.js**

```javascript
const options = {
  method: 'PUT',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    '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": "AUTO",
      "id": "seg_123",
      "membershipStatus": "OPEN",
      "ruleBasedUserList": {
        "prepopulationStatus": "REQUESTED",
        "flexibleRuleUserList": {
          "inclusiveOperands": [
            {
              "lookbackWindowDays": 30,
              "rule": {
                "ruleItemGroups": [
                  {
                    "ruleItems": [
                      {
                        "name": "url__",
                        "stringRuleItem": {
                          "operator": "CONTAINS",
                          "value": "/products"
                        }
                      }
                    ]
                  }
                ]
              }
            }
          ],
          "exclusiveOperands": [
            {
              "lookbackWindowDays": 30,
              "rule": {
                "ruleItemGroups": [
                  {
                    "ruleItems": [
                      {
                        "name": "url__",
                        "stringRuleItem": {
                          "operator": "CONTAINS",
                          "value": "/products"
                        }
                      }
                    ]
                  }
                ]
              }
            }
          ]
        }
      },
      "membershipLifeSpan": 30,
      "seedUserListIds": [
        "list_1"
      ],
      "countryCodes": [
        "US",
        "CA"
      ],
      "expansionLevel": "BALANCED"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/ad-publishing/google/segments?locationId=<LOCATIONID>&type=<TYPE>', 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/segments"

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

params = {
    "locationId": "<LOCATIONID>",
    "type": "<TYPE>"
}

payload = {
    "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": "AUTO",
    "id": "seg_123",
    "membershipStatus": "OPEN",
    "ruleBasedUserList": {
        "prepopulationStatus": "REQUESTED",
        "flexibleRuleUserList": {
            "inclusiveOperands": [
                {
                    "lookbackWindowDays": 30,
                    "rule": {
                        "ruleItemGroups": [
                            {
                                "ruleItems": [
                                    {
                                        "name": "url__",
                                        "stringRuleItem": {
                                            "operator": "CONTAINS",
                                            "value": "/products"
                                        }
                                    }
                                ]
                            }
                        ]
                    }
                }
            ],
            "exclusiveOperands": [
                {
                    "lookbackWindowDays": 30,
                    "rule": {
                        "ruleItemGroups": [
                            {
                                "ruleItems": [
                                    {
                                        "name": "url__",
                                        "stringRuleItem": {
                                            "operator": "CONTAINS",
                                            "value": "/products"
                                        }
                                    }
                                ]
                            }
                        ]
                    }
                }
            ]
        }
    },
    "membershipLifeSpan": 30,
    "seedUserListIds": [
        "list_1"
    ],
    "countryCodes": [
        "US",
        "CA"
    ],
    "expansionLevel": "BALANCED"
}

response = requests.put(url, params=params, 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/segments?locationId=<LOCATIONID>&type=<TYPE>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'PUT',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "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": "AUTO",
  "id": "seg_123",
  "membershipStatus": "OPEN",
  "ruleBasedUserList": {
    "prepopulationStatus": "REQUESTED",
    "flexibleRuleUserList": {
      "inclusiveOperands": [
        {
          "lookbackWindowDays": 30,
          "rule": {
            "ruleItemGroups": [
              {
                "ruleItems": [
                  {
                    "name": "url__",
                    "stringRuleItem": {
                      "operator": "CONTAINS",
                      "value": "/products"
                    }
                  }
                ]
              }
            ]
          }
        }
      ],
      "exclusiveOperands": [
        {
          "lookbackWindowDays": 30,
          "rule": {
            "ruleItemGroups": [
              {
                "ruleItems": [
                  {
                    "name": "url__",
                    "stringRuleItem": {
                      "operator": "CONTAINS",
                      "value": "/products"
                    }
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  },
  "membershipLifeSpan": 30,
  "seedUserListIds": [
    "list_1"
  ],
  "countryCodes": [
    "US",
    "CA"
  ],
  "expansionLevel": "BALANCED"
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .put("https://services.leadconnectorhq.com/ad-publishing/google/segments?locationId=<LOCATIONID>&type=<TYPE>")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"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\":\"AUTO\",\"id\":\"seg_123\",\"membershipStatus\":\"OPEN\",\"ruleBasedUserList\":{\"prepopulationStatus\":\"REQUESTED\",\"flexibleRuleUserList\":{\"inclusiveOperands\":[{\"lookbackWindowDays\":30,\"rule\":{\"ruleItemGroups\":[{\"ruleItems\":[{\"name\":\"url__\",\"stringRuleItem\":{\"operator\":\"CONTAINS\",\"value\":\"/products\"}}]}]}}],\"exclusiveOperands\":[{\"lookbackWindowDays\":30,\"rule\":{\"ruleItemGroups\":[{\"ruleItems\":[{\"name\":\"url__\",\"stringRuleItem\":{\"operator\":\"CONTAINS\",\"value\":\"/products\"}}]}]}}]}},\"membershipLifeSpan\":30,\"seedUserListIds\":[\"list_1\"],\"countryCodes\":[\"US\",\"CA\"],\"expansionLevel\":\"BALANCED\"}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/ad-publishing/google/segments?locationId=<LOCATIONID>&type=<TYPE>"
  payload := strings.NewReader(`{
  "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": "AUTO",
  "id": "seg_123",
  "membershipStatus": "OPEN",
  "ruleBasedUserList": {
    "prepopulationStatus": "REQUESTED",
    "flexibleRuleUserList": {
      "inclusiveOperands": [
        {
          "lookbackWindowDays": 30,
          "rule": {
            "ruleItemGroups": [
              {
                "ruleItems": [
                  {
                    "name": "url__",
                    "stringRuleItem": {
                      "operator": "CONTAINS",
                      "value": "/products"
                    }
                  }
                ]
              }
            ]
          }
        }
      ],
      "exclusiveOperands": [
        {
          "lookbackWindowDays": 30,
          "rule": {
            "ruleItemGroups": [
              {
                "ruleItems": [
                  {
                    "name": "url__",
                    "stringRuleItem": {
                      "operator": "CONTAINS",
                      "value": "/products"
                    }
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  },
  "membershipLifeSpan": 30,
  "seedUserListIds": [
    "list_1"
  ],
  "countryCodes": [
    "US",
    "CA"
  ],
  "expansionLevel": "BALANCED"
}`)
  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/google/segments?locationId=<LOCATIONID>&type=<TYPE>")

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 = '{
  "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": "AUTO",
  "id": "seg_123",
  "membershipStatus": "OPEN",
  "ruleBasedUserList": {
    "prepopulationStatus": "REQUESTED",
    "flexibleRuleUserList": {
      "inclusiveOperands": [
        {
          "lookbackWindowDays": 30,
          "rule": {
            "ruleItemGroups": [
              {
                "ruleItems": [
                  {
                    "name": "url__",
                    "stringRuleItem": {
                      "operator": "CONTAINS",
                      "value": "/products"
                    }
                  }
                ]
              }
            ]
          }
        }
      ],
      "exclusiveOperands": [
        {
          "lookbackWindowDays": 30,
          "rule": {
            "ruleItemGroups": [
              {
                "ruleItems": [
                  {
                    "name": "url__",
                    "stringRuleItem": {
                      "operator": "CONTAINS",
                      "value": "/products"
                    }
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  },
  "membershipLifeSpan": 30,
  "seedUserListIds": [
    "list_1"
  ],
  "countryCodes": [
    "US",
    "CA"
  ],
  "expansionLevel": "BALANCED"
}'

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

**PowerShell**

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

$body = '{
  "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": "AUTO",
  "id": "seg_123",
  "membershipStatus": "OPEN",
  "ruleBasedUserList": {
    "prepopulationStatus": "REQUESTED",
    "flexibleRuleUserList": {
      "inclusiveOperands": [
        {
          "lookbackWindowDays": 30,
          "rule": {
            "ruleItemGroups": [
              {
                "ruleItems": [
                  {
                    "name": "url__",
                    "stringRuleItem": {
                      "operator": "CONTAINS",
                      "value": "/products"
                    }
                  }
                ]
              }
            ]
          }
        }
      ],
      "exclusiveOperands": [
        {
          "lookbackWindowDays": 30,
          "rule": {
            "ruleItemGroups": [
              {
                "ruleItems": [
                  {
                    "name": "url__",
                    "stringRuleItem": {
                      "operator": "CONTAINS",
                      "value": "/products"
                    }
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  },
  "membershipLifeSpan": 30,
  "seedUserListIds": [
    "list_1"
  ],
  "countryCodes": [
    "US",
    "CA"
  ],
  "expansionLevel": "BALANCED"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/ad-publishing/google/segments?locationId=<LOCATIONID>&type=<TYPE>' -Method 'PUT' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
