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.
Related
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
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've got a curl request which looks like:
curl -s http://someurl1.com -H 'Accept: application/json' -u 'emv:LgKrAVkFf2c6mr4DFBQUdjBK' -d grant_type='password' -d scope='offline_access' -d username='datafiles#random.com' -d password='456Qwer()' -d acr_values='tenant:sdfdfsdf-e5e7-42d5-9881-sdfsdf' | python -m json.tool
How can I construct a simple HTTP request from it? I've tried to import it with postman but got Error while importing Curl: Zero or Multiple option-less arguments. Only one is supported (the URL)
curl http://someurl1.com -H 'Accept: application/json' -u 'emv:LgKrAVkFf2c6mr4DFBQUdjBK' -d grant_type='password' -d scope='offline_access' -d username='datafiles#random.com' -d password='456Qwer()' -d acr_values='tenant:sdfdfsdf-e5e7-42d5-9881-sdfsdf'
this string can be imported by Postman.
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