0
votes

I am trying to exchange a Salesforce Marketing Cloud (SFMC) authorization_code for an access_token per the docs here: https://developer.salesforce.com/docs/atlas.en-us.mc-app-development.meta/mc-app-development/access-token-app.htm

curl https://{my_subdomain}.auth.marketingcloudapis.com/v2/token \
  --request POST  \
  --header "Content-Type: application/json" \
  --data '{"grant_type": "authorization_code", "code": "{{my_code}}", "client_id": "{{my_client_id}}", "redirect_uri": "https://127.0.0.1:80/", “client_secret: “{{my_client_secret}}”, "scope": "audiences_read list_and_subscribers_write offline"}'

Yet it continually gives me the following error:

{"documentation":"https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/error-handling.htm","errorcode":0,"message":"Bad Request"}%

I have no idea where I am going wrong, any help is appreciated.

I was seeing "correct" errors when I was using an expired code and when my client_id and/or client_secret were wrong, but nothing after I pasted in the correct values. Perhaps it is my scopes?

According to the docs linked in the error code, The token was not found in the request, or it is invalid or expired.. This is the only error code that has customcode == 0. It is strange since I am trying to get a token, not pass one in, and that error code is associated with a 401, which may or may not be what I am receiving back.

1
You'll get a lot more eyes on your SFMC questions over at salesforce.stackexchange.com, specifically with the marketing-cloud tag.Adam Spriggs

1 Answers

0
votes

It turns out my client_secret in my data was using the incorrect double quote. It was a slanted double-quote. I discovered this when I tried using Python3 instead of cURL and was converting my JSON above into JSON to pass to the requests library. I was able to successfully get a token.

So the answer is, the above is correct, just watch your encodings!