Getting Unauthorized error in Send Request Test Script

I have a authorization token(Bearer Token) Used in Sending API Requests there the request is getting sent and the response also been received but the same authorization token is giving me Unauthorized Response when used in Test Script. Please Help on this

pm.sendRequest({
    url: 'https://myappurl.com/api/BudgetItem/Get?budgetId=217=&id=382',
    method: 'GET',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer my_working_token', 
    },
    body: {
        mode: 'none',
    }
}, function(err, response) {
    if (err) {
        console.error("Error",err);
        return;
    }
    console.log("Response",response);
    pm.test("Response status code is 201", function () {
        pm.response.to.have.status(201);
    });
});

Tell me if Iā€™m missing something here or any setting to be enabled.

Also, I have tested the Authorization token externally in python there also the request is being sent successfully. Facing issue only in Test Script and Pre-request script in Postman.

Hey @roopesh07 :wave:

The correct key name for the Headers is header - that might be the issue.

Hey Danny :wave: :smiley:,
It worked!! Thank you so much for the solution. I did not even noticed it. I have been using the autogenerated script from Postbot.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.