What does the "curl: (3) bad range in URL position X" Error in an API call mean?
search cancel

What does the "curl: (3) bad range in URL position X" Error in an API call mean?

book

Article ID: 284341

calendar_today

Updated On:

Products

CloudHealth

Issue/Introduction

While attempting to run a curl command that contains brackets and braces in the URL (such as with our Reporting API with time/date filters), you may run into an error code that looks like:

curl: (3) bad range in URL position X

This is normally due to glob, which uses wildcard characters (such as brackets/braces) to specify sets of filenames.  Therefore, you must escape the characters with a "\", such as:

curl -H 'Authorization: Bearer <your_api_key>' -H 'Accept: application/json' 'https://chapi.cloudhealthtech.com/olap_reports/usage/instance
?dimensions\[\]=time
&dimensions\[\]=AWS-Availaibility-Zones
&measures\[\]=ec2_cost_compute
&filters\[\]=AWS-Availaibility-Zones:reject:us-east-1b,us-east-1d
&interval=monthly'

 Alternatively, you can also use the

-g/--globoff

flag at the beginning of your call, which switches off the URL globbing parser.  Here is an example of how it can be used:

curl --globoff https://www.google.com?test[]=1
curl -g https://www.google.com?test[]=1

Below is more info regarding globoff: 

-g/--globoff

This option switches off the "URL globbing parser".
When you set this option, you can specify URLs that contain the letters {}[]
without having them being interpreted by curlitself. Note that these letters are
not normal legal URL contents but they should be encoded according to the URI standard.