Arrgghghgh - 401 - unauthorised error

Hi all,

Trying to swap my app from API 1.0 to 2.0, and I cant get past the token
request - getting Authorisation (401) error. My app is authorised,
appears in my Freeagent application list, and all seems good. But when my
app gets the token, no matter what I do, I cant get past a 401
authorisation error. Not sure if its the userid/password which is wrong
(picked up from the developer dashboard), or the passed in authorisation
code (which as instructed, is passed back following authorisation)

Note - the auth code and user/password codes have been changed from the
ACTUAL values, but are pretty much in the format as being supplied (length,
look/feel etc).

Note - the hard coding and odd settings (PreAuthenticate, Protocol version,
etc) are me trying to get the blasted thing working (following advice I
found on the web). Clearly, in my app, the auth codes wont be hard coded

  • but just trying to get past the 401 error at this point.

Any clues/advice?

        Dim URL As String
        URL = "https://api.freeagent.com/v2/token_endpoint"
        ' Create the data to send
        Dim data As StringBuilder = New StringBuilder()

data.Append(“grant_type=authorization_code&code=1Boeu6tpoeteCF8YAijVCendLiKY1mDbFnJNsw7nbS”)
<----- HARD CODED TO TEST WHERE ITS GOING WRONG

        ' Create a byte array of the data to be sent
        Dim byteArray As Byte() = 

UTF8Encoding.UTF8.GetBytes(data.ToString())

        ' Setup the Request
        Dim request As HttpWebRequest = WebRequest.Create(URL)
        request.PreAuthenticate = True
        request.Method = "POST"
        request.ProtocolVersion = HttpVersion.Version10
        request.ContentType = 

“application/x-www-form-urlencoded;charset=UTF-8”
request.ContentLength = byteArray.Length
request.Credentials = New
NetworkCredential(“PjdASDASDASccpVk4iag”, “KvSDFSDFDSFJl2dKOzaOg”)
<---------- HARD CODED TO TEST WHERE ITS GOING WRONG, ITS THE ‘*OAuth
identifier’ *AND OAuth secret VALUES

        ' Write data
        Dim postStream As Stream = request.GetRequestStream()
        postStream.Write(byteArray, 0, byteArray.Length)
        postStream.Close()

        ' Send Request & Get Response
        Response = request.GetResponse()   <------ 401 error here!!!!!!

Sorry, but I am…

through this line of code…

        request.Credentials = New 

NetworkCredential(“PjdASDASDASccpVk4iag”, “KvSDFSDFDSFJl2dKOzaOg”)

When you say CLIENTID, I assume you mean the “*OAuth identifier” *(its not
called clientid in the developer dashboard) - the first part is the client
id (oAUTH Identifier) and the 2nd is the secret code (note, the example
above is not the actual codes - change for this post).

I am posting them as request credentials (that used to work for V1 where I
sent the Freeagent login and user password) - or is it now supposed to go
in the actual send post (as per say the grant_type or application id?)On Tuesday, 4 February 2014 14:22:20 UTC, Harry wrote:

Hi,

Thanks for sending that through - taking a look at your request it doesn’t
look like you’re including the basic auth credentials in your request. This
should be set to the client ID and client secret as the username and
password respectively.


Regards,
Harry Mills

On Tue, Feb 4, 2014 at 12:59 PM, JaffaB <jaffa...@yahoo.co.uk<javascript:> wrote:

Thanks a lot.

Request has been sent through. Just the token request at this time.

Regards

J

On Tuesday, 4 February 2014 12:29:36 UTC, JaffaB wrote:

Hi all,

Trying to swap my app from API 1.0 to 2.0, and I cant get past the token
request - getting Authorisation (401) error. My app is authorised,
appears in my Freeagent application list, and all seems good. But when my
app gets the token, no matter what I do, I cant get past a 401
authorisation error. Not sure if its the userid/password which is wrong
(picked up from the developer dashboard), or the passed in authorisation
code (which as instructed, is passed back following authorisation)

Note - the auth code and user/password codes have been changed from the
ACTUAL values, but are pretty much in the format as being supplied (length,
look/feel etc).

Note - the hard coding and odd settings (PreAuthenticate, Protocol
version, etc) are me trying to get the blasted thing working (following
advice I found on the web). Clearly, in my app, the auth codes wont be
hard coded - but just trying to get past the 401 error at this point.

Any clues/advice?

        Dim URL As String
        URL = "https://api.freeagent.com/v2/token_endpoint"
        ' Create the data to send
        Dim data As StringBuilder = New StringBuilder()
        data.Append("grant_type=authorization_code&code=

1Boeu6tpoeteCF8YAijVCendLiKY1mDbFnJNsw7nbS") <----- HARD CODED TO
TEST WHERE ITS GOING WRONG

        ' Create a byte array of the data to be sent
        Dim byteArray As Byte() = UTF8Encoding.UTF8.GetBytes(

data.ToString())

        ' Setup the Request
        Dim request As HttpWebRequest = WebRequest.Create(URL)
        request.PreAuthenticate = True
        request.Method = "POST"
        request.ProtocolVersion = HttpVersion.Version10
        request.ContentType = "application/x-www-form-

urlencoded;charset=UTF-8"
request.ContentLength = byteArray.Length
request.Credentials = New NetworkCredential(“PjdASDASDASccpVk4iag”,
“KvSDFSDFDSFJl2dKOzaOg”) <---------- HARD CODED TO TEST WHERE ITS GOING
WRONG, ITS THE ‘*OAuth identifier’ *AND OAuth secret VALUES

        ' Write data
        Dim postStream As Stream = request.GetRequestStream()
        postStream.Write(byteArray, 0, byteArray.Length)
        postStream.Close()

        ' Send Request & Get Response
        Response = request.GetResponse()   <------ 401 error 

here!!!


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_ap...@googlegroups.com <javascript:>.
To post to this group, send email to freeag...@googlegroups.com<javascript:>
.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.

Hi,

That’s quite strange - they’re not showing up in the request bin. I made a
request with basic auth using curl (just curl -X POST -u test_user:password http://requestb.in/1c9tdj71) and it shows the
Authorization: Basic… line in the headers (see
http://requestb.in/1c9tdj71?inspect#1ixtx2). I can’t see this line on your
request (http://requestb.in/1c9tdj71?inspect#19t3a9).

I’m not familiar with the library you’re using to create the request but
I’m afraid it’s not sending through the basic auth credentials.

Regards,
Harry MillsOn Tue, Feb 4, 2014 at 2:52 PM, JaffaB jaffa_brown@yahoo.co.uk wrote:

Sorry, but I am…

through this line of code…

        request.Credentials = New

NetworkCredential(“PjdASDASDASccpVk4iag”, “KvSDFSDFDSFJl2dKOzaOg”)

When you say CLIENTID, I assume you mean the “*OAuth identifier” *(its
not called clientid in the developer dashboard) - the first part is the
client id (oAUTH Identifier) and the 2nd is the secret code (note, the
example above is not the actual codes - change for this post).

I am posting them as request credentials (that used to work for V1 where I
sent the Freeagent login and user password) - or is it now supposed to go
in the actual send post (as per say the grant_type or application id?)

On Tuesday, 4 February 2014 14:22:20 UTC, Harry wrote:

Hi,

Thanks for sending that through - taking a look at your request it
doesn’t look like you’re including the basic auth credentials in your
request. This should be set to the client ID and client secret as the
username and password respectively.


Regards,
Harry Mills

On Tue, Feb 4, 2014 at 12:59 PM, JaffaB jaffa...@yahoo.co.uk wrote:

Thanks a lot.

Request has been sent through. Just the token request at this time.

Regards

J

On Tuesday, 4 February 2014 12:29:36 UTC, JaffaB wrote:

Hi all,

Trying to swap my app from API 1.0 to 2.0, and I cant get past the
token request - getting Authorisation (401) error. My app is authorised,
appears in my Freeagent application list, and all seems good. But when my
app gets the token, no matter what I do, I cant get past a 401
authorisation error. Not sure if its the userid/password which is wrong
(picked up from the developer dashboard), or the passed in authorisation
code (which as instructed, is passed back following authorisation)

Note - the auth code and user/password codes have been changed from the
ACTUAL values, but are pretty much in the format as being supplied (length,
look/feel etc).

Note - the hard coding and odd settings (PreAuthenticate, Protocol
version, etc) are me trying to get the blasted thing working (following
advice I found on the web). Clearly, in my app, the auth codes wont be
hard coded - but just trying to get past the 401 error at this point.

Any clues/advice?

        Dim URL As String
        URL = "https://api.freeagent.com/v2/token_endpoint"
        ' Create the data to send
        Dim data As StringBuilder = New StringBuilder()
        data.Append("grant_type=authorization_code&code=

1Boeu6tpoeteCF8YAijVCendLiKY1mDbFnJNsw7nbS") <----- HARD CODED TO
TEST WHERE ITS GOING WRONG

        ' Create a byte array of the data to be sent
        Dim byteArray As Byte() = UTF8Encoding.UTF8.GetBytes(dat

a.ToString())

        ' Setup the Request
        Dim request As HttpWebRequest = WebRequest.Create(URL)
        request.PreAuthenticate = True
        request.Method = "POST"
        request.ProtocolVersion = HttpVersion.Version10
        request.ContentType = "application/x-www-form-urlenc

oded;charset=UTF-8"
request.ContentLength = byteArray.Length
request.Credentials = New NetworkCredential(“PjdASDASDASccpVk4iag”,
“KvSDFSDFDSFJl2dKOzaOg”) <---------- HARD CODED TO TEST WHERE ITS GOING
WRONG, ITS THE ‘*OAuth identifier’ *AND OAuth secret VALUES

        ' Write data
        Dim postStream As Stream = request.GetRequestStream()
        postStream.Write(byteArray, 0, byteArray.Length)
        postStream.Close()

        ' Send Request & Get Response
        Response = request.GetResponse()   <------ 401 error

here!!!


You received this message because you are subscribed to the Google
Groups “FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to freeagent_ap...@googlegroups.com.
To post to this group, send email to freeag...@googlegroups.com.

Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_api+unsubscribe@googlegroups.com.
To post to this group, send email to freeagent_api@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.

Hi there,

Sorry to hear you’re having problems. I’d like to check what you’re sending
through to make sure the headers are getting set correctly and it’s being
sent in the right format as I’m not familiar with the HTTP request library
you’re using. Request Bin (http://requestb.in) is a great service for this

  • you can just change the URL at the top of your script to "
    http://requestb.in/1c9tdj71" (an empty bin I just set up) and run the
    script. The HTTP request will be shown on the request bin page. Make sure
    you’re not sending through anything confidential as anyone with the URL can
    view your post.

Let me know when you’ve got the request up on the page and I can take a
look and we can work out what’s going wrong.

Regards,
Harry MillsOn Tue, Feb 4, 2014 at 12:29 PM, JaffaB jaffa_brown@yahoo.co.uk wrote:

Hi all,

Trying to swap my app from API 1.0 to 2.0, and I cant get past the token
request - getting Authorisation (401) error. My app is authorised,
appears in my Freeagent application list, and all seems good. But when my
app gets the token, no matter what I do, I cant get past a 401
authorisation error. Not sure if its the userid/password which is wrong
(picked up from the developer dashboard), or the passed in authorisation
code (which as instructed, is passed back following authorisation)

Note - the auth code and user/password codes have been changed from the
ACTUAL values, but are pretty much in the format as being supplied (length,
look/feel etc).

Note - the hard coding and odd settings (PreAuthenticate, Protocol
version, etc) are me trying to get the blasted thing working (following
advice I found on the web). Clearly, in my app, the auth codes wont be
hard coded - but just trying to get past the 401 error at this point.

Any clues/advice?

        Dim URL As String
        URL = "https://api.freeagent.com/v2/token_endpoint"
        ' Create the data to send
        Dim data As StringBuilder = New StringBuilder()

data.Append(“grant_type=authorization_code&code=1Boeu6tpoeteCF8YAijVCendLiKY1mDbFnJNsw7nbS”)
<----- HARD CODED TO TEST WHERE ITS GOING WRONG

        ' Create a byte array of the data to be sent
        Dim byteArray As Byte() =

UTF8Encoding.UTF8.GetBytes(data.ToString())

        ' Setup the Request
        Dim request As HttpWebRequest = WebRequest.Create(URL)
        request.PreAuthenticate = True
        request.Method = "POST"
        request.ProtocolVersion = HttpVersion.Version10
        request.ContentType =

“application/x-www-form-urlencoded;charset=UTF-8”
request.ContentLength = byteArray.Length
request.Credentials = New
NetworkCredential(“PjdASDASDASccpVk4iag”, “KvSDFSDFDSFJl2dKOzaOg”)
<---------- HARD CODED TO TEST WHERE ITS GOING WRONG, ITS THE ‘*OAuth
identifier’ *AND OAuth secret VALUES

        ' Write data
        Dim postStream As Stream = request.GetRequestStream()
        postStream.Write(byteArray, 0, byteArray.Length)
        postStream.Close()

        ' Send Request & Get Response
        Response = request.GetResponse()   <------ 401 error here!!!!!!


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_api+unsubscribe@googlegroups.com.
To post to this group, send email to freeagent_api@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.

Hi,

Thanks for sending that through - taking a look at your request it doesn’t
look like you’re including the basic auth credentials in your request. This
should be set to the client ID and client secret as the username and
password respectively.

Regards,
Harry MillsOn Tue, Feb 4, 2014 at 12:59 PM, JaffaB jaffa_brown@yahoo.co.uk wrote:

Thanks a lot.

Request has been sent through. Just the token request at this time.

Regards

J

On Tuesday, 4 February 2014 12:29:36 UTC, JaffaB wrote:

Hi all,

Trying to swap my app from API 1.0 to 2.0, and I cant get past the token
request - getting Authorisation (401) error. My app is authorised,
appears in my Freeagent application list, and all seems good. But when my
app gets the token, no matter what I do, I cant get past a 401
authorisation error. Not sure if its the userid/password which is wrong
(picked up from the developer dashboard), or the passed in authorisation
code (which as instructed, is passed back following authorisation)

Note - the auth code and user/password codes have been changed from the
ACTUAL values, but are pretty much in the format as being supplied (length,
look/feel etc).

Note - the hard coding and odd settings (PreAuthenticate, Protocol
version, etc) are me trying to get the blasted thing working (following
advice I found on the web). Clearly, in my app, the auth codes wont be
hard coded - but just trying to get past the 401 error at this point.

Any clues/advice?

        Dim URL As String
        URL = "https://api.freeagent.com/v2/token_endpoint"
        ' Create the data to send
        Dim data As StringBuilder = New StringBuilder()
        data.Append("grant_type=authorization_code&code=

1Boeu6tpoeteCF8YAijVCendLiKY1mDbFnJNsw7nbS") <----- HARD CODED TO TEST
WHERE ITS GOING WRONG

        ' Create a byte array of the data to be sent
        Dim byteArray As Byte() = UTF8Encoding.UTF8.GetBytes(

data.ToString())

        ' Setup the Request
        Dim request As HttpWebRequest = WebRequest.Create(URL)
        request.PreAuthenticate = True
        request.Method = "POST"
        request.ProtocolVersion = HttpVersion.Version10
        request.ContentType = "application/x-www-form-

urlencoded;charset=UTF-8"
request.ContentLength = byteArray.Length
request.Credentials = New NetworkCredential(“PjdASDASDASccpVk4iag”,
“KvSDFSDFDSFJl2dKOzaOg”) <---------- HARD CODED TO TEST WHERE ITS GOING
WRONG, ITS THE ‘*OAuth identifier’ *AND OAuth secret VALUES

        ' Write data
        Dim postStream As Stream = request.GetRequestStream()
        postStream.Write(byteArray, 0, byteArray.Length)
        postStream.Close()

        ' Send Request & Get Response
        Response = request.GetResponse()   <------ 401 error

here!!!


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_api+unsubscribe@googlegroups.com.
To post to this group, send email to freeagent_api@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.

Your’s appears to be VB.NET, but I have an almost-full C# client here:

and I build up that URL here:

and

From memory, for the token_access url, you dont need ANY headers. You
DO need them once you have a proper token, then it’s just

request.AddHeader(“Authorization”, "Bearer " +
Client.CurrentAccessToken.access_token);

(the access token is what you get back from the token_access call)

My client, which I use in mobileAgent, uses RestSharp, but it
shouldn’t be too hard to work out whats going on.On Wed, Feb 5, 2014 at 4:26 AM, JaffaB jaffa_brown@yahoo.co.uk wrote:

Agghghghgh - about to give up on this. Tired all the permutations I can
think of including…

Adding it to the data packet…

            data.Append("grant_type=" + Uri.EscapeDataString(grantType))
            data.Append("&code=" + Uri.EscapeDataString(application_id))
            data.Append("&username=" + Uri.EscapeDataString(username))
            data.Append("&password=" + Uri.EscapeDataString(password))

Forcing it into the header…

            request.Credentials = New NetworkCredential(username,

password)
Dim credentialBuffer As Byte() = New
UTF8Encoding().GetBytes(Uri.EscapeDataString(username) + “:” +
Uri.EscapeDataString(password))
request.Headers(“Authorization”) = "Basic " +
Convert.ToBase64String(credentialBuffer)

And then forcing though the authentication…

            Dim nc As NetworkCredential = New

NetworkCredential(username, password)
Dim cache As CredentialCache = New CredentialCache()
cache.Add(New Uri(url), “Basic”, nc)
request.Credentials = cache
request.PreAuthenticate = True

All of which give me the same result - 401 - Unauthorized.

I will park this for now and move onto another project - but if anybody else
has any ideas, I would love to hear them. Shame - V1 of the interface was
soooo easy compared to this.

J

On Tuesday, 4 February 2014 12:29:36 UTC, JaffaB wrote:

Hi all,

Trying to swap my app from API 1.0 to 2.0, and I cant get past the token
request - getting Authorisation (401) error. My app is authorised, appears
in my Freeagent application list, and all seems good. But when my app gets
the token, no matter what I do, I cant get past a 401 authorisation error.
Not sure if its the userid/password which is wrong (picked up from the
developer dashboard), or the passed in authorisation code (which as
instructed, is passed back following authorisation)

Note - the auth code and user/password codes have been changed from the
ACTUAL values, but are pretty much in the format as being supplied (length,
look/feel etc).

Note - the hard coding and odd settings (PreAuthenticate, Protocol
version, etc) are me trying to get the blasted thing working (following
advice I found on the web). Clearly, in my app, the auth codes wont be
hard coded - but just trying to get past the 401 error at this point.

Any clues/advice?

        Dim URL As String
        URL = "https://api.freeagent.com/v2/token_endpoint"
        ' Create the data to send
        Dim data As StringBuilder = New StringBuilder()

data.Append(“grant_type=authorization_code&code=1Boeu6tpoeteCF8YAijVCendLiKY1mDbFnJNsw7nbS”)
<----- HARD CODED TO TEST WHERE ITS GOING WRONG

        ' Create a byte array of the data to be sent
        Dim byteArray As Byte() =

UTF8Encoding.UTF8.GetBytes(data.ToString())

        ' Setup the Request
        Dim request As HttpWebRequest = WebRequest.Create(URL)
        request.PreAuthenticate = True
        request.Method = "POST"
        request.ProtocolVersion = HttpVersion.Version10
        request.ContentType =

“application/x-www-form-urlencoded;charset=UTF-8”
request.ContentLength = byteArray.Length
request.Credentials = New
NetworkCredential(“PjdASDASDASccpVk4iag”, “KvSDFSDFDSFJl2dKOzaOg”)
<---------- HARD CODED TO TEST WHERE ITS GOING WRONG, ITS THE ‘OAuth
identifier’ AND OAuth secret VALUES

        ' Write data
        Dim postStream As Stream = request.GetRequestStream()
        postStream.Write(byteArray, 0, byteArray.Length)
        postStream.Close()

        ' Send Request & Get Response
        Response = request.GetResponse()   <------ 401 error

here!!!


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_api+unsubscribe@googlegroups.com.
To post to this group, send email to freeagent_api@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.

Nic Wise
t. +64 21 676 418 | @fastchicken
b. http://www.fastchicken.co.nz/

Agghghghgh - about to give up on this. Tired all the permutations I can
think of including…

Adding it to the data packet…

            data.Append("grant_type=" + Uri.EscapeDataString(grantType))
            data.Append("&code=" + Uri.EscapeDataString(application_id))
            data.Append("&username=" + Uri.EscapeDataString(username))
            data.Append("&password=" + Uri.EscapeDataString(password))

Forcing it into the header…

            request.Credentials = New NetworkCredential(username, 

password)
Dim credentialBuffer As Byte() = New
UTF8Encoding().GetBytes(Uri.EscapeDataString(username) + “:” +
Uri.EscapeDataString(password))
request.Headers(“Authorization”) = "Basic " +
Convert.ToBase64String(credentialBuffer)

And then forcing though the authentication…

            Dim nc As NetworkCredential = New 

NetworkCredential(username, password)
Dim cache As CredentialCache = New CredentialCache()
cache.Add(New Uri(url), “Basic”, nc)
request.Credentials = cache
request.PreAuthenticate = True

All of which give me the same result - 401 - Unauthorized.

I will park this for now and move onto another project - but if anybody
else has any ideas, I would love to hear them. Shame - V1 of the interface
was soooo easy compared to this.

JOn Tuesday, 4 February 2014 12:29:36 UTC, JaffaB wrote:

Hi all,

Trying to swap my app from API 1.0 to 2.0, and I cant get past the token
request - getting Authorisation (401) error. My app is authorised,
appears in my Freeagent application list, and all seems good. But when my
app gets the token, no matter what I do, I cant get past a 401
authorisation error. Not sure if its the userid/password which is wrong
(picked up from the developer dashboard), or the passed in authorisation
code (which as instructed, is passed back following authorisation)

Note - the auth code and user/password codes have been changed from the
ACTUAL values, but are pretty much in the format as being supplied (length,
look/feel etc).

Note - the hard coding and odd settings (PreAuthenticate, Protocol
version, etc) are me trying to get the blasted thing working (following
advice I found on the web). Clearly, in my app, the auth codes wont be
hard coded - but just trying to get past the 401 error at this point.

Any clues/advice?

        Dim URL As String
        URL = "https://api.freeagent.com/v2/token_endpoint"
        ' Create the data to send
        Dim data As StringBuilder = New StringBuilder()

data.Append(“grant_type=authorization_code&code=1Boeu6tpoeteCF8YAijVCendLiKY1mDbFnJNsw7nbS”)
<----- HARD CODED TO TEST WHERE ITS GOING WRONG

        ' Create a byte array of the data to be sent
        Dim byteArray As Byte() = 

UTF8Encoding.UTF8.GetBytes(data.ToString())

        ' Setup the Request
        Dim request As HttpWebRequest = WebRequest.Create(URL)
        request.PreAuthenticate = True
        request.Method = "POST"
        request.ProtocolVersion = HttpVersion.Version10
        request.ContentType = 

“application/x-www-form-urlencoded;charset=UTF-8”
request.ContentLength = byteArray.Length
request.Credentials = New
NetworkCredential(“PjdASDASDASccpVk4iag”, “KvSDFSDFDSFJl2dKOzaOg”)
<---------- HARD CODED TO TEST WHERE ITS GOING WRONG, ITS THE ‘*OAuth
identifier’ *AND OAuth secret VALUES

        ' Write data
        Dim postStream As Stream = request.GetRequestStream()
        postStream.Write(byteArray, 0, byteArray.Length)
        postStream.Close()

        ' Send Request & Get Response
        Response = request.GetResponse()   <------ 401 error here!!!!!!

Well, I cracked it. The links didn’t help much becuase they were
actually passing parameters which Freeagent API didnt like…

        request.AddParameter("client_id", ApiKey, ParameterType.GetOrPost);
        request.AddParameter("client_secret", ApiSecret, ParameterType.GetOrPost);

anyway, after a bit more trial and error, found that you have to EXPLICITLY state you want to talk in json, otherwise the message is rejected with 401 - go figure!!

SO in case it helps anybody else, the code for the token fetch (in vb) is as follows:

            request.ContentType = "application/json"
            request.Credentials = New 

System.Net.NetworkCredential(username, password)
request.Headers(“Authorization”) = username & “:” & password
request.PreAuthenticate = True
request.Accept = “application/json, application/xml,
text/json, text/x-json, text/javascript, text/xml”
request.ContentLength = 0
request.Method = “POST”
request.ContentType = “application/x-www-form-urlencoded”
request.ContentLength = byteArray.LengthOn Wednesday, 5 February 2014 03:17:27 UTC, Nic Wise wrote:

Your’s appears to be VB.NET, but I have an almost-full C# client here:

https://github.com/nicwise/FreeAgent

and I build up that URL here:

https://github.com/nicwise/FreeAgent/blob/master/FreeAgent/Helpers/RequestHelper.cs

and

https://github.com/nicwise/FreeAgent/blob/master/FreeAgent/Client/Client.Authentication.cs

From memory, for the token_access url, you dont need ANY headers. You
DO need them once you have a proper token, then it’s just

request.AddHeader(“Authorization”, "Bearer " +
Client.CurrentAccessToken.access_token);

(the access token is what you get back from the token_access call)

My client, which I use in mobileAgent, uses RestSharp, but it
shouldn’t be too hard to work out whats going on.

On Wed, Feb 5, 2014 at 4:26 AM, JaffaB <jaffa...@yahoo.co.uk <javascript:>> wrote:

Agghghghgh - about to give up on this. Tired all the permutations I
can
think of including…

Adding it to the data packet…

            data.Append("grant_type=" + 

Uri.EscapeDataString(grantType))

            data.Append("&code=" + 

Uri.EscapeDataString(application_id))

            data.Append("&username=" + 

Uri.EscapeDataString(username))

            data.Append("&password=" + 

Uri.EscapeDataString(password))

Forcing it into the header…

            request.Credentials = New NetworkCredential(username, 

password)
Dim credentialBuffer As Byte() = New
UTF8Encoding().GetBytes(Uri.EscapeDataString(username) + “:” +
Uri.EscapeDataString(password))
request.Headers(“Authorization”) = "Basic " +
Convert.ToBase64String(credentialBuffer)

And then forcing though the authentication…

            Dim nc As NetworkCredential = New 

NetworkCredential(username, password)
Dim cache As CredentialCache = New CredentialCache()
cache.Add(New Uri(url), “Basic”, nc)
request.Credentials = cache
request.PreAuthenticate = True

All of which give me the same result - 401 - Unauthorized.

I will park this for now and move onto another project - but if anybody
else
has any ideas, I would love to hear them. Shame - V1 of the interface
was
soooo easy compared to this.

J

On Tuesday, 4 February 2014 12:29:36 UTC, JaffaB wrote:

Hi all,

Trying to swap my app from API 1.0 to 2.0, and I cant get past the
token

request - getting Authorisation (401) error. My app is authorised,
appears

in my Freeagent application list, and all seems good. But when my app
gets

the token, no matter what I do, I cant get past a 401 authorisation
error.

Not sure if its the userid/password which is wrong (picked up from the
developer dashboard), or the passed in authorisation code (which as
instructed, is passed back following authorisation)

Note - the auth code and user/password codes have been changed from the
ACTUAL values, but are pretty much in the format as being supplied
(length,

look/feel etc).

Note - the hard coding and odd settings (PreAuthenticate, Protocol
version, etc) are me trying to get the blasted thing working (following
advice I found on the web). Clearly, in my app, the auth codes wont
be

hard coded - but just trying to get past the 401 error at this point.

Any clues/advice?

        Dim URL As String 
        URL = "https://api.freeagent.com/v2/token_endpoint" 
        ' Create the data to send 
        Dim data As StringBuilder = New StringBuilder() 

data.Append(“grant_type=authorization_code&code=1Boeu6tpoeteCF8YAijVCendLiKY1mDbFnJNsw7nbS”)

<----- HARD CODED TO TEST WHERE ITS GOING WRONG

        ' Create a byte array of the data to be sent 
        Dim byteArray As Byte() = 

UTF8Encoding.UTF8.GetBytes(data.ToString())

        ' Setup the Request 
        Dim request As HttpWebRequest = WebRequest.Create(URL) 
        request.PreAuthenticate = True 
        request.Method = "POST" 
        request.ProtocolVersion = HttpVersion.Version10 
        request.ContentType = 

“application/x-www-form-urlencoded;charset=UTF-8”
request.ContentLength = byteArray.Length
request.Credentials = New
NetworkCredential(“PjdASDASDASccpVk4iag”, “KvSDFSDFDSFJl2dKOzaOg”)
<---------- HARD CODED TO TEST WHERE ITS GOING WRONG, ITS THE ‘OAuth
identifier’ AND OAuth secret VALUES

        ' Write data 
        Dim postStream As Stream = request.GetRequestStream() 
        postStream.Write(byteArray, 0, byteArray.Length) 
        postStream.Close() 

        ' Send Request & Get Response 
        Response = request.GetResponse()   <------ 401 error 

here!!!


You received this message because you are subscribed to the Google
Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send
an
email to freeagent_ap...@googlegroups.com <javascript:>.
To post to this group, send email to freeag...@googlegroups.com<javascript:>.

Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.


Nic Wise
t. +64 21 676 418 | @fastchicken
b. http://www.fastchicken.co.nz/

Thanks a lot.

Request has been sent through. Just the token request at this time.

Regards

JOn Tuesday, 4 February 2014 12:29:36 UTC, JaffaB wrote:

Hi all,

Trying to swap my app from API 1.0 to 2.0, and I cant get past the token
request - getting Authorisation (401) error. My app is authorised,
appears in my Freeagent application list, and all seems good. But when my
app gets the token, no matter what I do, I cant get past a 401
authorisation error. Not sure if its the userid/password which is wrong
(picked up from the developer dashboard), or the passed in authorisation
code (which as instructed, is passed back following authorisation)

Note - the auth code and user/password codes have been changed from the
ACTUAL values, but are pretty much in the format as being supplied (length,
look/feel etc).

Note - the hard coding and odd settings (PreAuthenticate, Protocol
version, etc) are me trying to get the blasted thing working (following
advice I found on the web). Clearly, in my app, the auth codes wont be
hard coded - but just trying to get past the 401 error at this point.

Any clues/advice?

        Dim URL As String
        URL = "https://api.freeagent.com/v2/token_endpoint"
        ' Create the data to send
        Dim data As StringBuilder = New StringBuilder()

data.Append(“grant_type=authorization_code&code=1Boeu6tpoeteCF8YAijVCendLiKY1mDbFnJNsw7nbS”)
<----- HARD CODED TO TEST WHERE ITS GOING WRONG

        ' Create a byte array of the data to be sent
        Dim byteArray As Byte() = 

UTF8Encoding.UTF8.GetBytes(data.ToString())

        ' Setup the Request
        Dim request As HttpWebRequest = WebRequest.Create(URL)
        request.PreAuthenticate = True
        request.Method = "POST"
        request.ProtocolVersion = HttpVersion.Version10
        request.ContentType = 

“application/x-www-form-urlencoded;charset=UTF-8”
request.ContentLength = byteArray.Length
request.Credentials = New
NetworkCredential(“PjdASDASDASccpVk4iag”, “KvSDFSDFDSFJl2dKOzaOg”)
<---------- HARD CODED TO TEST WHERE ITS GOING WRONG, ITS THE ‘*OAuth
identifier’ *AND OAuth secret VALUES

        ' Write data
        Dim postStream As Stream = request.GetRequestStream()
        postStream.Write(byteArray, 0, byteArray.Length)
        postStream.Close()

        ' Send Request & Get Response
        Response = request.GetResponse()   <------ 401 error here!!!!!!

We support both HTTP Basic Auth and placing the client_id and client_secret
in the request parameters. The vast majority of our third party developers
use a client library to handle OAuth authentication with FreeAgent, and
supporting both means we can support all client libraries.

The
​OAuth ​
section of the documentation is for users who choose to roll their own
OAuth client code and so as the IETF don’t recommend putting the client_id
and client_secret in the reques
​t it isn’t documented
: http://tools.ietf.org/html/rfc6749#section-2.3.1

All OAuth services must support HTTP Basic Auth, whereas support for
client_id and client_secret in parameters is optional.

​I hope this clears up any confusion.​

Regards,
Harry MillsOn Sun, Feb 9, 2014 at 8:57 PM, Nic Wise nicw@fastchicken.co.nz wrote:

Very strange - I didn’t think they still supported username/password
auth, but that it was all oauth (and Authorization: Bearer )

But yeah, you do have to tell it you want json - RestSharp does that for
me :slight_smile:

On Thu, Feb 6, 2014 at 1:41 AM, JaffaB jaffa_brown@yahoo.co.uk wrote:

Well, I cracked it. The links didn’t help much becuase they were
actually
passing parameters which Freeagent API didnt like…

        request.AddParameter("client_id", ApiKey,

ParameterType.GetOrPost);
request.AddParameter(“client_secret”, ApiSecret,
ParameterType.GetOrPost);

anyway, after a bit more trial and error, found that you have to
EXPLICITLY
state you want to talk in json, otherwise the message is rejected with
401 -
go figure!!

SO in case it helps anybody else, the code for the token fetch (in vb)
is as
follows:

            request.ContentType = "application/json"
            request.Credentials = New

System.Net.NetworkCredential(username, password)
request.Headers(“Authorization”) = username & “:” &
password
request.PreAuthenticate = True
request.Accept = “application/json, application/xml,
text/json, text/x-json, text/javascript, text/xml”
request.ContentLength = 0
request.Method = “POST”
request.ContentType = “application/x-www-form-urlencoded”
request.ContentLength = byteArray.Length

On Wednesday, 5 February 2014 03:17:27 UTC, Nic Wise wrote:

Your’s appears to be VB.NET, but I have an almost-full C# client here:

https://github.com/nicwise/FreeAgent

and I build up that URL here:

https://github.com/nicwise/FreeAgent/blob/master/FreeAgent/Helpers/RequestHelper.cs

and

https://github.com/nicwise/FreeAgent/blob/master/FreeAgent/Client/Client.Authentication.cs

From memory, for the token_access url, you dont need ANY headers. You
DO need them once you have a proper token, then it’s just

request.AddHeader(“Authorization”, "Bearer " +
Client.CurrentAccessToken.access_token);

(the access token is what you get back from the token_access call)

My client, which I use in mobileAgent, uses RestSharp, but it
shouldn’t be too hard to work out whats going on.

On Wed, Feb 5, 2014 at 4:26 AM, JaffaB jaffa...@yahoo.co.uk wrote:

Agghghghgh - about to give up on this. Tired all the permutations I
can
think of including…

Adding it to the data packet…

            data.Append("grant_type=" +

Uri.EscapeDataString(grantType))
data.Append("&code=" +
Uri.EscapeDataString(application_id))
data.Append("&username=" +
Uri.EscapeDataString(username))
data.Append("&password=" +
Uri.EscapeDataString(password))

Forcing it into the header…

            request.Credentials = New NetworkCredential(username,

password)
Dim credentialBuffer As Byte() = New
UTF8Encoding().GetBytes(Uri.EscapeDataString(username) + “:” +
Uri.EscapeDataString(password))
request.Headers(“Authorization”) = "Basic " +
Convert.ToBase64String(credentialBuffer)

And then forcing though the authentication…

            Dim nc As NetworkCredential = New

NetworkCredential(username, password)
Dim cache As CredentialCache = New CredentialCache()
cache.Add(New Uri(url), “Basic”, nc)
request.Credentials = cache
request.PreAuthenticate = True

All of which give me the same result - 401 - Unauthorized.

I will park this for now and move onto another project - but if
anybody

else
has any ideas, I would love to hear them. Shame - V1 of the interface
was
soooo easy compared to this.

J

On Tuesday, 4 February 2014 12:29:36 UTC, JaffaB wrote:

Hi all,

Trying to swap my app from API 1.0 to 2.0, and I cant get past the
token
request - getting Authorisation (401) error. My app is authorised,
appears
in my Freeagent application list, and all seems good. But when my
app

gets
the token, no matter what I do, I cant get past a 401 authorisation
error.
Not sure if its the userid/password which is wrong (picked up from
the

developer dashboard), or the passed in authorisation code (which as
instructed, is passed back following authorisation)

Note - the auth code and user/password codes have been changed from
the

ACTUAL values, but are pretty much in the format as being supplied
(length,
look/feel etc).

Note - the hard coding and odd settings (PreAuthenticate, Protocol
version, etc) are me trying to get the blasted thing working
(following

advice I found on the web). Clearly, in my app, the auth codes wont
be
hard coded - but just trying to get past the 401 error at this point.

Any clues/advice?

        Dim URL As String
        URL = "https://api.freeagent.com/v2/token_endpoint"
        ' Create the data to send
        Dim data As StringBuilder = New StringBuilder()

data.Append(“grant_type=authorization_code&code=1Boeu6tpoeteCF8YAijVCendLiKY1mDbFnJNsw7nbS”)

<----- HARD CODED TO TEST WHERE ITS GOING WRONG

        ' Create a byte array of the data to be sent
        Dim byteArray As Byte() =

UTF8Encoding.UTF8.GetBytes(data.ToString())

        ' Setup the Request
        Dim request As HttpWebRequest = WebRequest.Create(URL)
        request.PreAuthenticate = True
        request.Method = "POST"
        request.ProtocolVersion = HttpVersion.Version10
        request.ContentType =

“application/x-www-form-urlencoded;charset=UTF-8”
request.ContentLength = byteArray.Length
request.Credentials = New
NetworkCredential(“PjdASDASDASccpVk4iag”, “KvSDFSDFDSFJl2dKOzaOg”)
<---------- HARD CODED TO TEST WHERE ITS GOING WRONG, ITS THE ‘OAuth
identifier’ AND OAuth secret VALUES

        ' Write data
        Dim postStream As Stream = request.GetRequestStream()
        postStream.Write(byteArray, 0, byteArray.Length)
        postStream.Close()

        ' Send Request & Get Response
        Response = request.GetResponse()   <------ 401 error

here!!!


You received this message because you are subscribed to the Google
Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send
an
email to freeagent_ap...@googlegroups.com.
To post to this group, send email to freeag...@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.


Nic Wise
t. +64 21 676 418 | @fastchicken
b. http://www.fastchicken.co.nz/


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_api+unsubscribe@googlegroups.com.
To post to this group, send email to freeagent_api@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.


Nic Wise
t. +64 21 676 418 | @fastchicken
b. http://www.fastchicken.co.nz/


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_api+unsubscribe@googlegroups.com.
To post to this group, send email to freeagent_api@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.

Very strange - I didn’t think they still supported username/password
auth, but that it was all oauth (and Authorization: Bearer )

But yeah, you do have to tell it you want json - RestSharp does that for me :)On Thu, Feb 6, 2014 at 1:41 AM, JaffaB jaffa_brown@yahoo.co.uk wrote:

Well, I cracked it. The links didn’t help much becuase they were actually
passing parameters which Freeagent API didnt like…

        request.AddParameter("client_id", ApiKey,

ParameterType.GetOrPost);
request.AddParameter(“client_secret”, ApiSecret,
ParameterType.GetOrPost);

anyway, after a bit more trial and error, found that you have to EXPLICITLY
state you want to talk in json, otherwise the message is rejected with 401 -
go figure!!

SO in case it helps anybody else, the code for the token fetch (in vb) is as
follows:

            request.ContentType = "application/json"
            request.Credentials = New

System.Net.NetworkCredential(username, password)
request.Headers(“Authorization”) = username & “:” & password
request.PreAuthenticate = True
request.Accept = “application/json, application/xml,
text/json, text/x-json, text/javascript, text/xml”
request.ContentLength = 0
request.Method = “POST”
request.ContentType = “application/x-www-form-urlencoded”
request.ContentLength = byteArray.Length

On Wednesday, 5 February 2014 03:17:27 UTC, Nic Wise wrote:

Your’s appears to be VB.NET, but I have an almost-full C# client here:

https://github.com/nicwise/FreeAgent

and I build up that URL here:

https://github.com/nicwise/FreeAgent/blob/master/FreeAgent/Helpers/RequestHelper.cs

and

https://github.com/nicwise/FreeAgent/blob/master/FreeAgent/Client/Client.Authentication.cs

From memory, for the token_access url, you dont need ANY headers. You
DO need them once you have a proper token, then it’s just

request.AddHeader(“Authorization”, "Bearer " +
Client.CurrentAccessToken.access_token);

(the access token is what you get back from the token_access call)

My client, which I use in mobileAgent, uses RestSharp, but it
shouldn’t be too hard to work out whats going on.

On Wed, Feb 5, 2014 at 4:26 AM, JaffaB jaffa...@yahoo.co.uk wrote:

Agghghghgh - about to give up on this. Tired all the permutations I
can
think of including…

Adding it to the data packet…

            data.Append("grant_type=" +

Uri.EscapeDataString(grantType))
data.Append("&code=" +
Uri.EscapeDataString(application_id))
data.Append("&username=" +
Uri.EscapeDataString(username))
data.Append("&password=" +
Uri.EscapeDataString(password))

Forcing it into the header…

            request.Credentials = New NetworkCredential(username,

password)
Dim credentialBuffer As Byte() = New
UTF8Encoding().GetBytes(Uri.EscapeDataString(username) + “:” +
Uri.EscapeDataString(password))
request.Headers(“Authorization”) = "Basic " +
Convert.ToBase64String(credentialBuffer)

And then forcing though the authentication…

            Dim nc As NetworkCredential = New

NetworkCredential(username, password)
Dim cache As CredentialCache = New CredentialCache()
cache.Add(New Uri(url), “Basic”, nc)
request.Credentials = cache
request.PreAuthenticate = True

All of which give me the same result - 401 - Unauthorized.

I will park this for now and move onto another project - but if anybody
else
has any ideas, I would love to hear them. Shame - V1 of the interface
was
soooo easy compared to this.

J

On Tuesday, 4 February 2014 12:29:36 UTC, JaffaB wrote:

Hi all,

Trying to swap my app from API 1.0 to 2.0, and I cant get past the
token
request - getting Authorisation (401) error. My app is authorised,
appears
in my Freeagent application list, and all seems good. But when my app
gets
the token, no matter what I do, I cant get past a 401 authorisation
error.
Not sure if its the userid/password which is wrong (picked up from the
developer dashboard), or the passed in authorisation code (which as
instructed, is passed back following authorisation)

Note - the auth code and user/password codes have been changed from the
ACTUAL values, but are pretty much in the format as being supplied
(length,
look/feel etc).

Note - the hard coding and odd settings (PreAuthenticate, Protocol
version, etc) are me trying to get the blasted thing working (following
advice I found on the web). Clearly, in my app, the auth codes wont
be
hard coded - but just trying to get past the 401 error at this point.

Any clues/advice?

        Dim URL As String
        URL = "https://api.freeagent.com/v2/token_endpoint"
        ' Create the data to send
        Dim data As StringBuilder = New StringBuilder()

data.Append(“grant_type=authorization_code&code=1Boeu6tpoeteCF8YAijVCendLiKY1mDbFnJNsw7nbS”)
<----- HARD CODED TO TEST WHERE ITS GOING WRONG

        ' Create a byte array of the data to be sent
        Dim byteArray As Byte() =

UTF8Encoding.UTF8.GetBytes(data.ToString())

        ' Setup the Request
        Dim request As HttpWebRequest = WebRequest.Create(URL)
        request.PreAuthenticate = True
        request.Method = "POST"
        request.ProtocolVersion = HttpVersion.Version10
        request.ContentType =

“application/x-www-form-urlencoded;charset=UTF-8”
request.ContentLength = byteArray.Length
request.Credentials = New
NetworkCredential(“PjdASDASDASccpVk4iag”, “KvSDFSDFDSFJl2dKOzaOg”)
<---------- HARD CODED TO TEST WHERE ITS GOING WRONG, ITS THE ‘OAuth
identifier’ AND OAuth secret VALUES

        ' Write data
        Dim postStream As Stream = request.GetRequestStream()
        postStream.Write(byteArray, 0, byteArray.Length)
        postStream.Close()

        ' Send Request & Get Response
        Response = request.GetResponse()   <------ 401 error

here!!!


You received this message because you are subscribed to the Google
Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send
an
email to freeagent_ap...@googlegroups.com.
To post to this group, send email to freeag...@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.


Nic Wise
t. +64 21 676 418 | @fastchicken
b. http://www.fastchicken.co.nz/


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_api+unsubscribe@googlegroups.com.
To post to this group, send email to freeagent_api@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.

Nic Wise
t. +64 21 676 418 | @fastchicken
b. http://www.fastchicken.co.nz/

Having taken a look around for more information about the HttpWebRequest
Credential lines I found


might help. It appears others are having the same problem and you
might need some kind of credential cache that specifies the authorization
type (Basic).

Good luck!

Regards,
Harry MillsOn Tue, Feb 4, 2014 at 2:57 PM, Harry Mills harry@freeagent.com wrote:

Hi,

That’s quite strange - they’re not showing up in the request bin. I made a
request with basic auth using curl (just curl -X POST -u test_user:password http://requestb.in/1c9tdj71http://requestb.in/1c9tdj71)
and it shows the Authorization: Basic… line in the headers (see
http://requestb.in/1c9tdj71?inspect#1ixtx2). I can’t see this line on
your request (http://requestb.in/1c9tdj71?inspect#19t3a9).

I’m not familiar with the library you’re using to create the request but
I’m afraid it’s not sending through the basic auth credentials.


Regards,
Harry Mills

On Tue, Feb 4, 2014 at 2:52 PM, JaffaB jaffa_brown@yahoo.co.uk wrote:

Sorry, but I am…

through this line of code…

        request.Credentials = New

NetworkCredential(“PjdASDASDASccpVk4iag”, “KvSDFSDFDSFJl2dKOzaOg”)

When you say CLIENTID, I assume you mean the “*OAuth identifier” *(its
not called clientid in the developer dashboard) - the first part is the
client id (oAUTH Identifier) and the 2nd is the secret code (note, the
example above is not the actual codes - change for this post).

I am posting them as request credentials (that used to work for V1 where
I sent the Freeagent login and user password) - or is it now supposed to go
in the actual send post (as per say the grant_type or application id?)

On Tuesday, 4 February 2014 14:22:20 UTC, Harry wrote:

Hi,

Thanks for sending that through - taking a look at your request it
doesn’t look like you’re including the basic auth credentials in your
request. This should be set to the client ID and client secret as the
username and password respectively.


Regards,
Harry Mills

On Tue, Feb 4, 2014 at 12:59 PM, JaffaB jaffa...@yahoo.co.uk wrote:

Thanks a lot.

Request has been sent through. Just the token request at this time.

Regards

J

On Tuesday, 4 February 2014 12:29:36 UTC, JaffaB wrote:

Hi all,

Trying to swap my app from API 1.0 to 2.0, and I cant get past the
token request - getting Authorisation (401) error. My app is authorised,
appears in my Freeagent application list, and all seems good. But when my
app gets the token, no matter what I do, I cant get past a 401
authorisation error. Not sure if its the userid/password which is wrong
(picked up from the developer dashboard), or the passed in authorisation
code (which as instructed, is passed back following authorisation)

Note - the auth code and user/password codes have been changed from
the ACTUAL values, but are pretty much in the format as being supplied
(length, look/feel etc).

Note - the hard coding and odd settings (PreAuthenticate, Protocol
version, etc) are me trying to get the blasted thing working (following
advice I found on the web). Clearly, in my app, the auth codes wont be
hard coded - but just trying to get past the 401 error at this point.

Any clues/advice?

        Dim URL As String
        URL = "https://api.freeagent.com/v2/token_endpoint"
        ' Create the data to send
        Dim data As StringBuilder = New StringBuilder()
        data.Append("grant_type=authorization_code&code=

1Boeu6tpoeteCF8YAijVCendLiKY1mDbFnJNsw7nbS") <----- HARD CODED TO
TEST WHERE ITS GOING WRONG

        ' Create a byte array of the data to be sent
        Dim byteArray As Byte() = UTF8Encoding.UTF8.GetBytes(dat

a.ToString())

        ' Setup the Request
        Dim request As HttpWebRequest = WebRequest.Create(URL)
        request.PreAuthenticate = True
        request.Method = "POST"
        request.ProtocolVersion = HttpVersion.Version10
        request.ContentType = "application/x-www-form-urlenc

oded;charset=UTF-8"
request.ContentLength = byteArray.Length
request.Credentials = New NetworkCredential(“PjdASDASDASccpVk4iag”,
“KvSDFSDFDSFJl2dKOzaOg”) <---------- HARD CODED TO TEST WHERE ITS GOING
WRONG, ITS THE ‘*OAuth identifier’ *AND OAuth secret VALUES

        ' Write data
        Dim postStream As Stream = request.GetRequestStream()
        postStream.Write(byteArray, 0, byteArray.Length)
        postStream.Close()

        ' Send Request & Get Response
        Response = request.GetResponse()   <------ 401 error

here!!!


You received this message because you are subscribed to the Google
Groups “FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to freeagent_ap...@googlegroups.com.
To post to this group, send email to freeag...@googlegroups.com.

Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.


You received this message because you are subscribed to the Google Groups
“FreeAgent API” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to freeagent_api+unsubscribe@googlegroups.com.
To post to this group, send email to freeagent_api@googlegroups.com.
Visit this group at http://groups.google.com/group/freeagent_api.
For more options, visit https://groups.google.com/groups/opt_out.