Use the preference page URL API to generate URLs for a contact’s specific email preference pages, which allows them to manage their email preferences from within authenticated areas of your website. To generate subscription preferences URLs, ensure that your app has authorized the scopes listed below:Documentation Index
Fetch the complete documentation index at: https://developers.hubspot.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
communication_preferences.read_writeORcommunication_preferences.readANDcommunication_preferences.write
Generate subscription preference page URLs
To generate preference page URLs for a contact, make aPOST request to /communication-preferences/v4/links/generate and provide the following query parameters:
channel(required): communication channel, required to beEMAIL.businessUnitId: you can optionally include the ID of a specific brand, which results in the links that take contacts to pages customized for that brand. On these pages, only subscriptions within that brand will be displayed.
subscriberIdString(required): email address of the contact for whom the subscription preferences page is being generated.language: language for the preferences page. For translations to work as expected, you should select a language associated with a subscription type. If no language is specified, the system may default to your account’s default language or English.subscriptionId: ID of a specific subscription type, which may result in that subscription type being highlighted on the preferences page. This parameter must be included to return anunsubscribeSingleUrllink.
results field of the response.
For example, if you wanted to generate a unique email preference page for bh@hubspot.com associated with a businessUnitId of 887987898, you’d make a POST to https://api.hubapi.com/communication-preferences/v4/links/generate?businessUnitId=887987898&channel=EMAIL, then include a request body that resembled the following:
Troubleshoot errors
If your request returns an error, review the error message and code, then follow the troubleshooting steps for that error.Understand error messages
Most errors follow the following format:| Property name | Description |
|---|---|
status | Outcome of the request; for errors, this will always return “error”. |
message | Description of what went wrong. |
correlationId | Unique identifier for this request. |
errorCode | Machine-readable code identifying the specific error type. |
category | High-level error classification, such as VALIDATION_ERROR. |
context | Object containing request parameters that may have caused the error. |
subscriberIdString | Email address (subscriber identifier) from the request |
language | Language parameter from the request, if provided. |
subscriptionId | Subscription ID from the request, if provided. |
businessUnitId | Business unit ID from the request, if provided. |
Troubleshoot common errors
Learn more about the errors that can occur when generating a subscription preferences page URL.Language not configured
- Error code:
LANGUAGE_NOT_CONFIGURED - Description: the provided
languageparameter is invalid. - Troubleshooting steps: assign one of the languages listed in the error property “message” to a subscription type, then wait several minutes to try again.
Subscription type not found
- Error code:
SUBSCRIPTION_TYPE_NOT_FOUND - Description: the provided
subscriptionIdparameter is invalid. - Troubleshooting steps: get all subscription types, then confirm that one of them uses the
subscriptionIdincluded in the request.
Subscription type & brand mismatch
- Error code:
SUBSCRIPTION_TYPE_BUSINESS_UNIT_MISMATCH - Description: the provided
subscriptionIdbelongs to a different brand than specified inbusinessUnitId. - Troubleshooting steps: to resolve this error, try the following:
- Use a subscription type that belongs to the specified brand.
- Omit the
businessUnitIdparameter. - Get all subscription types and confirm which subscription types are used for each brand.
Contact not found
- Error code:
CONTACT_NOT_FOUND - Description: the provided email address is not associated with a contact record in the HubSpot account.
- Troubleshooting steps: to resolve this error, try the following:
- Verify the email address belongs to a contact in the HubSpot account.
- Create a contact associated with this email address, then try again.
Invalid channel
- Description: the
channelparameter contains a value other thanEMAIL. - Troubleshooting steps: use
channel=EMAILas the query parameter.