# Getting Unauthorized error in Send Request Test Script

**URL:** <https://community.postman.com/t/getting-unauthorized-error-in-send-request-test-script/55006>\
**Category:** Help Hub\
**Tags:** tests, authentication, request, pmsendrequest\
**Created:** [November 26, 2023, 6:24am UTC](https://community.postman.com/t/getting-unauthorized-error-in-send-request-test-script/55006 "2023-11-26T06:24:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![roopesh07](https://avatars.discourse-cdn.com/v4/letter/r/6de8d8/32.png) [@roopesh07](https://community.postman.com/u/roopesh07)\
**Post date:** [November 26, 2023, 6:24am UTC](https://community.postman.com/t/getting-unauthorized-error-in-send-request-test-script/55006/1 "2023-11-26T06:24:10Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![roopesh07](https://avatars.discourse-cdn.com/v4/letter/r/6de8d8/32.png) [@roopesh07](https://community.postman.com/u/roopesh07)\
**Post date:** [November 26, 2023, 6:32am UTC](https://community.postman.com/t/getting-unauthorized-error-in-send-request-test-script/55006/2 "2023-11-26T06:32:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 26, 2023, 7:08am UTC](https://community.postman.com/t/getting-unauthorized-error-in-send-request-test-script/55006/3 "2023-11-26T07:08:55Z")

</div>

Hey @roopesh07 👋

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

---

<div class="post-metadata">

**Author:** ![roopesh07](https://avatars.discourse-cdn.com/v4/letter/r/6de8d8/32.png) [@roopesh07](https://community.postman.com/u/roopesh07)\
**Post date:** [November 26, 2023, 7:30am UTC](https://community.postman.com/t/getting-unauthorized-error-in-send-request-test-script/55006/4 "2023-11-26T07:30:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [November 29, 2023, 7:31am UTC](https://community.postman.com/t/getting-unauthorized-error-in-send-request-test-script/55006/5 "2023-11-29T07:31:18Z")

</div>

Closed on November 29, 2023, 7:31am UTC

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