1

I am trying to trigger outbound SMS for another outbound SMS, I am able to trigger it but not able to pass the subscriber key and attributes in the payload. Below is the script that's working with only mobile number in the content.

%%[
    VAR @apiid,@url,@exec,@accessToken,@mobileNumber,@OMedia,@apiresponse,@apistatusCode,@statusCode,@response,@httppost,@apitoken,@skey,@cpk1
    set @mobileNumber = "xxxxxx"
    set @skey="123#Test"
    set @cpk1="123##Test"
    SET @apiid = '{"client_id": "xxxxxx","client_secret": "xxxxx", "grant_type": "client_credentials"}'
    SET @httppost = HTTPPost2("https://subdomain.auth.marketingcloudapis.com/v2/token","application/json",@apiid,false,@apistatusCode,@apiresponse)
    SET @apitoken = Substring(@apistatusCode,18,512)
    IF @httppost ==  200 THEN
    SET @OMedia = concat('{"mobileNumbers":[', @mobileNumber,']}')
     
      SET @url ="https://subdomain.rest.marketingcloudapis.com/sms/v1/messageContact/**smskey**/send/"
    SET @exec = HTTPPost2(@url,"application/json",@OMedia,true,@statusCode,@response,'Authorization',CONCAT("Bearer ", @apitoken)) 
    ENDIF
]%%

but when I try to pass attributes in the payload content like below its not working

SET @OMedia = concat('{"Subscribers": [{"mobileNumbers":[', @mobileNumber,'],"SubscriberKey": [',@skey,'],"Attributes":{"COMPOSITE_PRIMARY_KEY":[', @cpk1,']}}]}')

Is there a way to pass a unique key to next message from current message through API?

2
  • I don't know if it is just a typo in your code here on SFSE; but you write sey @cpk1="123##Test" instead of set @cpk1="123##Test" Commented Jun 28, 2021 at 9:23
  • @LukasLunow, Yes, its a typo. Corrected it now.
    – Vi Bin
    Commented Jun 28, 2021 at 9:35

1 Answer 1

0

I think you are using this SMS API - https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/postMessageContactSend.htm

If so, looking at the second example. You payload seems to be incorrect. Please try with API tools like Postman and try to write the ampscript.

In your payload it should be 'MobileNumber' instead of mobileNumbers. Remove the array brackets. So, it should be looking like below:

SET @OMedia = concat('{"Subscribers": [{"MobileNumber":"', @mobileNumber,'","SubscriberKey":"',@skey,'","Attributes":{"COMPOSITE_PRIMARY_KEY":"', @cpk1,'"}}]}')

Let me know if this helps!

4
  • When I try to use the above payload, it gives me "errorCode":33100,"errorMessage":"Single sends must include a subscriber."
    – Vi Bin
    Commented Jun 28, 2021 at 11:51
  • I hope you are trying via Postman. If yes, try to give a valid mobile number for respective long/short code.
    – Naveen VM
    Commented Jun 28, 2021 at 14:20
  • I've tried it from Cloudpage and I've given valid mobile number which is opted for that short code. Its working fine with my code with only mobile number in payload but this isnt getting executed.
    – Vi Bin
    Commented Jun 28, 2021 at 14:32
  • Please try the payload with subscriber key details in PostMan and see what you get. Post the payload in your question as well. Then try with ampscript.
    – Naveen VM
    Commented Jun 28, 2021 at 14:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .