25

I've been trying to plug into the Toggl API for a project, and their examples are all using CURL. I'm trying to use the C# wrapper which causes a bad request when trying to create a report, so I thought I'd use Postman to try a simple HTTP request.

I can't seem to get the HTTP request to accept my API Token though. Here's the example that they give (CURL):

curl -u my-secret-toggl-api-token:api_token -X GET "https://www.toggl.com/reports/api/v2/project/?page=1&[email protected]&workspace_id=1&project_id=2"

I've tried the following HTTP request with Postman with a header called api_token with my token as the value:

https://www.toggl.com/reports/api/v2/project/[email protected]&project_id=9001&workspace_id=9001

(changed ids and email of course).

Any help on how to use the CURL -u in HTTP would be appreciated, thanks.

2
  • 5
    Well, in Postman, select Basic Auth, fill Username with my-secret-toggl-api-token, and Password with api_token. Refresh headers and there you go Commented Jan 6, 2016 at 16:19
  • I did this and I believe it's worked! I now get a different error but I think that's down to my permissions in our Toggl Team, thanks. Commented Jan 8, 2016 at 9:37

3 Answers 3

36

The easy way is adding credential into url as user:pass@ format.

https://my-secret-toggl-api-token:[email protected]/reports/api/v2/project/?page=...
        <---------------------------------->

Alternately you can use credential with your http header like below:

Authorization: Basic XXXXXX

Here XXXXXX is base64(my-secret-toggl-api-token:api_token)

Sign up to request clarification or add additional context in comments.

2 Comments

I used the Basic Authorization in Postman and it returns a different error for me, which I now believe is related to my access within Toggl. Thank you for the answer, it helped a lot!
Probably worth noting here that the :api_token part of this is the exact string required, e.g. https://aaa111...bbb222:[email protected]/...
0

As explained to me in another post, you can pass the api token to the user property if you are using HttpWebRequest:

request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes($"my-secret-toggl-api-token:api_token")));

Comments

0

Using fetch

In node environment, your request might look something like so:

const url = 'https://www.toggl.com/reports/api/v2/project/page=1&[email protected]&workspace_id=1&project_id=2';
const token = 'my-secret-toggl-api-token:api_token';

fetch(url, {
  method: 'GET', // not required
  headers: {
    Authorization: `Basic ${Buffer.from(String(token)).toString('base64')}`,
  },
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.