Tag a conversation

SDK platic.conversations.tags.set()
SDK platic.conversations.tags.update()

Two ways to change the tags of a conversation:

  • PUT replaces the list: the conversation ends with exactly the tags you send. An empty list removes them all.
  • PATCH adds and removes some tags in one step, without sending the whole list.

Every tag must already exist in the workspace: these actions never create one. Create a tag first.

Example

// Add and remove
await platic.conversations.tags.update("8Yc2kQ1mZ0rTq4Lp7WvX", { add: ["vip"], remove: ["new"] });

// Replace, guarded by the version you read
const { data, meta } = await platic.conversations.get("8Yc2kQ1mZ0rTq4Lp7WvX", { fields: ["tags"] });
await platic.conversations.tags.set(
  "8Yc2kQ1mZ0rTq4Lp7WvX",
  { tags: [...(data.tags ?? []), "refund"] },
  { expectedVersion: meta.resourceVersion },
);

The SDK sends an Idempotency-Key on every action and reuses it when it retries. A tag the workspace does not have throws InvalidConfigError with code UNKNOWN_TAG.

Use PATCH when you only want to add or remove a few tags: two callers can do it at the same time without overwriting each other. Use PUT when you have the whole list, and send If-Resource-Version so you do not overwrite a change made since you read it.

How tags are matched

  • Name a tag by its name (any casing) or by its tag id. The conversation stores its name, as listed in Tags.
  • remove also accepts a tag the conversation still has after it was deleted from the workspace.
  • add and remove cannot name the same tag.
  • Adding a tag the conversation has, or removing one it does not have, changes nothing. If nothing changes, the answer has meta.changed: false: nothing is written and no webhook is sent.
  • A conversation can have up to 20 tags.
  • Changing tags does not count as activity: lastActivityAt and the inbox order stay the same.

Path parameters

ParameterTypeDescriptionRequired
conversationIdstringThe conversation's id. See How IDs work✓

Headers

HeaderDescriptionRequired
Idempotency-KeyMakes the call safe to retry. 1 to 255 visible ASCII characters; a UUID works. See Retries—
If-Resource-VersionPUT only. The meta.resourceVersion of your last read or action. If the conversation changed since then, the answer is 412 VERSION_MISMATCH and nothing changes. Without it, the last write wins. PATCH does not need it: sending it returns 400 INVALID_REQUEST—

Query parameters

ParameterTypeDescription
fieldsstringFields of the conversation to return, comma-separated. Replaces the defaults; id is always returned. The fields are the same as in Get a conversation
includestringRelations to resolve in included: agents, channels, assignees
workspacestringThe workspace, for an API key that covers several. Other credentials always act on their own workspace

Request body

PUT: replace

FieldTypeRequiredDescription
tagsstring[]✓The tags the conversation ends with, up to 20. Each one 1 to 100 characters and existing in the workspace. [] removes them all
{
  "tags": ["vip", "refund"]
}

PATCH: add and remove

Send add, remove or both.

FieldTypeRequiredDescription
addstring[]—Tags to add, up to 20. Each must exist in the workspace
removestring[]—Tags to remove, up to 20
{
  "add": ["vip"],
  "remove": ["new"]
}

Any other field returns 400 INVALID_REQUEST.

Response

The answer is the conversation after the change, read with fields and include as in Get a conversation, and a meta that says what the action did. This example used ?fields=id,tags.

{
  "status": "success",
  "data": {
    "id": "8Yc2kQ1mZ0rTq4Lp7WvX",
    "tags": ["vip", "refund"]
  },
  "meta": {
    "fields": ["id", "tags"],
    "include": [],
    "requestId": "req_7f3c",
    "resourceVersion": "MTc2NDYxMjAwMC4xMjM0NTY3ODk",
    "action": "tags",
    "changed": true,
    "effects": {
      "added": ["vip"],
      "removed": ["new"]
    },
    "replayed": false
  }
}
FieldDescription
dataThe conversation as it is now, with the selected fields
includedRelated records, only when you sent include
meta.actionAlways tags
meta.changedfalse when the conversation already had that result: nothing was written and no webhook was sent
meta.effects.addedTags the conversation did not have before
meta.effects.removedTags the conversation no longer has
meta.resourceVersionThe conversation's version after the change. Send it in If-Resource-Version on your next PUT
meta.replayedtrue when this is the stored outcome of an earlier call with the same Idempotency-Key. Nothing ran again; data and resourceVersion show the conversation as it is now
meta.fields · meta.includeFields and relations applied
meta.requestIdID of the request, for support
meta.warningsOnly when there is something to report. CONVERSATION_NOT_READABLE: the change was applied, but your credential can no longer read the conversation, so data has only id

Retries

Send an Idempotency-Key so a retry after a lost answer is safe. A key belongs to one credential, one action and one conversation.

  • Same key, same body: you get the first outcome with meta.replayed: true. Nothing runs again. fields and include may change: they only choose what the answer shows.
  • Same key, different body: 409 IDEMPOTENCY_KEY_REUSED. Use a new key for a new change.
  • First call still running: 409 IDEMPOTENCY_IN_PROGRESS. Retry in a few seconds with the same key.
  • Lifetime: keys are kept for one day. A call that fails does not keep its key, so retrying it runs the action again.

Your access is checked again on every retry. More in Idempotency.

Errors

Statusdetails.codeWhen it happens
400INVALID_REQUESTThe body, a query parameter or a header is not valid: a list with more than 20 tags, add and remove naming the same tag, or If-Resource-Version on PATCH. details.issues says which
400INVALID_REQUESTThe workspace in ?workspace= is not covered by the credential. details.available lists the ones it covers
400INVALID_FIELDA name in fields does not exist. details.allowed lists the accepted ones
400INVALID_INCLUDEA name in include does not exist. details.allowed lists the accepted ones
401UNAUTHENTICATEDThe credential is missing or invalid
403FORBIDDENThe credential cannot change conversations, or your role can read this conversation but not change it
403INSUFFICIENT_SCOPEAn OAuth token without the platica:write scope. details.requiredScope says which one is missing
404CONVERSATION_NOT_FOUNDNo conversation has that id in the workspace, or it is out of your credential's reach
409IDEMPOTENCY_KEY_REUSEDThe Idempotency-Key was already used with a different body
409IDEMPOTENCY_IN_PROGRESSThe first call with this Idempotency-Key is still running. Retry shortly with the same key
412VERSION_MISMATCHPUT only: If-Resource-Version is not the current version. details.currentVersion has it. Nothing changed: read the conversation again and repeat
422UNKNOWN_TAGSome tags do not exist in the workspace. details.unknownTags lists them and details.availableTags lists the ones that do. Create them first
422TOO_MANY_TAGSThe conversation would end with more than 20 tags
503ACTION_FAILEDThe outcome could not be confirmed (details.retryable: true). Repeat with the same Idempotency-Key: an action that already ran is not run again

The general error format is in Errors.

Notes

Every call that changes the tags sends conversation.tags.updated with source: "api.conversation.v2.tags".