I am trying to implement following REST in google script
Code I have used is as below
function whatsapp() {
//https://www.gupshup.io/developer/docs/bot-platform/guide/whatsapp-api-documentation#SendText
var payload = {"channel":"whatsapp",
"source":"917834811114",
"destination":"91999990**34",//I have * done it on purpose
"src.name":"googlerishisheet",
"message.payload" : {
"isHSM":"true",
"type": "text",
"text": "Hi John, your order is confirmed and will be delivered to you by 15 Feb"
}
}
var url = 'https://api.gupshup.io/sm/api/v1/msg?apikey=0*8e4a487d6d4d3ccd2d52e7f0ffb78f'; // I have done * on purpose
var options = {"method" : "post",
"payload" : payload};
UrlFetchApp.fetch(url, options);
}
Result I am getting is
I have tried following ways also.
"payload":JSON.stringify(payload)
Result - {text=Hi John, your order is confirmed and will be delivered to you by 15 Feb, type=text, isHSM=false}
"message":{"payload" : { "isHSM":"false", "type": "text", "text": "Hi I am testing whatsapp" }}};
and set contentType to x-www.....urlencoded..
Result - {payload={type=text,text=Hi I am testing whatsapp, isHSM=false}}
"src.name":"googlerishisheet", "message.payload.isHSM":"false", "message.payload.type": "text", "message.payload.text": "Hi I am testing whatsapp" };
Result - Same issueDocumentation states that message.payload
value is of type object
. However, it seems you should send it as plain string, while maintaining the payload
contentType as "application/x-www-form-urlencoded"
"message.payload" : JSON.stringify({
"isHSM":"true",
"type": "text",
"text": "Hi John, your order is confirmed and will be delivered to you by 15 Feb"
})