Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curl -u equivalent in HTTP request

Tags:

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.

like image 742
Matt Brewerton Avatar asked Jan 06 '16 15:01

Matt Brewerton


People also ask

Is curl an HTTP request?

The client, curl, sends an HTTP request. The request contains a method (like GET, POST, HEAD etc), a number of request headers and sometimes a request body. The HTTP server responds with a status line (indicating if things went well), response headers and most often also a response body.

What is the alternative of curl?

Postman, HTTPie, Flurl, FileZilla, and WinSCP are the most popular alternatives and competitors to cURL.

What HTTP method does curl use?

curl knows the HTTP method If you just pass in a HTTP URL like curl http://example.com , curl will use GET. If you use -d or -F curl will use POST, -I will cause a HEAD and -T will make it a PUT.

What is curl in request?

'cURL' is a command-line tool that lets you transmit HTTP requests and receive responses from the command line or a shell script. It is available for Linux distributions, Mac OS X, and Windows. To use cURL to run your REST web API call, use the cURL command syntax to construct the command.


1 Answers

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)

like image 107
Sabuj Hassan Avatar answered Oct 14 '22 13:10

Sabuj Hassan