0

I can't seem to get this simple curl API command to work. The original sample code is in HTML/Javascript. The I ran the code using Chrome and used developer tools to record the session. The html/js example worked fine. I copied the chrome network request URL and inserted it into the curl command with no luck. Here is what Chrome "More tools--> Developer tools --> Network --> Headers" gave me,

Request URL:https://api.betterdoctor.com/2016-03-01/doctors?location=37.773,-122.413,100&skip=2&limit=10&user_key=CODE_SAMPLES_KEY_9d3608187
Request Method:GET
Status Code:200 OK
Remote Address:52.9.169.107:443
Referrer Policy:no-referrer-when-downgrade

I tried to the following curl command and just cut and pasted the chrome results,

curl -k -H "Content-Type:application/json" -X GET https://api.betterdoctor.com/2016-03-01/doctors?location=37.773,-122.413,100&skip=2&limit=10&user_key=CODE_SAMPLES_KEY_9d3608187

I get the following error message,

{"meta":{"error":true,"message":"Missing user_key","error_code":1000,"http_status_code":401}}'skip' is not recognized as an internal or external command,
operable program or batch file.
'limit' is not recognized as an internal or external command,
operable program or batch file.
'user_key' is not recognized as an internal or external command,
operable program or batch file.

Any ideas what I might be doing wrong?

1
  • Try wrapping the URL in quotes curl -k -H "Content-Type:application/json" -X GET "https://api.betterdoctor.com/2016-03-01/doctors?location=37.773,-122.413,100&skip=2&limit=10&user_key=CODE_SAMPLES_KEY_9d3608187" Commented Jul 31, 2017 at 17:53

1 Answer 1

1

In man bash, you'll find the following paragraph:

If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0. Commands separated by a ; are executed sequentially; the shell waits for each command to terminate in turn. The return status is the exit status of the last command executed.

To avoid bash interpreting this operator, you should put quotes around your URL to make it a string literal:

curl -k -H "Content-Type:application/json" -X GET "https://api.betterdoctor.com/2016-03-01/doctors?location=37.773,-122.413,100&skip=2&limit=10&user_key=CODE_SAMPLES_KEY_9d3608187"
Sign up to request clarification or add additional context in comments.

1 Comment

You are correct! I placed quotes around the https and it worked perfectly. Good explanation...

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.