To update consent statuses for your contacts, use the updateContacts mutation.

You can do it by adding contacts to respective consent groups or by specifying their preferences on a per-channel basis. The way you format these mutations depends on the approach your marketing team pursues.

Option A: update statuses within a consent group

The following example demonstrates how to add a contact to several consent groups or to update existing statuses within a consent group. Note that we set the OPT_IN status for the first consent group. In the second consent group, we limit preference to a particular channel within the consent group (EMAIL).

mutation {
  updateContacts(
    dataSetId: "4fe4136f-c007-44a3-b38f-92220xxxxxxxx"
    updateContactInputs: [
      {
        key: "PISCX-098724242477"
        to: {
          consent: {
            consentGroups: [
              {
                consentGroupId: "97660d76-02d8-5fd6-xxxx-000000000000"
                status: OPT_IN
              }
              {
                consentGroupId: "97660d76-02d8-5fd6-xxxx-000000000010"
                channels: [{ channel: EMAIL, status: OPT_IN_UNVERIFIED }]
              }
            ]
          }
        }
      }
    ]
  ) {
    modifiedCount
  }
}
{
  "data": {
    "updateContacts": {
      "modifiedCount": 1
    }
  }
}

Option B: update consent statuses per channel

In this example, we will subscribe one contact to emails and unsubscribe another one from text messages.

mutation {
  updateContacts(
    dataSetId: "4fe4136f-c007-44a3-b38f-92220xxxxxxxx"
    updateContactInputs: [
      {
        key: "PISCX-098724242477"
        to: {
          attributes: [
            { name: "Email", value: "[email protected]" }
          ]
          consent: { channels: { channel: EMAIL, status: OPT_IN } }
        }
      }
      {
        key: "PISCX-032724242417"
        to: {
          consent: { channels: { channel: SMS, status: OPT_OUT } }
        }
      }
    ]
  ) {
    modifiedCount
  }
}
{
  "data": {
    "updateContacts": {
      "modifiedCount": 2
    }
  }
}

Arguments

Arguments supported by the updateContacts object:

ArgumentValuesRequired?Definition
dataSetIdIDRequiredThe ID of your audience
updateContactInputsArrayOptionalSee nested fields below.

Optional fields nested inside the updateContactInputs argument:

FieldNested fieldValuesDefinition
keyStringThe unique identifier of the contact in your audience
toconsentArraySee nested fields below.

Input fields nested inside the consent field:

FieldNested field - level 1Nested field - level 2ValuesDefinition
channelschannelEither of the following values:

- EMAIL
- SMS
The type of communication channel
statusOne of the following values:

- OPT_IN
- OPT_OUT
- OPT_IN_UNVERIFIED
- null
Indicates if the contact has agreed to receive communication through the channel.
consentGroupschannelschannelEither of the following values:

- EMAIL
- SMS
The communication channel associated with the consent group
statusOne of the following values:

- OPT_IN
- OPT_OUT
- OPT_IN_UNVERIFIED
- null
The contact's consent status in relation to the communication channel
consentGroupIdStringThe ID of the consent group the contact has been added to
statusOne of the following values:

- OPT_IN
- OPT_OUT
- OPT_IN_UNVERIFIED
- null
The contact's status within the consent group (applies to all of its channels)

Fields

Fields returned by the updateContacts mutation:

FieldValuesRequired?Definition
modifiedCountIntegerRequiredThe number of contacts that have been updated

Possible error messages

Error codeDefinition
INVALID_CHANNEL_TYPE
INVALID_CONSENT_FIELD_NAME
CONSENT_GROUP_NOT_FOUND
CHANNEL_NOT_DEFINED
CONSENT_UPDATE_FOR_UNSET_ATTRIBUTE
CHANNELS_DUPLICATE_PROVIDED
CHANNELS_ALREADY_ASSIGNED
CONTACT_NOT_FOUND_BY_KEYA contact with the specified key is not available in the audience. Use the Get all contacts query to get the list of existing contacts.