Skip to content
Codelia SMSDocs
Guides: Contacts and lists

Contacts and lists

A contact is a person you message, and their phone number is what identifies them in your organization. A list groups contacts, so a campaign can send to all of them by the list's ID in listIds.

Add a contact

Send the contact to POST /organizations/{accountId}/contacts. The API key needs contacts:write:

curl -X POST "https://api.sms.codelia.studio/v1/organizations/$CODELIA_ACCOUNT_ID/contacts" \
  -H "Authorization: Bearer $CODELIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "phone": "+442079460130",
  "firstName": "Ada",
  "lastName": "Lovelace",
  "email": "ada@example.com",
  "preferredLanguage": "en",
  "birthday": {
    "day": 14,
    "month": 3
  },
  "metadata": {
    "loyaltyTier": "gold"
  }
}'
FieldWhat to send
phoneRequired. The number in international format, like +442079460123.
firstName, lastNameUp to 120 characters each.
emailAn email address, up to 320 characters.
preferredLanguageA lowercase two-letter language code, like el, from GET /languages. A message sent in several languages gives this person theirs. See Send in each person's language.
birthdayAn object, like { "day": 14, "month": 3, "year": 1990 }. day is 1 to 31 and month is 1 to 12. year is optional, from 1900 to this year. 29 February is accepted with no year or with a leap year. Send null to remove it.
metadataYour own keys and text values, up to 32 keys, each value up to 200 characters. A campaign's placeholders can use them.

Every contact you read has birthday: null when it isn't set, and with year set to null when no year was given.

The answer is 201 with the contact: keep its id. A number that's already one of your contacts is refused with 409 and contact_exists: update that contact instead.

Find contacts

List them, newest first, with contacts:read:

curl "https://api.sms.codelia.studio/v1/organizations/$CODELIA_ACCOUNT_ID/contacts?q=Ada&limit=50" \
  -H "Authorization: Bearer $CODELIA_API_KEY"
  • q is split into words, and each word must match the first name, last name, email or number, so Ada Lov finds Ada Lovelace.
  • filter narrows the list with a rule, sent as URL-encoded JSON in the same shape as a smart list's definition. It applies together with q.
  • limit is up to 200, and 50 if you leave it out. The answer's nextCursor gets the next page: see Paging through results.
  • Each contact has an optOut field only when the API key holds opt-outs:read: { "scope": "organization" } when their number opted out, null when it didn't.

Get one contact with GET /organizations/{accountId}/contacts/{contactId}. GET /organizations/{accountId}/contacts/facets lists the languages and countries your contacts have, each with how many have it, most common first.

Change or delete a contact

These need contacts:write:

  • PATCH /organizations/{accountId}/contacts/{contactId} changes the fields you send and leaves the rest. The number can't be changed: delete the contact and add it again. A birthday you send replaces the whole birthday, so one without year removes a stored year.
  • DELETE /organizations/{accountId}/contacts/{contactId} removes the contact and takes it off every list. Messages already sent to the number are unaffected, and so is the number's opt-out.
  • POST /organizations/{accountId}/contacts/delete with up to 1,000 contactIds deletes several at once. IDs that aren't your contacts are counted in skipped.

Import contacts

POST /organizations/{accountId}/contacts/import takes up to 10,000 rows and matches each on its phone number. The API key needs contacts:write:

curl -X POST "https://api.sms.codelia.studio/v1/organizations/$CODELIA_ACCOUNT_ID/contacts/import" \
  -H "Authorization: Bearer $CODELIA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: import-newsletter-2026-10" \
  -d '{
  "rows": [
    {
      "phone": "+442079460131",
      "firstName": "Grace",
      "lastName": "Hopper",
      "language": "en",
      "birthday": "14/03/1990",
      "loyaltyTier": "silver"
    },
    {
      "phone": "+442079460132",
      "firstName": "Alan",
      "email": "alan@example.com"
    }
  ],
  "listName": "Newsletter"
}'
  • A row for a number you already have updates that contact. A row that changes nothing is counted in skipped.
  • phone, firstName, lastName, email, language and birthday are read by name. Any other key is kept in the contact's metadata, ready for placeholders: up to 32, with each value cut to 200 characters.
  • language sets the contact's preferred language: a two-letter code, in any case, so EL is Greek. An empty value leaves an existing preference as it is.
  • birthday sets the contact's birthday, as text: DD/MM, DD/MM/YYYY or YYYY-MM-DD. It's read day first, so 05/03 is 5 March, and 03/14 isn't a date. A spreadsheet's date number isn't read, so send the date as text. An empty value leaves an existing birthday as it is.
  • A row that can't be imported is listed in failed, with its row number (the first row is 1) and a code: invalid_phone, invalid_language, invalid_birthday or duplicate_in_file. The other rows are still imported.
  • Add listName to put everyone in the file on that list, creating the list if you don't have one by that name, or listId for a list you have. Send one or the other, not both.
  • The answer counts imported, updated and skipped, lists failed, and gives the list's listId.

An import takes an Idempotency-Key, so a retry after a timeout gets the first answer back, with the same counts. See Retrying safely.

Lists

A list is one of two kinds, in its kind field:

  • static: the contacts you put in it.
  • smart: a saved filter. Its members are whoever matches the filter when it's read or sent to, so it fills itself as your contacts change.

GET /organizations/{accountId}/contact-lists lists every list, newest first, each with its memberCount. These calls need contact-lists:read, and changes need contact-lists:write.

Create a list

A list name is unique in your organization. A list with no definition is static:

curl -X POST "https://api.sms.codelia.studio/v1/organizations/$CODELIA_ACCOUNT_ID/contact-lists" \
  -H "Authorization: Bearer $CODELIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Spring sale",
  "description": "Customers who asked to hear about sales."
}'

The answer is 201 with the list: keep its id. A name you already use is refused with 409 and contact_list_exists.

Smart lists

Send a definition and the list is smart. Supplying a filter also needs contacts:read, because the answer counts who it matches:

curl -X POST "https://api.sms.codelia.studio/v1/organizations/$CODELIA_ACCOUNT_ID/contact-lists" \
  -H "Authorization: Bearer $CODELIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Greek speakers",
  "definition": {
    "version": 1,
    "match": "all",
    "conditions": [
      {
        "field": "preferredLanguage",
        "operator": "in",
        "value": [
          "el"
        ]
      }
    ]
  }
}'
  • version is 1. match is all (the default) or any, and there can be up to 20 conditions.
  • Your organization can have up to 25 smart lists. Past that, creating one is refused with 409 and smart_list_limit_reached.
  • A condition on optedOut also needs opt-outs:read, and one on list needs contact-lists:read.

The conditions a filter can use:

fieldoperator
preferredLanguage, countryCodein or notIn, with value as a list of codes; isSet; isEmpty
firstName, lastName, emailis, contains or startsWith, with value; isSet; isEmpty
phoneis, contains or startsWith, with value
createdAtinLast or notInLast, with days; before or after, with value; between, with from and to
listin or notIn, with value as up to 10 list IDs
optedOutis, with value true or false
birthdaythisMonth; inMonth, with value as up to 12 month numbers from 1 to 12; isSet; isEmpty

Three things to know before you rely on a count:

  • notIn also matches contacts with no value at all. Add an isSet condition on the same field for only those who have one.
  • inLast and notInLast count back from when the list is read or sent to, not from when you saved it.
  • thisMonth is the month when the list is read or sent to, not when you saved it, so on 1 April it holds April's birthdays. The month is the calendar month in UTC.

A list condition can name only static lists: a smart list there is refused with 400 and smart_list_reference.

To try a filter before you save it, send it as definition to POST /organizations/{accountId}/contact-lists/preview. It answers with how many contacts match, in count, and up to 25 of them, in sample, and saves nothing. It needs contact-lists:read and contacts:read.

Change or delete a list

  • PATCH /organizations/{accountId}/contact-lists/{listId} renames a list, or changes a smart list's definition. A list can't change kind: that's refused with 409 and list_kind_immutable.
  • DELETE /organizations/{accountId}/contact-lists/{listId} removes the list. Its contacts stay. A list that a smart list's filter uses can't be deleted: 409 and list_referenced_by_filter.

Every organization has a built-in list of all its contacts. It has a reservedKey, and it can't be renamed, changed or deleted.

Who's on a list

Add contacts to a static list by their IDs, up to 1,000 per request:

curl -X POST "https://api.sms.codelia.studio/v1/organizations/$CODELIA_ACCOUNT_ID/contact-lists/$LIST_ID/members" \
  -H "Authorization: Bearer $CODELIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "contactIds": [
    "'"$CONTACT_ID"'"
  ]
}'
  • Adding a contact who's already on the list changes nothing. IDs that aren't your contacts are counted in skipped.
  • DELETE /organizations/{accountId}/contact-lists/{listId}/members/{contactId} takes one contact off the list. They stay in your contacts.
  • A smart list has no members to add or remove: that's refused with 409 and smart_list_not_editable. Change its filter instead.

See who's on a list:

curl "https://api.sms.codelia.studio/v1/organizations/$CODELIA_ACCOUNT_ID/contact-lists/$LIST_ID/members?limit=200&offset=0" \
  -H "Authorization: Bearer $CODELIA_API_KEY"

The answer is the contacts themselves: the most recently added first on a static list, and the newest contact first on a smart list. It pages by limit (up to 500, and 200 if you leave it out) and offset. See Paging through results.

People who opted out stay on your lists, and your marketing messages skip them. See Opt-outs.

When it's refused

When a request is refused, nothing changes.

StatuserrorWhat happenedWhat to do
400invalid_phoneThe phone number couldn't be read as an international number.Include the country code, like +442079460123.
400smart_list_referenceA filter uses a smart list, and a filter can use only static lists.Filter on static lists only.
400unknown_list_referenceA filter uses a list that doesn't exist in your organization.Check the list IDs in the filter.
400validation_errorA birthday isn't a date: a day the month doesn't have, 29 February in a year that isn't a leap year, a year before 1900 or after this one, or a day without a month. errors.birthday says which.Send a real date, or null for no birthday.
404contact_list_not_foundAn import's listId isn't a list in your organization.Check the list ID, or send listName instead.
409contact_existsA contact with this phone number already exists in your organization.Update that contact instead.
409contact_list_existsA list with this name already exists.Choose another name.
409list_kind_immutableA change would turn a static list into a smart list, or the other way.Create a new list of the kind you need.
409list_referenced_by_filterA smart list's filter uses this list, so it can't be deleted.Change that smart list's filter, or delete it first.
409reserved_list_not_editableThe built-in list of all your contacts can't be changed.Create a list of your own.
409reserved_list_not_deletableThe built-in list of all your contacts can't be deleted.Nothing to do.
409smart_list_limit_reachedYour organization already has 25 smart lists.Delete one before you create another.
409smart_list_not_editablePeople can't be added to or removed from a smart list by hand.Change its filter instead.
409smart_list_not_importableAn import can't add people to a smart list.Import into a static list.

Every code, including the ones any request can get, is on Errors and limits.