# How do I set the header grant\_type header when authenticating an API Client?

**URL:** <https://forum.sierrawireless.com/t/how-do-i-set-the-header-grant-type-header-when-authenticating-an-api-client/18938>\
**Category:** Connectivity and Cloud Services\
**Created:** [January 10, 2020, 2:24pm UTC](https://forum.sierrawireless.com/t/how-do-i-set-the-header-grant-type-header-when-authenticating-an-api-client/18938 "2020-01-10T14:24:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![wkhatch](https://avatars.discourse-cdn.com/v4/letter/w/67e7ee/32.png) [@wkhatch](https://forum.sierrawireless.com/u/wkhatch)\
**Post date:** [January 10, 2020, 2:24pm UTC](https://forum.sierrawireless.com/t/how-do-i-set-the-header-grant-type-header-when-authenticating-an-api-client/18938/1 "2020-01-10T14:24:37Z")

</div>

Per the docs [https://doc.airvantage.net/av/reference/cloud/API/](https://doc.airvantage.net/av/reference/cloud/API/) section “Authenticating an API Client”

I am not able to determine how to properly set this header, or where this code value is derived from

grant\_type=authorization\_code&code=1JV6zV&

Is there a better example somewhere, or, can anybody shed light or provide more details on how to properly obtain the correct value for the “code” parameter, and how to include all this in the headers of the request? Thanks

Examples on what I’ve tried so far:

**Pre Conditions for all requests:**  
\*the key and secret for the particular client are concatenated into a string, separated by a : which is then base64 encoded, and used as the value for the Authorization header, prepended by Basic and a space, as shown.

- The request is a post type
- the Content-Type header is set to application/x-www-form-urlencoded
- Url is: [https://na.airvantage.net/api/oauth/token](https://na.airvantage.net/api/oauth/token)

I’ve tried creating a header for the entire grant\_type, where grant\_type is the key, and everything to the right of that (in the docs) is the value, like: grant\_type : authorization\_code&code=1JV6zV& This results in response of {“error”:“invalid\_request”,“error\_description”:“Missing parameter grant\_type”}

I’ve tried splitting grant\_type=authorization\_code&code=1JV6zV& into two different headers, for grant\_type and code, also results in {“error”:“invalid\_request”,“error\_description”:“Missing parameter grant\_type”}

I’ve tried using query parameters in the URL, as: [https://na.airvantage.net/api/oauth/token?grant\_type=authorization\_code&code=1JV6zV&](https://na.airvantage.net/api/oauth/token?grant_type=authorization_code&code=1JV6zV&) which results in {“error”:“invalid\_grant”}

And finally, including the grant\_type=authorization\_code&code=1JV6zV& in the body of the request, which results in: {“error”:“invalid\_request”,“error\_description”:“Missing parameter grant\_type”}

---

<div class="post-metadata">

**Author:** ![rjacolin](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/rjacolin/32/4748_2.png) [@rjacolin](https://forum.sierrawireless.com/u/rjacolin)\
**Post date:** [January 10, 2020, 3:02pm UTC](https://forum.sierrawireless.com/t/how-do-i-set-the-header-grant-type-header-when-authenticating-an-api-client/18938/2 "2020-01-10T15:02:30Z")

</div>

Hello,

you have an howto which explains you how to deal with these parameters here: [https://source.sierrawireless.com/airvantage/av/howto/cloud/gettingstarted\_api/](https://source.sierrawireless.com/airvantage/av/howto/cloud/gettingstarted_api/)

Regards.  
Robert

---

<div class="post-metadata">

**Author:** ![wkhatch](https://avatars.discourse-cdn.com/v4/letter/w/67e7ee/32.png) [@wkhatch](https://forum.sierrawireless.com/u/wkhatch)\
**Post date:** [January 10, 2020, 3:08pm UTC](https://forum.sierrawireless.com/t/how-do-i-set-the-header-grant-type-header-when-authenticating-an-api-client/18938/3 "2020-01-10T15:08:50Z")

</div>

Yes, the links I included in the post refer to same.

---

<div class="post-metadata">

**Author:** ![rjacolin](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/rjacolin/32/4748_2.png) [@rjacolin](https://forum.sierrawireless.com/u/rjacolin)\
**Post date:** [January 10, 2020, 3:37pm UTC](https://forum.sierrawireless.com/t/how-do-i-set-the-header-grant-type-header-when-authenticating-an-api-client/18938/4 "2020-01-10T15:37:27Z")

</div>

No, your link goes to reference API. My link goes to a howto which is a step by step explanation.  
In section 2, which explains how to deal with authentication, scroll down to the _Get an Access Token_ section. In the screenshot in this section, you can see that each parameter is set as a key/value item in the body. In your case, you have 2 keys: one for grant\_type and one for code. So your last tries is the best. The previous one is less secure and 2 firsts are not working.

The code must be get using this api:  
GET [https://na.airvantage.net/api/oauth/authorize?client\_id=085d82466f824079a829f301b8a1f492&response\_type=code&redirect\_uri=http://www.example.org](https://na.airvantage.net/api/oauth/authorize?client_id=085d82466f824079a829f301b8a1f492&response_type=code&redirect_uri=http://www.example.org)

AirVantage authenticates the user and ask for authorization.  
When the client application obtains authorization from the user, it is redirected to the provided redirect URI with the authorization code.

[http://www.example.org?code=1JV6zV](http://www.example.org?code=1JV6zV)

Did you call this api to get your own code? 1JV6zV is just an example.

Finally which tools are you using so that I can try to help you better?

Regards.  
Robert

---

<div class="post-metadata">

**Author:** ![wkhatch](https://avatars.discourse-cdn.com/v4/letter/w/67e7ee/32.png) [@wkhatch](https://forum.sierrawireless.com/u/wkhatch)\
**Post date:** [January 10, 2020, 3:51pm UTC](https://forum.sierrawireless.com/t/how-do-i-set-the-header-grant-type-header-when-authenticating-an-api-client/18938/5 "2020-01-10T15:51:35Z")

</div>

Oh of course, now I see. We have to make two requests…

I’m using postman, and just trying to authenticate a client. This is for an application, so I assumed just using the API method would be sufficient. Basically, I’m just using Postman as a dev/testing proxy for what will ultimately be a server side code service.

I did not call any method to get a code. So, following along with your example, I’d need to first get the code using GET [https://na.airvantage.net/api/oauth/authorize?client\_id=085d82466f824079a829f301b8a1f492&response\_type=code&redirect\_uri=http://www.example.org](https://na.airvantage.net/api/oauth/authorize?client_id=085d82466f824079a829f301b8a1f492&response_type=code&redirect_uri=http://www.example.org)

what if there is no redirect url? I have zero need for that within the application I’m using this in, so wondering if this will just return the response directly if it’s missing. Otherwise, perhaps I’m not using the appropriate means of accomplishing what I’m trying to do?

Thanks man, sorry for the previous disconnect.

---

<div class="post-metadata">

**Author:** ![rjacolin](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/rjacolin/32/4748_2.png) [@rjacolin](https://forum.sierrawireless.com/u/rjacolin)\
**Post date:** [January 10, 2020, 3:58pm UTC](https://forum.sierrawireless.com/t/how-do-i-set-the-header-grant-type-header-when-authenticating-an-api-client/18938/6 "2020-01-10T15:58:40Z")

</div>

Pleased to know it has been clarified.  
You can use the _Request an Access Token using the Resource Owner Flow_ which is described in the howto. With his flow, you get a token after the first call and the redirect is optional.

Regards.  
Robert

---

<div class="post-metadata">

**Author:** ![wkhatch](https://avatars.discourse-cdn.com/v4/letter/w/67e7ee/32.png) [@wkhatch](https://forum.sierrawireless.com/u/wkhatch)\
**Post date:** [January 10, 2020, 5:19pm UTC](https://forum.sierrawireless.com/t/how-do-i-set-the-header-grant-type-header-when-authenticating-an-api-client/18938/7 "2020-01-10T17:19:45Z")

</div>

Ok, I’m getting the access token now. But when I use it in subsequent requests, using Authorization: Bearer {token} (where this is just my raw string token) against the example request in the doc you linked to, to get a system, I’m getting the following response:

{  
“error”: “context.unknown”,  
“errorParameters”: null  
}

I’m not setting any additional headers besides the authorization, and just swapping out my system name. any ideas? Thanks again.

---

<div class="post-metadata">

**Author:** ![jawaddidouh](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@jawaddidouh](https://forum.sierrawireless.com/u/jawaddidouh)\
**Post date:** [January 20, 2020, 12:14pm UTC](https://forum.sierrawireless.com/t/how-do-i-set-the-header-grant-type-header-when-authenticating-an-api-client/18938/8 "2020-01-20T12:14:55Z")

</div>

@wkhatch have you finaly find the solution ? i have the same problem, it’s look like that we write header with the wrong format

---

<div class="post-metadata">

**Author:** ![wkhatch](https://avatars.discourse-cdn.com/v4/letter/w/67e7ee/32.png) [@wkhatch](https://forum.sierrawireless.com/u/wkhatch)\
**Post date:** [January 20, 2020, 3:57pm UTC](https://forum.sierrawireless.com/t/how-do-i-set-the-header-grant-type-header-when-authenticating-an-api-client/18938/9 "2020-01-20T15:57:05Z")

</div>

Hi @jawaddidouh. I’m not sure which part of my question you’re referring to. The first issue I’d had was due to not first making the request for the auth token, which you’d use in subsequent requests. I’d misinterpreted the docs for API client auth. To resolve that, I followed the getting started guide docs, posted by rjacolin, for the _Request an Access Token using the Resource Owner Flow_ as I didn’t need the redirects used in the other types of auth.

My next problem was yet another mistake on my end, due to incorrectly assuming our endpoints were in na and not eu. I was wrong; they were in eu, so once I modified my url, everything worked.

I have a fairly complete set of Postman requests at this point, and happy to share them. Not sure how I’d do that, but there’s probably a way I can export them, if that would help. Hope this helps a little, and feel free to ask for clarification if necessary.

---

<div class="post-metadata">

**Author:** ![wkhatch](https://avatars.discourse-cdn.com/v4/letter/w/67e7ee/32.png) [@wkhatch](https://forum.sierrawireless.com/u/wkhatch)\
**Post date:** [January 20, 2020, 3:59pm UTC](https://forum.sierrawireless.com/t/how-do-i-set-the-header-grant-type-header-when-authenticating-an-api-client/18938/10 "2020-01-20T15:59:46Z")

</div>

Thought I’d posted my original solution to this, but not seeing it so providing a quick summary in case anybody else hits this type of response after successfully getting an auth token.

It was a simple matter of not using the correct end point base url. I’d assumed we were in [na.airvantage.com](http://na.airvantage.com), but we were actually in [eu.airvantage.com](http://eu.airvantage.com) Changing that fixed the issue.

---

<div class="post-metadata">

**Author:** ![jawaddidouh](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@jawaddidouh](https://forum.sierrawireless.com/u/jawaddidouh)\
**Post date:** [January 23, 2020, 6:59am UTC](https://forum.sierrawireless.com/t/how-do-i-set-the-header-grant-type-header-when-authenticating-an-api-client/18938/11 "2020-01-23T06:59:33Z")

</div>

Hi @wkhatch,

Thanks for reply, my mistake was finaly the header of the request ! every time i puted header = 1 !! so yes it’s was about your first issue !

Best regards,

Jawad
