Add contacts to the audience

SDK platic.campaigns.audience.add()

Add contacts to a campaign audience using one source:

  • clients: phone number and name. Contacts that do not exist in the workspace are created.
  • searchId: all results of a contact search.
  • tag: all contacts with that tag.
  • clientIds: a list of ids.

Example

await platic.campaigns.audience.add("campaign_123", [{ phoneNumber: "5215512345678", name: "Ana López" }]);

Path parameters

ParameterTypeDescriptionRequirement
campaignIdstringUnique identifier of the campaignrequired

Request body

{
  "clients": [
    { "phoneNumber": "521234567890", "name": "John Smith" },
    { "phoneNumber": "521234567891", "name": "Maria Garcia" }
  ]
}

From a search, a tag, or ids

{ "searchId": "srch_4f9a2c", "dryRun": true }

With dryRun: true, it counts how many contacts would be added without changing the audience.

Body parameters

Send exactly one source: clients, searchId, tag, or clientIds.

ParameterTypeDescriptionRequirement
clientsarrayList of contacts to add by phone. At least 1 itemone source
searchIdstringThe searchId from search contacts: adds all its results, not just the page you saw. It lasts 12 hoursone source
topNnumberWith searchId, only the first N resultsoptional
tagstringAdds all the contacts with that tagone source
clientIdsstring[]Contact ids from the workspace, up to 5,000one source
dryRunbooleantrue to only count how many would come in. It does not apply to clientsoptional

clients[] object

ParameterTypeDescriptionRequirement
phoneNumberstringPhone number in international formatrequired
namestringName of the contactrequired

Response

{
  "status": "success",
  "message": "2 client(s) added to campaign (1 created, 1 updated)",
  "data": {
    "addedCount": 2,
    "createdCount": 1,
    "updatedCount": 1,
    "clients": [
      { "phoneNumber": "521234567890", "name": "John Smith" },
      { "phoneNumber": "521234567891", "name": "Maria Garcia" }
    ]
  }
}

Response fields

FieldTypeDescription
addedCountnumberTotal contacts processed
createdCountnumberNew contacts created in the workspace
updatedCountnumberExisting contacts updated with the campaign's tag
clientsarrayList of contacts sent in the request

Response with a source

{
  "status": "success",
  "message": "312 contacts were added to the audience",
  "data": {
    "source": "search",
    "dryRun": false,
    "message": "312 contacts were added to the audience",
    "added": 312,
    "skipped": 4
  }
}

source identifies the source: search, tag, or client_ids. Platica can include the added, created, updated, and skipped counts when it reports them.

With dryRun, preview shows how many contacts would be added and errors includes up to 10 problems.

A missing searchId returns 404 SEARCH_NOT_FOUND. An expired one returns 410 SEARCH_EXPIRED. Run a new search in either case.

Notes

  • If the contact already exists (same phoneNumber), its name is updated and the campaign's tag is added.
  • If the contact does not exist, a minimal record is created with phoneNumber, name, tags, owners, customFields, creationDate, and lastUpdate.
  • The tag assigned to the contacts has the format campaign-{campaignId}.