I am new to using API’s and having an issue with using the GET.
I am writing my code in VB.net and have got the code working for approving the app and exchanging the auth code for the access token. But when I try to do any GETs such a list invoices or even just display company info, I get a 400 code.
This is my code, a valid access token is being passing into the sub.
I have tried removing the accept and contenttype headers, but to no avail.
Public Sub get_invoices(access_token As String) Dim responsedata As String Dim hwrequest As Net.HttpWebRequest = Net.HttpWebRequest.Create("https://api.sandbox.freeagent.com/v2/company") hwrequest.Accept = "application/json" hwrequest.ContentType = "application/json" hwrequest.Headers.Add("Authorization", "Bearer " & access_token) hwrequest.ContentLength = 0 ' hwrequest.Method = "GET" Try Dim hwresponse As Net.HttpWebResponse = hwrequest.GetResponse() If hwresponse.StatusCode = Net.HttpStatusCode.OK Then Dim responseStream As IO.StreamReader = New IO.StreamReader(hwresponse.GetResponseStream()) responsedata = responseStream.ReadToEnd() End If Catch ex As Exception Console.WriteLine(ex.Message) End Try End Sub
On executing the line:
Dim hwresponse As Net.HttpWebResponse = hwrequest.GetResponse()
I am getting the 400 error.
I have done the same request with google playground and it is working fine.