# Test Postman and NextJS secure API endpoints

**URL:** <https://community.auth0.com/t/test-postman-and-nextjs-secure-api-endpoints/67315>\
**Category:** Get Help\
**Tags:** nextjs, login\
**Created:** [August 3, 2021, 4:13pm UTC](https://community.auth0.com/t/test-postman-and-nextjs-secure-api-endpoints/67315 "2021-08-03T16:13:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattveraldi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mattveraldi/32/30904_2.png) [@mattveraldi](https://community.auth0.com/u/mattveraldi)\
**Post date:** [August 3, 2021, 4:13pm UTC](https://community.auth0.com/t/test-postman-and-nextjs-secure-api-endpoints/67315/1 "2021-08-03T16:13:17Z")

</div>

Hi,

I set up a NextJS + Auth0 environment following the official guide, and i have some secured APIs that I would like to test with Postman. but I can’t make it work…

I followed this guide: [How to Manage a Collection of Secure API Endpoints with Postman (auth0.com)](https://auth0.com/blog/manage-a-collection-of-secure-api-endpoints-with-postman/) and I managed to get the token. Then I added the request to the collection and set the Authorization to use that token… but still the api returns 401 unauthorized.

Can anybody help me please?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 4, 2021, 3:46pm UTC](https://community.auth0.com/t/test-postman-and-nextjs-secure-api-endpoints/67315/3 "2021-08-04T15:46:57Z")

</div>

Hi @mattveraldi,

Welcome to the Auth0 Community!

Is there anything else to the error? Is there a description?

Have you decoded the token to see if it is missing any necessary permissions etc.? You can decode it using [jwt.io](http://jwt.io).

---

<div class="post-metadata">

**Author:** ![mattveraldi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mattveraldi/32/30904_2.png) [@mattveraldi](https://community.auth0.com/u/mattveraldi)\
**Post date:** [August 5, 2021, 7:42am UTC](https://community.auth0.com/t/test-postman-and-nextjs-secure-api-endpoints/67315/4 "2021-08-05T07:42:37Z")

</div>

Hi,

Thank you. This is the error:

```auto
{
    "error": "not_authenticated",
    "description": "The user does not have an active session or is not authenticated"
}

```

and this is the decoded jwt generated with postman OAuth2 authentication

```auto
{
  "iss": "https://dev-3iba167e.us.auth0.com/",
  "sub": "auth0|610960c6c61fd70077d1657e",
  "aud": [
    "localhost:3000",
    "https://dev-3iba167e.us.auth0.com/userinfo"
  ],
  "iat": 1628007554,
  "exp": 1628093954,
  "azp": "i4tBFrdpABSoZMMPLBcXN3Jt320mSJ7w",
  "scope": "openid profile email"
}

```

The token is sent in headers correctly…  
I’m securing the api with the H.O.F. `withApiAuthRequired`, maybe there is some configuration that I’m missing there?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 5, 2021, 7:52pm UTC](https://community.auth0.com/t/test-postman-and-nextjs-secure-api-endpoints/67315/5 "2021-08-05T19:52:39Z")

</div>

What endpoint is giving you that error? Can you take a screenshot or code snippit of the request that is returning that?

---

<div class="post-metadata">

**Author:** ![mattveraldi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mattveraldi/32/30904_2.png) [@mattveraldi](https://community.auth0.com/u/mattveraldi)\
**Post date:** [August 9, 2021, 11:26pm UTC](https://community.auth0.com/t/test-postman-and-nextjs-secure-api-endpoints/67315/6 "2021-08-09T23:26:19Z")

</div>

Hi,  
The endpoint is running locally at `localhost:3000/api/link-items` and it is a POST call.

This is the POST handler

```auto
/**
 * handle POST
 * @param req
 * @param res
 */
const addNewLinkItem = async (req: NextApiRequest, res: NextApiResponse, user: Claims) => {
  const linkItem = req.body as LinkItem;
  try {
    await prisma.linkItem.create({
      data: linkItem,
    });
    res.status(200).send("Link item created");
  } catch (error) {
    console.error(error);
    res.status(500).send("An error occurred creating link item");
  }
};

```

And this is the export  
`export default withApiAuthRequired(requestHandler);`

where `requestHandler` calls an handler based on the request type (POST in this case).

---

<div class="post-metadata">

**Author:** ![wesen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/wesen/32/32987_2.png) [@wesen](https://community.auth0.com/u/wesen)\
**Post date:** [November 13, 2021, 6:26pm UTC](https://community.auth0.com/t/test-postman-and-nextjs-secure-api-endpoints/67315/7 "2021-11-13T18:26:06Z")

</div>

Did you ever find a solution? I seem to be running into the same issue, using nextjs-auth0 and withApiAuthRequired on the next.js side (works fine on its own), but I am unable to hook up my postman.

---

<div class="post-metadata">

**Author:** ![wesen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/wesen/32/32987_2.png) [@wesen](https://community.auth0.com/u/wesen)\
**Post date:** [November 13, 2021, 6:36pm UTC](https://community.auth0.com/t/test-postman-and-nextjs-secure-api-endpoints/67315/8 "2021-11-13T18:36:59Z")

</div>

For the sake of completeness, I figured out a solution that I found here: [https://github.com/auth0/nextjs-auth0/issues/135](https://github.com/auth0/nextjs-auth0/issues/135). It requires installing the desktop app and the chrome interceptor plugin, and snatching the session cookie from the localhost app

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [November 15, 2021, 9:20pm UTC](https://community.auth0.com/t/test-postman-and-nextjs-secure-api-endpoints/67315/9 "2021-11-15T21:20:26Z")

</div>

@wesen

thanks for sharing your solution!

---

<div class="post-metadata">

**Author:** ![mattveraldi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mattveraldi/32/30904_2.png) [@mattveraldi](https://community.auth0.com/u/mattveraldi)\
**Post date:** [November 15, 2021, 10:14pm UTC](https://community.auth0.com/t/test-postman-and-nextjs-secure-api-endpoints/67315/10 "2021-11-15T22:14:04Z")

</div>

Unfortunately I didn’t find any… I just gave it up since I had been moved to another project

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [November 30, 2021, 10:14pm UTC](https://community.auth0.com/t/test-postman-and-nextjs-secure-api-endpoints/67315/11 "2021-11-30T22:14:22Z")

</div>

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