# Error while trying to exchange auth code for an OAuth access token

**URL:** <https://www.thethingsnetwork.org/forum/t/error-while-trying-to-exchange-auth-code-for-an-oauth-access-token/64664>\
**Category:** The Things Stack v3\
**Created:** [September 6, 2023, 6:00pm UTC](https://www.thethingsnetwork.org/forum/t/error-while-trying-to-exchange-auth-code-for-an-oauth-access-token/64664 "2023-09-06T18:00:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman\_Cherepanov](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/roman_cherepanov/32/35697_2.png) [@Roman\_Cherepanov](https://www.thethingsnetwork.org/forum/u/Roman_Cherepanov)\
**Post date:** [September 6, 2023, 6:00pm UTC](https://www.thethingsnetwork.org/forum/t/error-while-trying-to-exchange-auth-code-for-an-oauth-access-token/64664/1 "2023-09-06T18:00:30Z")

</div>

I get 400 error when I try to exchange authorization code for an OAuth access token according to the documentation [https://www.thethingsindustries.com/docs/api/concepts/auth/](https://www.thethingsindustries.com/docs/reference/api/authentication/)

### Steps to Reproduce

1. Get authorization code with request `https://eu1.cloud.thethings.network/oauth/authorize?client_id=<oauth_client_id>&redirect_uri=<redirect_uri>&response_type=code`
2. Exchange authorization code for an OAuth access token using request

```auto
POST /oauth/token HTTP/1.1
Host: eu1.cloud.thethings.network
Content-Type: application/json
Authorization: Basic <AUTHORIZATION_HEADER>
Content-Length: 156

{
    "grant_type": "authorization_code",
    "code": "<AUTHORIZATION_CODE>"
}

```

### Current Result

Error with code 400 and body:

```auto
{
    "code": 3,
    "message": "error:pkg/oauth:invalid_request (invalid or missing request parameter)",
    "details": [
        {
            "@type": "type.googleapis.com/ttn.lorawan.v3.ErrorDetails",
            "namespace": "pkg/oauth",
            "name": "invalid_request",
            "message_format": "invalid or missing request parameter",
            "correlation_id": "f58fe39f7984450a969c2134bac2835c",
            "code": 3
        }
    ]
}

```

### Expected Result

Response with status code 200 and body

```auto
{
  "access_token": "XXXXX", 
  "token_type": "bearer", 
  "expires_in": "3600",
  "refresh_token": "YYYYY"
}

```
