How do I get salesforce access token using the REST API in exact target landing page.. Help me to do this Activity..

 var @url, @clientId, @clientSecret, @result
 @clientid = ""Client_id"
 @clientSecret = "Client_secret"
 @url = "https://auth.exacttargetapis.com/v1/requestToken"
 SET @result =HTTPPost2(@url,"application/json", @clientId, @clientSecret)   

I used this code in landing page, instead of client_id and client_secret I have given salesforce connected app client_id and client_secret but its not returning access token is this correct way to get access token from exact target landing page using OAuth 2.0.

I am getting the below error. Is this correct code for getting token from salesforce?

Error Message : An expected comma is not found in the varible declaration. Script var @url, @clientId, @clientSecret, @result @clientid = "XXXXXX. XXXXXX" @clientSecret = "XXXX" @url = "XXXXXXXX/v1/requestToken" ListID: 0 Index: 50

Description: An unexpected error occurred during the execution of the page

  • Refer the link developer.salesforce.com/docs/… – Samuel Robert Mar 28 '17 at 6:33
  • Thank you responding.. i have updated question above please check once.. – user321 Mar 28 '17 at 6:47
  • Use the HTTP ampscript. Your code as it is not wrapped in any backend language to communicate with the server – Samuel Dare Mar 28 '17 at 6:55
  • Please do not use images as error message. – Martin Lezer Mar 28 '17 at 8:10

I use the following to request a token in AMPScript on Landing Pages, Emails and Mobile Connect:

VAR @httppost,@apiid,@apistatusCode,@apiresponse,@apitoken
SET @apiid = '{"clientId": "YOUR_clientId","clientSecret": "YOUR_clientSecret"}'
SET @httppost = HTTPPost2("https://auth.exacttargetapis.com/v1/requestToken","application/json",@apiid,false,@apistatusCode,@apiresponse)
SET @apitoken = Substring(@apistatusCode,17,24)

Where @apitoken is the Token to be used for future API calls.
Substring isn't a great way to get the Token from the Response, but it works.

Here is where you get the ClientID and ClientSecret:

enter image description here
Ref: https://appcenter.s1.marketingcloudapps.com

  • Thank you for responding .. getting thorized","errorcode":1 in response – user321 Mar 28 '17 at 7:57
  • Happy to help User321 - Double check that you have put the correct details from appcenter.s1.marketingcloudapps.com, including the correct Data Access rights. I've updated my answer to include a screenshot of the IDs. Are you getting the Error Code on the Token request - or when you try to use the Token? – Cameron Robert Mar 28 '17 at 9:30
  • Thank you..i am getting error when i am tring to get token – user321 Mar 28 '17 at 9:33
  • Hey @user321, I just tested my code exactly as it is above (replacing the values YOUR_clientId and YOUR_clientSecret with my details from the AppCenter, and I was able to successfully retrieve a Token. can you confirm that your "SET apiid" line looks something like this: '{"clientId": "39458gh4875gh45h","clientSecret": "eir34rh475hgh48"}' (fake values) – Cameron Robert Mar 28 '17 at 9:44
  • Is it Possible to get Salesforce Access Token USing AMP Script now we are getting App center token.. – user321 Mar 28 '17 at 9:53

You need to go the app exchange and register an app. At the end of the process you will get a Client ID and Client secret . Them you make a call to request the token which is valid for 60 minutes


Try This.

POST https://auth.exacttargetapis.com/v1/requestToken
Content-Type: application/json
  200 OK
"accessToken": "YOUR_ACCESS_TOKEN"
"expiresIn": 3600
  • Hi, i amgoing to write code in landing pages from ladning page we need to get access token using hhtp ampscript i tried code why iam getting error i m not sure please help on this way – user321 Mar 28 '17 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.