API Refresh Token

Hi,

I’m new to FreeAgent and OAuth in general and was trying to get a refresh
token implemented but am having some problems.

I’m sending a request via Fiddler as follows:

POST request sent to: https://api.freeagent.com/v2/token_endpoint

Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Host: api.freeagent.com
Accept: application/json
Authorization: Basic

The request body contains: grant_type=refresh_token&refresh_token=

The access token has not expired when I try but I seem to always get a 401
Access Denied response.

Any ideas what I’m doing wrong?

I’ve also tried this in C# code and also get a 401.

Thanks,
Rikky.

Hi Anup,

Thanks for the reply.

I’ve tried what you said and still get a 401. This is both in Fidler and C#
code.

This is the response from RequestBin:

HEADERS

Accept-Encoding: gzip

Cf-Connecting-Ip: 79.78.173.144

Content-Type: application/json

Authorization: Basic

User-Agent: Fiddler

Content-Length: 91

Via: 1.1 vegur

Host: requestb.in

Cf-Ipcountry: GB

Connect-Time: 1

Connection: close

X-Request-Id: 3cf084d9-ed99-4e6c-9692-8ecf2a362b3b

Cf-Visitor: {“scheme”:“http”}

Accept: application/json

Total-Route-Time: 0

Cf-Ray: 2c6756c068f70a66-LHR

RAW BODY

{“grant_type”:“refresh_token”,“refresh_token”:"" }

Any idea why I still get a 401 Access Denied?

Thanks.On Tuesday, July 19, 2016 at 12:12:33 PM UTC+1, Rikky wrote:

Hi,

I’m new to FreeAgent and OAuth in general and was trying to get a refresh
token implemented but am having some problems.

I’m sending a request via Fiddler as follows:

POST request sent to: https://api.freeagent.com/v2/token_endpoint

Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Host: api.freeagent.com
Accept: application/json
Authorization: Basic

The request body contains: grant_type=refresh_token&refresh_token=

The access token has not expired when I try but I seem to always get a 401
Access Denied response.

Any ideas what I’m doing wrong?

I’ve also tried this in C# code and also get a 401.

Thanks,
Rikky.

Hi Anup,

Yes, that is how I construct the auth header. It is constructed as you
mentioned and then base64 encoded using clientid:client secret.

Thanks.

Hi Rikky,

Could you please confirm how you are constructing the Authorization header?

Say, if the client_id is “abc” and client_secret is “def”, it should be a
base64 encoded value of “abc:def”. In this case, it comes out to be
“YWJjOmRlZg==\n” and the value is “Basic YWJjOmRlZg==\n” for
“Authorization” header.

Regards,

Anup NarkhedeOn Tuesday, July 19, 2016 at 12:12:33 PM UTC+1, Rikky wrote:

Hi,

I’m new to FreeAgent and OAuth in general and was trying to get a refresh
token implemented but am having some problems.

I’m sending a request via Fiddler as follows:

POST request sent to: https://api.freeagent.com/v2/token_endpoint

Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Host: api.freeagent.com
Accept: application/json
Authorization: Basic

The request body contains: grant_type=refresh_token&refresh_token=

The access token has not expired when I try but I seem to always get a 401
Access Denied response.

Any ideas what I’m doing wrong?

I’ve also tried this in C# code and also get a 401.

Thanks,
Rikky.

Hi Rikky,

Apologies for the delayed response. Looks like the issue is caused by an
incorrect Content-Type header. It should be

“application/json” instead of
“application/x-www-form-urlencoded;charset=UTF-8”. We acknowledge this
mistake in the API docs and we will correct it.

Meanwhile, could you please try the following?

Header:

Content-Type: application/json

Accept: application/json

Authorization: Basic

Request body:

{“grant_type”:“refresh_token”,“refresh_token”:""}

Here’s a quick example to verify it using a curl command:

curl -H “Content-Type: application/json” -H “Authorization: Basic " -H “Accept: application/json” -X POST -d
'{“grant_type”:“refresh_token”,“refresh_token”:”<refresh_token>"}’
https://api.freeagent.com/v2/token_endpoint

Let me know if this helps.

Anup NarkhedeOn Tuesday, July 19, 2016 at 12:12:33 PM UTC+1, Rikky wrote:

Hi,

I’m new to FreeAgent and OAuth in general and was trying to get a refresh
token implemented but am having some problems.

I’m sending a request via Fiddler as follows:

POST request sent to: https://api.freeagent.com/v2/token_endpoint

Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Host: api.freeagent.com
Accept: application/json
Authorization: Basic

The request body contains: grant_type=refresh_token&refresh_token=

The access token has not expired when I try but I seem to always get a 401
Access Denied response.

Any ideas what I’m doing wrong?

I’ve also tried this in C# code and also get a 401.

Thanks,
Rikky.