Thread fields allow you to extend Plain’s thread data model. The thread fields which you want to support have to conform to a schema configured in SettingsThread fields.

Thread fields can be nested and be either a boolean, text or a string enum.

Thread fields can be required. When they are required, their value must be set in order for the thread to be marked as done.

For interacting with thread fields via the API, every field has a key defined in its schema. Keys make it possible to quickly refer to a thread field without having to know its ID in the schema. For example if you have a field called “Product Area” the key you might choose for the key to be product_area.

Upsert a thread field

To upsert a thread field you need an API key with the following permissions:

  • threadField:create
  • threadField:update
import { PlainClient, ThreadFieldSchemaType } from '@team-plain/typescript-sdk';

const client = new PlainClient({ apiKey: 'plainApiKey_xxx' });

const res = await client.upsertThreadField({
  identifier: {
    key: 'product_area',
    threadId: 'th_01HVNWFJS395XVPPBJNE6A8BHP',
  },
  type: ThreadFieldSchemaType.String,
  stringValue: 'security',
});

if (res.error) {
  console.error(res.error);
} else {
  console.log(res.data);
}

Delete a thread field

To delete a thread field you need an API key with the following permissions:

  • threadField:delete
import { PlainClient } from '@team-plain/typescript-sdk';

const client = new PlainClient({ apiKey: 'plainApiKey_xxx' });

const res = await client.deleteThreadField({
  threadFieldId: 'tf_01HVTN2VTNYP91P5XGDQ57M2ZX',
});

if (res.error) {
  console.error(res.error);
} else {
  console.log(res.data);
}