Subscribe a user

Use the subscribe mutation to opt-in a user to a subscription.

Notes:

  • A legal disclosure is required when a user is opted-in programmatically.

  • 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

Make sure to set the Authorization: Bearer <Unique API Key> on the request. For more information about obtaining a unique API Key please see the Authentication Docs

POST https://api.attentivemobile.com/v1/graphql

Copy
Copied
mutation testsubscribe ($input: SubscribeInput!) {
  subscribe(input: $input) {
    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": "+15555555555"
      },
      "signupSourceId": "12345",
      "externalIdentifiers": {
          "clientUserId": "abc",
          "customIdentifiers": [
              {
                  "name": "customKey",
                  "value": "customValue"
              }
          ]
      }
    } 
}