# 401 on POST to custom API

**URL:** <https://community.auth0.com/t/401-on-post-to-custom-api/105691>\
**Category:** Get Help\
**Tags:** apis, application\
**Created:** [April 28, 2023, 1:05am UTC](https://community.auth0.com/t/401-on-post-to-custom-api/105691 "2023-04-28T01:05:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![itsm](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@itsm](https://community.auth0.com/u/itsm)\
**Post date:** [April 28, 2023, 1:05am UTC](https://community.auth0.com/t/401-on-post-to-custom-api/105691/1 "2023-04-28T01:05:56Z")

</div>

Hi!

Stack: NextJS, custom Node/Express API with protected routes, Auth0 for authentication.

Flow is as follows:

- Login to Auth0 from Next app
- On successful login, call the Management API to get an auth token
- Use auth token to access protected routes in Node/Express API

So using the token, I’m able to access protected routes on my API, only when making a GET request. POST requests returns a 401 unauthorized error.

Does anyone have any thoughts on this?

Thanks!

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [April 28, 2023, 12:21pm UTC](https://community.auth0.com/t/401-on-post-to-custom-api/105691/3 "2023-04-28T12:21:07Z")

</div>

Hi @itsm,

Welcome back in the Auth0 Community!

It’s possible that the issue with the POST requests returning a 401 unauthorized error is related to the way you are sending the authentication token in your requests. Here are a few things to check:

1. Make sure that you are including the authentication token in the Authorization header of your POST requests. You should include the word “Bearer” followed by a space, then the token itself. For example:

```auto
Authorization: Bearer <access_token>

```

1. Check that the token you are using is valid and has the necessary scopes to access the protected routes. You can use a tool like [jwt.io](http://jwt.io) to decode the token and inspect its contents.

---

<div class="post-metadata">

**Author:** ![peter.fernandez](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/peter.fernandez/32/45477_2.png) [@peter.fernandez](https://community.auth0.com/u/peter.fernandez)\
**Post date:** [April 28, 2023, 1:42pm UTC](https://community.auth0.com/t/401-on-post-to-custom-api/105691/4 "2023-04-28T13:42:06Z")

</div>

Hi @itsm 👋

Ordinarily you should be able to obtain an _Access Token_ for a (custom) API by specifying an `audience` parameter on either a call to the Auth0 `/authorize’ endpoint, or when using one of the Auth0 SDKs; see [here](https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-the-authorization-code-flow) for further details.

The _Access Token_ should be passed to the API as previously indicated, and the API should then validate both the `audience` and the `scope` for the operation requested 🕶

---

<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:** [May 12, 2023, 1:42pm UTC](https://community.auth0.com/t/401-on-post-to-custom-api/105691/5 "2023-05-12T13:42:40Z")

</div>

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