What is a cURL API call, and what does it look like?

Knowledge Drop

Last tested: Nov 4, 2020
 

cURL is a command-line utility available on most Unix/Linux based operating systems which can be used to make an HTTP network request and receive the response either interactively as you type or in a bash shell script. cURL can make any kind of HTTP requests, configure request headers, and upload data in request bodies for POST, PUT, and PATCH requests. For quick-and-dirty testing or exploration of an HTTP service or REST API, curl is a simple but powerful tool.

As with any use of the Looker API, the first thing you need to do when using cURL is call /login to authenticate and receive an access_token. The access_token can then be used in subsequent calls to the Looker API.

For example, you would do the following (Replacing XXXXX with the appropriate credentials):

curl -d "client_id=XXXXXXXXXX&client_secret=XXXXXXXXX" https://mycompany.looker.com:19999/login

This will return a response that looks something like:

{

"access_token":"4QDkCyCtZzYgj4C2p2cj3csJH7zqS5RzKs2kTnG4",

"token_type":"Bearer",

"expires_in":3600

}

You can then use that access_token to make an API call like add-group_user:

curl -H "Authorization: token 4QDkCyCtZzYgj4C2p2cj3csJH7zqS5RzKs2kTnG4" -H "Content-Type: application/json" -d "{\"user_id\": 1815}" https://mycompany.looker.com:19999/api/3.0/groups/5/users

This cURL command sends an HTTP POST request to the Looker server to assign user id 1815 to group id 5. The -H param sets a header value in the HTTP request. the -d param sets the body or payload of the request and makes the request an HTTP POST. Note that since we are sending JSON data in the body of the request, we must define the content type (application/json) with a Content-Type header. We also need to escape the double quotes in the "-d" param.

If no -d param is used, cURL will send an HTTP GET request. You can also send HTTP DELETE, PUT, and PATCH requests using --request followed by the HTTP method name: --request DELETE

Failure to include the Authorization header with a valid access_token value will cause the Looker server to response with HTTP status 404 Not Found, the standard response for authorization failure.

Other helpful resources:

This content is subject to limited support.                

Comments
naga040399-1658
Observer

Hi, this info is really helpful , I have used the same method.

I got to know that this methods will use production as a default environment. 

can I know, if I want to connect to development environment where can I mention that?

Version history
Last update:
‎05-07-2021 09:00 AM
Updated by: