Skip to main content
2 of 5
added 68 characters in body

How to pass attributes in Ampscript rest api block for outbound SMS?

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"
sey @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?