Я пытаюсь вызвать 2 сторонних apis. 1-й для входа и получения токена на предъявителя и 2-й для отправки сообщения. 1-й работает отлично, и я получаю токен. но когда я пытаюсь вызвать второй API для отправки сообщения, это не удается, вероятно, потому что я не знаю, как установить полученный токен во 2-м API
, вот мой код
var myJSONObject = {
"email": auth[0],
"password": auth[1]
};
req.post({
url: "{{server_url}}/auth/login",
method: "POST",
json: true,
body: myJSONObject
}, function (error, res, body){
if(error){
console.log(error.message);
} else {
var myJSONObject1 = {
"category":"SYSTEM",
"type": "ALERT",
"keywords":"FUNCTION|createSomethingLvl1",
"status":"UNREAD",
"from": "tenantadmin@tenantadmin.com",
"to": "someemail@gmail.com",
"subject": "Some nice subject",
"body": "Some detailed body that contains information that informs the person"
};
req.post({
url: "{{server_url}}/api/message",
method: "POST",
headers: {
"Authorization": res.body.access_token,
"Content-Type": "application/json"
},
json: true,
body: myJSONObject1
}, function (err, res1, body){
if(error){
console.log(err.message);
} else {
console.log(res1.body);
}
});
}
});