Invalid Client while requesting for access_token

While trying to authenticate with OAuth flow after getting authorization_code and trying to ask for access_token I get this error.

    "code": 40110000,
    "message": "invalid_client"

The request I am trying to run.

curl --location --request POST '' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'code=XX' \
--data-urlencode 'client_id=XX' \
--data-urlencode 'client_secret=XX' \
--data-urlencode 'redirect_uri=http://localhost:8080/api/oauth/alpaca/redirect'

No matter what parameters I try I never get authorization failed. So I would guess its somehow connected to client_id.

I tried generating new clientId and secret couple of times without success.

It probably is some silly mistake I missed in the docs, but I cant figure it out. (edited)

So after changing my state parameter to actually random string instead of copying it from docs, it works.