I'm trying to set up GAS to send an API call to my CRM. Here is the link for the API documentation.
I'm attempting to use the code for sending a text via the API. Below is what they provided. I have changed this code to work with GAS(see further down):
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "Bearer {{api_token}}");
var raw = JSON.stringify({
"message": ""
});
var requestOptions = {
method: 'PUT',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.kvcore.com/v2/public/contact/{{contact_id}}/text", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
I adapted the code provided to work with GAS. This is what I'm actually trying to run:
function kvCoreStyle(){
var myHeaders = {
"Content-Type":"application/json",
"Authorization":"Bearer {{TOKENID}}"
}
var raw = {
"message":"let me know if you get this text"
}
var requestOptions = {
"method":"PUT",
"headers":myHeaders,
"body": raw,
"redirect":"follow"
};
UrlFetchApp.fetch("https://api.kvcore.com/v2/public/contact/{{ContactID}}/text", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
}
Unfortunately, I keep getting an error saying "Request body must be a valid JSON string"
I have tried using JSON.stringify() on multiple portions of this and can not get it to work at all. Any advice would be appreciated!