Connecting to an API

I want to use the API to create tickets in my ticket system. I’m trying the most simple call to get the accounts. According to their docs I need to use the following for authorization:

We support HTTP Basic authentication to access the API. The DoneDone API is only available over SSL, so your credentials are safe.
When making calls to the API, provide your email address and api token via the HTTP Basic authorization header, in the form: Authorization: Basic xxxxxxxxxxxxxxxxxxxxx where xxxxxxxxxxxxxxxxxxxxx is the Base64-encoded string in the form email:apitoken. Your unique API token is available on the “Your Profile > API Key” section of the DoneDone app. You may also use your password in place of the api token, but we don’t recommend this.

What is wrong with my code?

Dim url As String = "https://2.donedone.com/public-api/accounts"
Dim username As String = "email address"
Dim password As String = "API key"

Dim connection As New URLConnection
Dim authorizationHeader As String = "Basic " + EncodeBase64(username + ":" + password)
connection.RequestHeader("Authorization:") = authorizationHeader

Dim result As String = connection.SendSync("GET", url)

I only get “not authorized” back from the url connection.

Try this:
connection.RequestHeader("Authorization") = authorizationHeader

2 Likes

Maybe

Authorization: Basic

Instead of

Basic

Both

connection.RequestHeader("Authorization") = authorizationHeader
and
connection.RequestHeader("Basic") = EncodeBase64(username + ":" + password)

don’t work.

This one is incorrect.

This one I don’t know what’s wrong

Are you sure your server allows “Basic”? Some simply don’t allow it.

This is odd. I tried with EncodeBase64MBS and then I got the correct data back. Then I compared EncodeBase64 and EncodeBase64MBS. The former adds a 0D0A and the MBS version doesn’t. Never seen this before.

What? That’s insane. Can you show simple way to reproduce it?

No 0D0A here

image

Remember the second parameter of EncodeBase64 is when to add line breaks and the default value is not 0.

4 Likes

As Tim said

image

And the fix:

image