# Upsert adset

PUT https://services.leadconnectorhq.com/ad-publishing/facebook/adsets

Create or update a Facebook ad set

## 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": "v4"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/ad-publishing/facebook/adsets": {
      "put": {
        "summary": "Upsert adset",
        "operationId": "upsertAdset",
        "description": "Create or update a Facebook ad set",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v4"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpsertAdsetDTO"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The saved ad set",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FacebookAdsetDTO"
                }
              }
            }
          },
          "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": {
      "UpsertAdsetDTO": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Ad set identifier",
            "example": "adset_123"
          },
          "locationId": {
            "type": "string",
            "description": "Location identifier",
            "example": "loc_abc123"
          },
          "name": {
            "type": "string",
            "description": "Ad set name",
            "example": "Targeting Group A"
          },
          "pageId": {
            "type": "string",
            "description": "Facebook page ID",
            "example": "123456789"
          },
          "instagramActorId": {
            "type": "string",
            "description": "Instagram actor ID",
            "example": "ig_123"
          },
          "messagingPlatforms": {
            "type": "array",
            "description": "Messaging platforms",
            "example": [
              "WHATSAPP"
            ],
            "items": {
              "type": "string",
              "enum": [
                "WHATSAPP",
                "MESSENGER",
                "INSTAGRAM_DIRECT"
              ]
            }
          },
          "whatsappNumber": {
            "type": "string",
            "description": "WhatsApp phone number",
            "example": "+1234567890"
          },
          "audience": {
            "description": "Targeting audience configuration including geo-locations, locales, placements, and custom audiences",
            "example": {
              "geoLocations": [
                {
                  "key": "US",
                  "name": "United States",
                  "type": "country",
                  "selectionType": "include"
                }
              ],
              "ageMin": 18,
              "ageMax": 65,
              "genders": [
                1,
                2
              ]
            },
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "geoLocations": {
                    "description": "Geographic locations to target or exclude",
                    "example": [
                      {
                        "key": "US",
                        "name": "United States",
                        "type": "country",
                        "selectionType": "include"
                      },
                      {
                        "key": "2421836",
                        "name": "New York",
                        "type": "city",
                        "selectionType": "include",
                        "radius": 25,
                        "radiusUnit": "mile"
                      }
                    ],
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "key": {
                          "type": "string",
                          "description": "Facebook location key",
                          "example": "US"
                        },
                        "name": {
                          "type": "string",
                          "description": "Location display name",
                          "example": "United States"
                        },
                        "type": {
                          "type": "string",
                          "description": "Geographic location type",
                          "example": "country",
                          "enum": [
                            "country",
                            "city",
                            "region",
                            "country_group",
                            "geo_market",
                            "large_geo_area",
                            "medium_geo_area",
                            "small_geo_area",
                            "subcity",
                            "neighborhood",
                            "zip",
                            "address"
                          ]
                        },
                        "selectionType": {
                          "type": "string",
                          "description": "Whether the location is included or excluded from targeting",
                          "example": "include",
                          "enum": [
                            "include",
                            "exclude"
                          ]
                        },
                        "radius": {
                          "type": "number",
                          "description": "Targeting radius around the location (for city/address types)",
                          "example": 25
                        },
                        "radiusUnit": {
                          "type": "string",
                          "description": "Unit for the targeting radius",
                          "example": "mi",
                          "enum": [
                            "km",
                            "mi"
                          ]
                        },
                        "geometry": {
                          "description": "Geometry data for address-based targeting",
                          "example": {
                            "location": {
                              "lat": 40.7128,
                              "lng": -74.006
                            },
                            "locationType": "APPROXIMATE"
                          },
                          "allOf": [
                            {
                              "type": "object",
                              "properties": {
                                "location": {
                                  "type": "object",
                                  "description": "Geographic coordinates",
                                  "example": {
                                    "lat": 40.7128,
                                    "lng": -74.006
                                  }
                                },
                                "locationType": {
                                  "type": "string",
                                  "description": "Geocoding result type",
                                  "example": "APPROXIMATE"
                                }
                              },
                              "required": [
                                "location",
                                "locationType"
                              ],
                              "title": "AudienceLocationGeometry"
                            }
                          ]
                        },
                        "countryName": {
                          "type": "string",
                          "description": "Name of the country the location is in",
                          "example": "United States"
                        },
                        "countryCode": {
                          "type": "string",
                          "description": "ISO 3166-1 alpha-2 code of the country the location is in. Used to declare Meta regional regulated categories (e.g. Singapore, Taiwan).",
                          "example": "US"
                        }
                      },
                      "required": [
                        "key",
                        "name",
                        "type",
                        "selectionType"
                      ],
                      "title": "AudienceLocationDTO"
                    }
                  },
                  "locales": {
                    "description": "Language locales to target",
                    "example": [
                      {
                        "name": "English (US)",
                        "key": 6
                      }
                    ],
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": {
                          "type": "string",
                          "description": "Locale display name",
                          "example": "English (US)"
                        },
                        "key": {
                          "type": "number",
                          "description": "Facebook locale key",
                          "example": 6
                        }
                      },
                      "required": [
                        "name",
                        "key"
                      ],
                      "title": "AudienceLocaleDTO"
                    }
                  },
                  "placements": {
                    "description": "Ad placement positions per platform (only used when placementType is \"manual\")",
                    "example": {
                      "facebook": [
                        "feed"
                      ],
                      "instagram": [
                        "story"
                      ],
                      "messenger": [
                        "messenger_home"
                      ]
                    },
                    "allOf": [
                      {
                        "type": "object",
                        "properties": {
                          "facebook": {
                            "description": "Facebook placement positions",
                            "example": [
                              "feed",
                              "right_hand_column",
                              "marketplace"
                            ],
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          },
                          "instagram": {
                            "description": "Instagram placement positions",
                            "example": [
                              "stream",
                              "story",
                              "explore"
                            ],
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          },
                          "messenger": {
                            "description": "Messenger placement positions",
                            "example": [
                              "messenger_home"
                            ],
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          }
                        },
                        "title": "AudiencePlacementsDTO"
                      }
                    ]
                  },
                  "placementType": {
                    "type": "string",
                    "description": "Placement strategy — \"auto\" lets Facebook choose, \"manual\" uses the placements config",
                    "example": "auto",
                    "enum": [
                      "auto",
                      "manual"
                    ]
                  },
                  "lookalike": {
                    "description": "Lookalike audiences to target",
                    "example": [
                      {
                        "id": "23851234567890",
                        "name": "Lookalike - Website Visitors"
                      }
                    ],
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "Custom audience ID",
                          "example": "23851234567890"
                        },
                        "name": {
                          "type": "string",
                          "description": "Custom audience name",
                          "example": "Website Visitors - Last 30 Days"
                        }
                      },
                      "required": [
                        "id",
                        "name"
                      ],
                      "title": "AudienceCustomAudienceItemDTO"
                    }
                  },
                  "retargeting": {
                    "description": "Retargeting custom audiences to target",
                    "example": [
                      {
                        "id": "23851234567891",
                        "name": "Website Visitors - Last 30 Days"
                      }
                    ],
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "Custom audience ID",
                          "example": "23851234567890"
                        },
                        "name": {
                          "type": "string",
                          "description": "Custom audience name",
                          "example": "Website Visitors - Last 30 Days"
                        }
                      },
                      "required": [
                        "id",
                        "name"
                      ],
                      "title": "AudienceCustomAudienceItemDTO"
                    }
                  },
                  "interests": {
                    "description": "Interest-based targeting criteria",
                    "example": [
                      {
                        "id": "6003139266461",
                        "name": "Fitness and wellness",
                        "type": "interests"
                      }
                    ],
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "Interest ID",
                          "example": "6003139266461"
                        },
                        "name": {
                          "type": "string",
                          "description": "Interest name",
                          "example": "Fitness and wellness"
                        },
                        "type": {
                          "type": "string",
                          "description": "Interest category type (defaults to \"interests\" if omitted)",
                          "example": "interests"
                        }
                      },
                      "required": [
                        "id",
                        "name"
                      ],
                      "title": "AudienceInterestDTO"
                    }
                  },
                  "ageMin": {
                    "type": "number",
                    "description": "Minimum age for targeting",
                    "example": 18
                  },
                  "ageMax": {
                    "type": "number",
                    "description": "Maximum age for targeting",
                    "example": 65
                  },
                  "genders": {
                    "description": "Gender targeting (1 = male, 2 = female)",
                    "example": [
                      1,
                      2
                    ],
                    "type": "array",
                    "items": {
                      "type": "number"
                    }
                  }
                },
                "required": [
                  "geoLocations"
                ],
                "title": "FacebookAudienceDTO"
              }
            ]
          },
          "budget": {
            "description": "Ad set budget config; schedule only under a campaign budget",
            "example": {
              "budgetType": "DAILY",
              "amount": 1000,
              "scheduleStartDate": "2024-01-01",
              "scheduleEndDate": "2024-01-31"
            },
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "budgetType": {
                    "type": "string",
                    "description": "Budget type",
                    "example": "DAILY",
                    "enum": [
                      "DAILY",
                      "LIFETIME"
                    ]
                  },
                  "amount": {
                    "type": "number",
                    "description": "Ad set budget in account currency",
                    "example": 100
                  },
                  "scheduleStartDate": {
                    "type": "string",
                    "description": "Schedule start date",
                    "example": "2024-01-01"
                  },
                  "scheduleEndDate": {
                    "type": "string",
                    "description": "Schedule end date",
                    "example": "2024-01-31"
                  }
                },
                "title": "AdSetBudgetDTO"
              }
            ]
          },
          "bidAmount": {
            "type": "number",
            "description": "Bid cap or cost-per-result goal in account currency. Required when the campaign bid strategy is LOWEST_COST_WITH_BID_CAP or COST_CAP.",
            "example": 2.5
          },
          "conversionLocation": {
            "type": "string",
            "description": "Where the conversion happens. Valid values depend on the parent campaign objective — OUTCOME_LEADS: `on_ad` (instant form), `website`, `website_and_lead_form`; OUTCOME_SALES: `website` (pixel), `messaging`. Not validated server-side, so values outside this set are forwarded to Facebook and may be rejected there.",
            "example": "website"
          },
          "customEventType": {
            "type": "string",
            "description": "Facebook standard event optimised for. Only meaningful when `conversionLocation` is `website` (requires `pixelId`). Valid values depend on the parent campaign objective — OUTCOME_LEADS: `COMPLETE_REGISTRATION`, `CONTACT`, `CONTENT_VIEW`, `FIND_LOCATION`, `LEAD`, `SCHEDULE`, `SEARCH`, `START_TRIAL`, `SUBMIT_APPLICATION`, `SUBSCRIBE`; OUTCOME_SALES: `ADD_PAYMENT_INFO`, `ADD_TO_CART`, `ADD_TO_WISHLIST`, `COMPLETE_REGISTRATION`, `CONTENT_VIEW`, `DONATE`, `INITIATED_CHECKOUT`, `PURCHASE`, `SEARCH`, `START_TRIAL`, `SUBSCRIBE`. Not validated server-side, so values outside this set are forwarded to Facebook and may be rejected there.",
            "example": "PURCHASE"
          },
          "pixelId": {
            "type": "string",
            "description": "Conversion pixel ID",
            "example": "px_123"
          },
          "campaignId": {
            "type": "string",
            "description": "Parent campaign ID",
            "example": "camp_123"
          }
        },
        "required": [
          "locationId",
          "campaignId"
        ],
        "title": "UpsertAdsetDTO"
      },
      "FacebookAdsetDTO": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Ad set identifier",
            "example": "6a323f3f4454921db1498cd8"
          },
          "name": {
            "type": "string",
            "description": "Ad set name",
            "example": "Ad set 1"
          },
          "campaignId": {
            "type": "string",
            "description": "Parent campaign id",
            "example": "6a323f3e4454921db1498ccf"
          },
          "fbAdSetId": {
            "type": "string",
            "description": "Facebook ad set id, set once published",
            "example": "120250378906150122"
          },
          "publishingStatus": {
            "type": "string",
            "description": "Publishing status. On a published entity this is not the state you asked for but the `effective_status` Meta reports, mapped back — a pause or resume re-reads it live, so an ad awaiting review comes back `IN_REVIEW` rather than `PAUSED` or `PUBLISHED`. Any effective status this service does not recognise also maps to `IN_REVIEW`.",
            "enum": [
              "DRAFT",
              "SCHEDULED",
              "PUBLISHING",
              "PUBLISHED",
              "PAUSED",
              "IN_REVIEW",
              "WITH_ISSUES",
              "REJECTED",
              "ARCHIVED",
              "FAILED"
            ],
            "example": "PUBLISHED"
          },
          "fbError": {
            "type": "string",
            "description": "Publish error from Facebook. `null` on reads when there is none.",
            "example": null,
            "nullable": true
          },
          "pageId": {
            "type": "string",
            "description": "Page the ads run under",
            "example": "196684453527082"
          },
          "instagramActorId": {
            "type": "string",
            "description": "Instagram account the ads run under. `null` when not linked.",
            "example": null,
            "nullable": true
          },
          "messagingPlatforms": {
            "description": "Messaging destinations for click-to-message ads. Empty for other conversion locations.",
            "example": [
              "MESSENGER",
              "INSTAGRAM_DIRECT"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "conversionLocation": {
            "type": "string",
            "description": "Where the conversion happens",
            "example": "on_ad"
          },
          "budget": {
            "description": "Budget configuration",
            "example": {
              "budgetType": "DAILY",
              "amount": 1,
              "actualAmount": 1
            },
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "budgetType": {
                    "type": "string",
                    "description": "Budget cadence",
                    "example": "DAILY"
                  },
                  "amount": {
                    "type": "number",
                    "description": "Budget amount as entered",
                    "example": 1
                  },
                  "actualAmount": {
                    "type": "number",
                    "description": "Amount actually applied. Differs from `amount` on connect-your-BM pricing.",
                    "example": 1
                  }
                },
                "required": [
                  "budgetType",
                  "amount"
                ],
                "title": "FacebookAdsetBudgetDTO"
              }
            ]
          },
          "audience": {
            "description": "Targeting",
            "example": {
              "genders": [
                0
              ],
              "geoLocations": [
                {
                  "key": "IN",
                  "name": "India",
                  "type": "country",
                  "selectionType": "include",
                  "radius": 17,
                  "radiusUnit": "km",
                  "geometry": {
                    "location": {
                      "lat": 20.593684,
                      "lng": 78.96288
                    },
                    "locationType": "APPROXIMATE"
                  }
                }
              ],
              "ageMin": 18,
              "ageMax": 65,
              "interests": [
                {
                  "id": "6016286626383",
                  "name": "Facebook access (mobile): tablets",
                  "type": "behaviors"
                }
              ],
              "placements": {
                "facebook": [
                  "feed",
                  "story"
                ],
                "instagram": [
                  "reels"
                ],
                "messenger": [
                  "messenger_home"
                ]
              },
              "placementType": "manual"
            },
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "genders": {
                    "description": "Genders as Facebook numeric codes, not names — `0` all, `1` male, `2` female. Empty array also means all.",
                    "example": [
                      0
                    ],
                    "type": "array",
                    "items": {
                      "type": "number"
                    }
                  },
                  "geoLocations": {
                    "description": "Geographic targeting",
                    "example": [
                      {
                        "key": "IN",
                        "name": "India",
                        "type": "country",
                        "selectionType": "include",
                        "radius": 17,
                        "radiusUnit": "km",
                        "geometry": {
                          "location": {
                            "lat": 20.593684,
                            "lng": 78.96288
                          },
                          "locationType": "APPROXIMATE"
                        }
                      }
                    ],
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "key": {
                          "type": "string",
                          "description": "Facebook location key",
                          "example": "IN"
                        },
                        "name": {
                          "type": "string",
                          "description": "Location display name",
                          "example": "India"
                        },
                        "type": {
                          "type": "string",
                          "description": "Location granularity",
                          "example": "country"
                        },
                        "selectionType": {
                          "type": "string",
                          "description": "Whether the location is targeted or excluded",
                          "enum": [
                            "include",
                            "exclude"
                          ],
                          "example": "include"
                        },
                        "radius": {
                          "type": "number",
                          "description": "Targeting radius. `-1` means no radius, used for country-level targeting.",
                          "example": 17
                        },
                        "radiusUnit": {
                          "type": "string",
                          "description": "Unit for the radius",
                          "enum": [
                            "km",
                            "mi"
                          ],
                          "example": "km"
                        },
                        "geometry": {
                          "description": "Geocoded coordinates, stored for address-based targeting and echoed back on reads",
                          "example": {
                            "location": {
                              "lat": 20.593684,
                              "lng": 78.96288
                            },
                            "locationType": "APPROXIMATE"
                          },
                          "allOf": [
                            {
                              "type": "object",
                              "properties": {
                                "location": {
                                  "type": "object",
                                  "description": "Geocoded centre point of the location",
                                  "example": {
                                    "lat": 20.593684,
                                    "lng": 78.96288
                                  }
                                },
                                "locationType": {
                                  "type": "string",
                                  "description": "Precision of the geocoding result",
                                  "example": "APPROXIMATE"
                                }
                              },
                              "required": [
                                "location",
                                "locationType"
                              ],
                              "title": "FacebookGeoLocationGeometryDTO"
                            }
                          ]
                        }
                      },
                      "required": [
                        "key",
                        "name",
                        "type",
                        "selectionType"
                      ],
                      "title": "FacebookGeoLocationDTO"
                    }
                  },
                  "ageMin": {
                    "type": "number",
                    "description": "Minimum age targeted",
                    "example": 18
                  },
                  "ageMax": {
                    "type": "number",
                    "description": "Maximum age targeted",
                    "example": 65
                  },
                  "interests": {
                    "description": "Interest and behaviour targeting",
                    "example": [
                      {
                        "id": "6016286626383",
                        "name": "Facebook access (mobile): tablets",
                        "type": "behaviors"
                      }
                    ],
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "description": "Facebook targeting id",
                          "example": "6016286626383"
                        },
                        "name": {
                          "type": "string",
                          "description": "Display name",
                          "example": "Facebook access (mobile): tablets"
                        },
                        "type": {
                          "type": "string",
                          "description": "Which targeting taxonomy the entry came from",
                          "example": "behaviors"
                        }
                      },
                      "required": [
                        "id",
                        "name"
                      ],
                      "title": "FacebookAudienceInterestDTO"
                    }
                  },
                  "placements": {
                    "type": "object",
                    "description": "Placement positions per platform. Only meaningful when `placementType` is `manual`.",
                    "additionalProperties": true,
                    "example": {
                      "facebook": [
                        "feed",
                        "story"
                      ],
                      "instagram": [
                        "reels"
                      ],
                      "messenger": [
                        "messenger_home"
                      ]
                    }
                  },
                  "placementType": {
                    "type": "string",
                    "description": "Placement strategy",
                    "enum": [
                      "auto",
                      "manual"
                    ],
                    "example": "manual"
                  }
                },
                "required": [
                  "genders",
                  "geoLocations"
                ],
                "title": "FacebookAdsetAudienceDTO"
              }
            ]
          },
          "unpublishedChanges": {
            "type": "boolean",
            "description": "Whether the ad set has edits not yet published",
            "example": false
          },
          "createdAt": {
            "type": "string",
            "description": "Created at",
            "example": "2026-06-17T06:31:27.129Z"
          },
          "updatedAt": {
            "type": "string",
            "description": "Updated at",
            "example": "2026-08-19T11:42:35.835Z"
          }
        },
        "required": [
          "id",
          "name",
          "campaignId",
          "publishingStatus",
          "pageId",
          "messagingPlatforms",
          "budget",
          "audience",
          "createdAt",
          "updatedAt"
        ],
        "title": "FacebookAdsetDTO"
      },
      "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/facebook/adsets' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v4' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "id": "adset_123",
  "locationId": "loc_abc123",
  "name": "Targeting Group A",
  "pageId": "123456789",
  "instagramActorId": "ig_123",
  "messagingPlatforms": [
    "WHATSAPP"
  ],
  "whatsappNumber": "+1234567890",
  "audience": {
    "geoLocations": [
      {
        "key": "US",
        "name": "United States",
        "type": "country",
        "selectionType": "include"
      }
    ],
    "ageMin": 18,
    "ageMax": 65,
    "genders": [
      1,
      2
    ]
  },
  "budget": {
    "budgetType": "DAILY",
    "amount": 1000,
    "scheduleStartDate": "2024-01-01",
    "scheduleEndDate": "2024-01-31"
  },
  "bidAmount": 2.5,
  "conversionLocation": "website",
  "customEventType": "PURCHASE",
  "pixelId": "px_123",
  "campaignId": "camp_123"
}'
```

**Node.js**

```javascript
const options = {
  method: 'PUT',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v4',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "id": "adset_123",
      "locationId": "loc_abc123",
      "name": "Targeting Group A",
      "pageId": "123456789",
      "instagramActorId": "ig_123",
      "messagingPlatforms": [
        "WHATSAPP"
      ],
      "whatsappNumber": "+1234567890",
      "audience": {
        "geoLocations": [
          {
            "key": "US",
            "name": "United States",
            "type": "country",
            "selectionType": "include"
          }
        ],
        "ageMin": 18,
        "ageMax": 65,
        "genders": [
          1,
          2
        ]
      },
      "budget": {
        "budgetType": "DAILY",
        "amount": 1000,
        "scheduleStartDate": "2024-01-01",
        "scheduleEndDate": "2024-01-31"
      },
      "bidAmount": 2.5,
      "conversionLocation": "website",
      "customEventType": "PURCHASE",
      "pixelId": "px_123",
      "campaignId": "camp_123"
  })
};

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

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

payload = {
    "id": "adset_123",
    "locationId": "loc_abc123",
    "name": "Targeting Group A",
    "pageId": "123456789",
    "instagramActorId": "ig_123",
    "messagingPlatforms": [
        "WHATSAPP"
    ],
    "whatsappNumber": "+1234567890",
    "audience": {
        "geoLocations": [
            {
                "key": "US",
                "name": "United States",
                "type": "country",
                "selectionType": "include"
            }
        ],
        "ageMin": 18,
        "ageMax": 65,
        "genders": [
            1,
            2
        ]
    },
    "budget": {
        "budgetType": "DAILY",
        "amount": 1000,
        "scheduleStartDate": "2024-01-01",
        "scheduleEndDate": "2024-01-31"
    },
    "bidAmount": 2.5,
    "conversionLocation": "website",
    "customEventType": "PURCHASE",
    "pixelId": "px_123",
    "campaignId": "camp_123"
}

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/facebook/adsets',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'PUT',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v4',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "id": "adset_123",
  "locationId": "loc_abc123",
  "name": "Targeting Group A",
  "pageId": "123456789",
  "instagramActorId": "ig_123",
  "messagingPlatforms": [
    "WHATSAPP"
  ],
  "whatsappNumber": "+1234567890",
  "audience": {
    "geoLocations": [
      {
        "key": "US",
        "name": "United States",
        "type": "country",
        "selectionType": "include"
      }
    ],
    "ageMin": 18,
    "ageMax": 65,
    "genders": [
      1,
      2
    ]
  },
  "budget": {
    "budgetType": "DAILY",
    "amount": 1000,
    "scheduleStartDate": "2024-01-01",
    "scheduleEndDate": "2024-01-31"
  },
  "bidAmount": 2.5,
  "conversionLocation": "website",
  "customEventType": "PURCHASE",
  "pixelId": "px_123",
  "campaignId": "camp_123"
}',
]);

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

**Java**

```java
HttpResponse<String> response = Unirest
  .put("https://services.leadconnectorhq.com/ad-publishing/facebook/adsets")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v4")
  .header("Content-Type", "application/json")
  .body("{\"id\":\"adset_123\",\"locationId\":\"loc_abc123\",\"name\":\"Targeting Group A\",\"pageId\":\"123456789\",\"instagramActorId\":\"ig_123\",\"messagingPlatforms\":[\"WHATSAPP\"],\"whatsappNumber\":\"+1234567890\",\"audience\":{\"geoLocations\":[{\"key\":\"US\",\"name\":\"United States\",\"type\":\"country\",\"selectionType\":\"include\"}],\"ageMin\":18,\"ageMax\":65,\"genders\":[1,2]},\"budget\":{\"budgetType\":\"DAILY\",\"amount\":1000,\"scheduleStartDate\":\"2024-01-01\",\"scheduleEndDate\":\"2024-01-31\"},\"bidAmount\":2.5,\"conversionLocation\":\"website\",\"customEventType\":\"PURCHASE\",\"pixelId\":\"px_123\",\"campaignId\":\"camp_123\"}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/ad-publishing/facebook/adsets"
  payload := strings.NewReader(`{
  "id": "adset_123",
  "locationId": "loc_abc123",
  "name": "Targeting Group A",
  "pageId": "123456789",
  "instagramActorId": "ig_123",
  "messagingPlatforms": [
    "WHATSAPP"
  ],
  "whatsappNumber": "+1234567890",
  "audience": {
    "geoLocations": [
      {
        "key": "US",
        "name": "United States",
        "type": "country",
        "selectionType": "include"
      }
    ],
    "ageMin": 18,
    "ageMax": 65,
    "genders": [
      1,
      2
    ]
  },
  "budget": {
    "budgetType": "DAILY",
    "amount": 1000,
    "scheduleStartDate": "2024-01-01",
    "scheduleEndDate": "2024-01-31"
  },
  "bidAmount": 2.5,
  "conversionLocation": "website",
  "customEventType": "PURCHASE",
  "pixelId": "px_123",
  "campaignId": "camp_123"
}`)
  req, _ := http.NewRequest("PUT", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v4")

  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/facebook/adsets")

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

request = Net::HTTP::Put.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v4"
request["Content-Type"] = "application/json"
request.body = '{
  "id": "adset_123",
  "locationId": "loc_abc123",
  "name": "Targeting Group A",
  "pageId": "123456789",
  "instagramActorId": "ig_123",
  "messagingPlatforms": [
    "WHATSAPP"
  ],
  "whatsappNumber": "+1234567890",
  "audience": {
    "geoLocations": [
      {
        "key": "US",
        "name": "United States",
        "type": "country",
        "selectionType": "include"
      }
    ],
    "ageMin": 18,
    "ageMax": 65,
    "genders": [
      1,
      2
    ]
  },
  "budget": {
    "budgetType": "DAILY",
    "amount": 1000,
    "scheduleStartDate": "2024-01-01",
    "scheduleEndDate": "2024-01-31"
  },
  "bidAmount": 2.5,
  "conversionLocation": "website",
  "customEventType": "PURCHASE",
  "pixelId": "px_123",
  "campaignId": "camp_123"
}'

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

**PowerShell**

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

$body = '{
  "id": "adset_123",
  "locationId": "loc_abc123",
  "name": "Targeting Group A",
  "pageId": "123456789",
  "instagramActorId": "ig_123",
  "messagingPlatforms": [
    "WHATSAPP"
  ],
  "whatsappNumber": "+1234567890",
  "audience": {
    "geoLocations": [
      {
        "key": "US",
        "name": "United States",
        "type": "country",
        "selectionType": "include"
      }
    ],
    "ageMin": 18,
    "ageMax": 65,
    "genders": [
      1,
      2
    ]
  },
  "budget": {
    "budgetType": "DAILY",
    "amount": 1000,
    "scheduleStartDate": "2024-01-01",
    "scheduleEndDate": "2024-01-31"
  },
  "bidAmount": 2.5,
  "conversionLocation": "website",
  "customEventType": "PURCHASE",
  "pixelId": "px_123",
  "campaignId": "camp_123"
}'

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