Web app and public app integrations allow applications to integrate with Marketing Cloud on behalf of an end-user, using the intersection of the app’s and user’s permissions. A public app can’t securely store a client secret, but a web app can.
Use the authorization code grant type to allow your web or public app to access Marketing Cloud resources on behalf of a user.
It can take up to five minutes before authorization codes, access
tokens, and refresh tokens generated by the v2/authorize
and v2/token
endpoints incorporate any changes made to the API integration in
Installed Packages.
Authorization Code Request
JSON Parameters
{
"response_type": "code"
"redirect_uri": "Must match a redirect URL specified on the API integration in
Installed Packages. The URL must be encoded for this request."
"clientId": "YOUR_SECURE_STORED_ID",
"clientSecret": "YOUR_SECURE_STORED_KEY",
"state": "",
"scope": "",
}
Example Request URL
https://YOUR_SUBDOMAIN.auth.marketingcloudapis.com/v2/authorize?response_type=code&client_id=vqwyswrlzzfk024ivr682esb&redirect_uri=https%3A%2F%2F127.0.0.1%3A80%2F&scope=email_read%20email_write%20email_send&state=mystate
Example Web App Request
Host: https://YOUR_SUBDOMAIN.auth.marketingcloudapis.com
POST /v2/token
Content-Type: application/json
{
"grant_type": "authorization_code",
"code": "code received",
"clientId": "YOUR_SECURE_STORED_ID",
"clientSecret": "YOUR_SECURE_STORED_KEY",
"redirect_uri": "https://127.0.0.1:80/",
"scope": "email_read email_write email_send offline"
}
Example Web App and Public App Response
HTTP/1.1 200 OK
{
"access_token":"code retrieved",
"refresh_token":"new token",
"expires_in":1200,
"token_type":"Bearer",
"rest_instance_url":"YOUR_SUBDOMAIN.rest.marketingcloudapis.com",
"soap_instance_url":"YOUR_SUBDOMAIN.soap.marketingcloudapis.com",
"scope": "email_read email_write email_send offline"
}
Example Error Response
HTTP/1.1 401 Unauthorized
{
"error": "unauthorized_client"
"error_description": "The client is not authorized to request an authorization code using this method."
"error_uri": "https://developer.salesforce.com/docs"
}
Diagram
Further Info
https://developer.salesforce.com/docs/atlas.en-us.mc-app-development.meta/mc-app-development/integration-app-auth-code.htm
https://developer.salesforce.com/docs/atlas.en-us.mc-app-development.meta/mc-app-development/authorization-code.htm