I'm newbie on this so I would like your help, according to CrazyCall docs I want to test those code examples in terminal using CURL, for example this one:
GET /api/v1/users HTTP/1.1
x-api-token: your-secret-api-key
Account: your-account-hash.crazycall.com
Host: api.crazycall.com
I tried to convert to curl and execute like this:
curl -XGET -H 'x-api-token: mdsRFGRV23XXXXXXX' -H 'Account: lopDOPLSVXXXX.crazycall.com' -H 'Host: api.crazycall.com' /api/v1/users
But it shows me a message <url> malformed
I also added "Content-type: application/json" header but it's still the same.
How can I fix it?
Prepand the protocol and domain (https://api.crazycall.com) to your path (/api/v1/users):
curl -X GET -H 'x-api-token: mdsRFGRV23XXXXXXX' -H 'Account: lopDOPLSVXXXX.crazycall.com' -H 'Host: api.crazycall.com' https://api.crazycall.com/api/v1/users
Related
How can I force cURL to send an invalid HTTP header, as follows:
curl -k 'https://192.168.1.1/' -H 'Host: 192.168.1.1' -H 'blah' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.8'
When I try the above, cURL helpfully leaves out the invalid header.
You can, but it's slightly more convoluted than that. curl will check that you use a colon and avoid passed in headers that don't have colons. But you can trick curl's colon check by passing in a header with embedded CRLF that then creates two header lines, and one of them can then be without colon.
For example like this:
curl -H "`printf "Foo: bar\r\nblah"`" -v localhost
(-v of course lets you see the actual request curl uses)
There is a sample in Jira API doc:
curl -D- -X GET -H "Authorization: Basic ZnJlZDpmcmVk" -H "Content-Type: application/json" "http://kelpie9:8081/rest/api/2/issue/QA-31"
What exactly does the -D- parameter mean? There is no description in curl documentation.
I'm also not sure whether -D- and -D mean the same thing.
It dumps headers to stdout.
The -D flag dumps headers to a file, and the following - instructs it to dump to stdout. From the linked spec:
-D, --dump-header
Write the protocol headers to the specified file.
It doesn't specify for this option, but this works like other options that take a filename:
Use "-" as filename to have the output sent to stdout.
I get the error curl: Can't open 'files=#1.txt'! when trying to run code:
curl -v -XPOST -k -H "Accept: application/json" -T "files=#1.txt" https://192.168.1.102/
any suggestion on how to pass the text file's name properly?
-T is for PUT and wants a file name only:
curl -T 1.txt https://192.168.1.102/
You seem to want to POST a file? If you want it sent "plainly", you probably want:
curl -H "Accept: application/json" --data-binary #1.txt https://192.168.1.102/
If you want to instead send the file as a multipart formpost, you might do it similar to:
curl -F files=#1.txt https://192.168.1.102/
I am using the url at the developer-api.nest.com site, and my request is re-directed to the firebase-apiserver01...01.dapi.production.nest.com
I get the correct structured data back, using this dos command:
curl -v -k -L -X GET "https://developer-api.nest.com/structures/Za6hCZpmt4g6mBTaaA96yuY87lzLtsucYjbxW_b_thAuJJ7oUOelKA/?auth=c.om2...AeiE"
I get the error 'Invalid content sent' when I send this PATCH
curl -v -k -L -X PATCH "https://developer-api.nest.com/structures/Za6hCZpmt4g6mBTaaA96yuY87lzLtsucYjbxW_b_thAuJJ7oUOelKA/?auth=c.om2...AeiE" -H "Content-Type: application/json" -d '{"away":"home"}'
I have tried adding '.json' before the question mark, but get the same error.
To set the structure to home/away you'll need to send a PUT request for example as follows:
curl -v -L -X PUT "https://developer-api.nest.com/structures/g-9y-2xkHpBh1MGkVaqXOGJiKOB9MkoW1hhYyQk2vAunCK8a731jbg?auth=<AUTH_TOKEN>" -H "Content-Type: application/json" -d '{"away":"home"}'
Hope that helps
--Nagesh
I am trying to update an object using curl.
There are 2 approaches I am trying:
1] Provide usr/pswd in patch reques
=> says "Warning: You can only select one HTTP request!"
2] Save login cookie first and use it to perform patch
with -I => says "Warning: You can only select one HTTP request!"
without -I => [{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]
Here are the requests:
1] Provide usr/pswd in patch request
curl -I -H "Content-Type: application/json" -H "charset=UTF-8" -H "Accept: application/json" -X PATCH -d '{"field":"new_value"}' -D- 'https://url?un=<uname>&pw=<pwd>/<path to obj>/<key>' --trace-ascii trace.OUT
Warning: You can only select one HTTP request!
2] Save login cookie first and use it to perform patch
curl -c cookies.txt 'https://url?un=<uname>&pw=<pwd>'
curl -b cookies.txt -H "Content-Type: application/json" -H "charset=UTF-8" -H "Accept: application/json" -X PATCH -d '{"field":"new_value"}' -D- 'https://url/<path to obj>/<key>'
=>[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]
curl **-I** cookies.txt -H "Content-Type: application/json" -H "charset=UTF-8" -H "Accept: application/json" -X PATCH -d '{"field":"new_value"}' -D- 'https://url/<path to obj>/<key>'
=> Warning: You can only select one HTTP request!
We have a tool that can perform the patch using a UI and I checked the request/headers in firebug and seems like I have everything in the request. However I want to script this call.
Any suggestions?
Thanks!
"-I" implies a HEAD request, but you specify a HTTP method of "PATCH". Curl complains that it can't do both at the same time.