Search code examples
javascriptnode.jsrequestify

How to add Bearer token to requestify post method in nodejs?


How can i pass Bearer token with post method. I tried with postman but getting this response "Error: Unauthorized Access. Request is not authorized"

            await turnContext.sendActivity(`${await requestify.request(url, {
                method: 'POST',
                body: data,
                dataType: 'json',
                auth:{
                    "Bearer":access_token // token
                }
            }).then(async function (res) {
                console.log(res.body);
                return res.body;
            })}`);

Solution

  • Looking at the documentation the auth property is used for basic auth only, so just add the Authorization header manually

    await requestify.request(url, {
        method: 'POST',
        body: data,
        dataType: 'json',
        headers :{
            Authorization:"Bearer " + access_token // token
        }
    })