1

I'm trying to call REST API to display a push message that is sent from Marketing Cloud in landing page.

How do I call the API? I was able to get the Token using the client secret and ID but how to pass the token to the REST push message call.

How to pass the Authorization : Bearer TOKEN to the httpget call?

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

VAR @httpgetmessage, @apiid,@apistatusCode2,@apiresponsemessage

SET @httppostmessage = HTTPGet("https://auth.exacttargetapis.com/v1/message/xxxxxxxx", headers = {"Authorization":"Bearer " + @apitoken,@apiresponsemessage})

%%=(@apitoken)=%% // This is printing my response token from the rest call

]%%
0

I've seen it done this way. May not be the exact call for your case, but the structure would be similar.

%%[

  VAR @auth,@url,@returnCode,@response,@regex,@accessToken,@mobileNumber,@shortCode,@message,@QueueMO
  set @mobileNumber = "19135551212"
  set @shortCode = "99999"
  set @message = "STOP"
  SET @auth = '{"clientId":"xxxxxxxxxxxx","clientSecret":"xxxxxxxxxxxx"}'
  SET @url = 'https://auth.exacttargetapis.com/v1/requestToken'
  SET @returnCode = HTTPPOST(@url,"application/json",@auth,@response)
  outputline(concat("<br>returnCode:", @returnCode))

  IF @returnCode = =  200 THEN
      SET @regex = '^{"accessToken":"(.*)",.*$'
      SET @accessToken = REGEXMATCH(@response,@regex,1)
      outputline(concat("<br>accessToken:", @accessToken))
      SET @QueueMO = CONCAT('{"mobileNumbers":["',@mobileNumber,'"],"ShortCode":',@shortCode,',"MessageText":"',@message,'"}')
      SET @url = CONCAT("https://www.exacttargetapis.com/sms/v1/QueueMO/?access_token = ",@accessToken)
      SET @returnCode = HTTPPOST(@url,"application/json",@QueueMO,@response)
      outputline(concat("<br>returnCode:", @returnCode))
  ENDIF

]%%
  • I'm not trying to send a push message, I need to display a push message sent to a contact in the landing page using the subscriber key. – Rags_SFMC Apr 24 '17 at 20:57

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.