Subscribe a user

Use the subscribe mutation to opt-in a user to a subscription. Note that a legal disclosure is required when a user is opted-in programmatically. For transactional messages, you must include a transactional opt-in unit. By default, if a subscription already exists, it will try and record the attempt to create the subscription again. For TEXT subscriptions, this will result in a message being sent to the person indicating that they are already subscribed.

The following input fields are provided:

user - Required. The user being subscribed. Note that this is a visitor to the site and does not need to be actively subscribed to Attentive. An email, phone, or both can be provided.

signupSourceId - Required. The unique identifier of the sign-up source. This can be found in the Subscribers tab of the Attentive platform in the ID column for any API sign-up method.

externalIdentifiers - Optional. If the user is associated with non-Attentive external ids, they can be included here. Options include Shopify id, Klaviyo id, or a list of custom identifiers.

The response will provide details about the new or existing subscriptions.

Example query

Copy
Copied
mutation {
  subscribe($input: SubscribePayload) {
    externalIdentifiers {
      clientUserId
      shopifyId
      customIdentifiers {
        name
        value
      }
    }
    subscribeResults {
      channel
      type
      destinationAddress {
        ... on DestinationEmail {
          value
        }
        ... on DestinationPhone {
          value
        }
      }
    }
  }
}

Example Input Variable:

Copy
Copied
    input: {
      user: {
        email: "test@gmail.com"
        phone: "5555555555"
      }
      signupSourceId: "12345"
      externalIdentifiers: {
          clientUserId: "abc",
          customIdentifiers: [
            {
                name: "customKey",
                value: "customValue"
            }
          ]
        }
    }