Answer the question
In order to leave comments, you need to log in
How to send a POST request through Google Apps Script?
I want to send a POST request to one senler mailing service with data inside and still need to pass the key I
wrote the following code below. In payload, I pass the necessary data for the service to add a subscriber to the chatbot. In the header I pass the access key.
function senler(){
var data = {
'vk_group_id': 163864515,
'v': 2,
'vk_user_id': 132528477,
'bot_id': 356810,
};
var options = {
'method': 'post',
'contentType': 'application/json',
'payload': JSON.stringify(data),
'headers': {'access_token': 'ee95------------------------------------------6'},
};
var response = UrlFetchApp.fetch('https://senler.ru/api/bots/addSubscriber', options);
Logger.log(response.getResponseCode());
}
Answer the question
In order to leave comments, you need to log in
There was a solution, many thanks to Grigory Boev !
It was necessary to place the key in payload and remove "JSON.stringify"
Working code:
function senler(){
var data = {
'access_token': 'ee---------------------------------------6',
'vk_group_id': 1----------5,
'v': 2,
'vk_user_id': 1------------7,
// 'subscription_id': 0,
'bot_id': 356810,
};
var options = {
'method': 'post',
'payload': data
};
var response = UrlFetchApp.fetch('https://senler.ru/api/bots/addSubscriber', options);
Logger.log(response.getResponseCode());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question