There are multiple reasons why your API request in general might not be working, but in this FAQ we’re going to assume that your API request already works somewhere else (such as in Postman), and you are having trouble getting that request to work via a cURL request specifically.
Let’s say that you are trying to use the example on the Blue Triangle API Overview documentation page (https://help-uji.aternity.com/hc/en-us/articles/15843275555859-The-Blue-Triangle-API-Overview). The example cURL request given there is:
curl -X GET \
'https://api.bluetriangletech.com/content-security-policies?prefix=demosports' \
-H 'X-API-Email:artificial_user@bluetriangle.com' \
-H 'X-API-Key: 4598b7a1dd50023bedd44c83c792d051'
*Please note, you will need to replace the X-API-Email and X-API-Key headers with your own. There is a separate FAQ regarding how to find your API email and key.
The example cURL requests given in most of the API documentation pages are written for Linux. If you are on a Windows device, you will likely have to make a few changes to the example cURL requests. If you try to run the request above on a Windows device, the response might say “curl: (6) Could not resolve host: \”. To resolve this, you need to modify the syntax for multi-line input (in the Windows command prompt, multi-line input is denoted with ^ instead of \). Here’s that change:
curl -X GET ^
'https://api.bluetriangletech.com/content-security-policies?prefix=demosports' ^
-H 'X-API-Email: artificial_user@bluetriangle.com' ^
-H 'X-API-Key: 4598b7a1dd50023bedd44c83c792d051'
If you run that in the Windows command prompt, the response might look like:
curl: (3) URL using bad/illegal format or missing URL
curl: (6) Could not resolve host: bluetriangle.com'
curl: (6) Could not resolve host: 4598b7a1dd50023bedd44c83c792d051'
This is because the Windows command prompt treats single quote characters (‘) differently than Linux. You should replace the single quotes with double quotes like this:
curl -X GET ^
“https://api.bluetriangletech.com/content-security-policies?prefix=demosports” ^
-H “X-API-Email: artificial_user@bluetriangle.com” ^
-H “X-API-Key: 4598b7a1dd50023bedd44c83c792d051”
Those are two of the biggest changes that you need to make to the example cURL requests in the documentation to get them to work in the Windows command prompt.
However, what if your API request uses a JSON request body? Let’s look at the example in the Performance Endpoint documentation:
curl -X POST https://api.bluetriangletech.com/performance \
-H "X-API-Email: email@company.com" \
-H "X-API-Key: 2831ac6dffec75a48fe712345e000481" \
-H "Content-Type: application/json" \
--data '{"site":"demosports","start":"1477972800","end":"1479877200","limit":100,"page":1,"dataColumns":["onload","dns","tcp"],"group":["time"]}'
Making both of the changes recommended above changes the request to this:
curl -X POST https://api.bluetriangletech.com/performance ^
-H "X-API-Email: email@company.com" ^
-H "X-API-Key: 2831ac6dffec75a48fe712345e000481" ^
-H "Content-Type: application/json" ^
--data “{"site":"demosports","start":"1477972800","end":"1479877200","limit":100,"page":1,"dataColumns":["onload","dns","tcp"],"group":["time"]}”
If you try that request, you might get a response like this:
{
"status": 0,
"error_code": 400,
"message": "An invalid value was specified for one of the query parameters.",
"details": "Missing site identifier."
}
But we already know that the site identifier is correct, because it worked in the previous request. In this case, the API isn’t properly receiving the “site” parameter (or any of the other parameters), because the double quotes need to be escaped. There are multiple ways to escape the double quotes, but here is one example:
curl -X POST https://api.bluetriangletech.com/performance ^
-H "X-API-Email: artificial_user@bluetriangle.com" ^
-H "X-API-Key: 4598b7a1dd50023bedd44c83c792d051" ^
-H "Content-Type: application/json" ^
-d "{\"site\":\"demosports\",\"start\":\"1477972800\",\"end\":\"14798
77200\",\"limit\":100,\"page\":1,\"dataColumns\":[\"onload\",\"dns\",\"tcp\"],\"group\":[\"time\"]}
*Pro tip, individually escaping each double quote within the request JSON can be quite tedious. We’d recommend pasting your request JSON in a file (named test.json, for example) and then referencing that file in the cURL request (you will need to run the cURL command from the same directory as the JSON file, or specify the full path to the file). Here is an example of that:
curl -X POST https://api.bluetriangletech.com/performance ^
-H "X-API-Email: artificial_user@bluetriangle.com" ^
-H "X-API-Key: 4598b7a1dd50023bedd44c83c792d051" ^
-H "Content-Type: application/json" ^
-d @test.json
Here are the contents of test.json for this example (it starts and ends with the {}, not with “{}”):
{"site":"demosports","start":"1477972800","end":"1479877200","limit":100,"page":1,"dataColumns":["onload","dns","tcp"],"group":["time"]}