How to pass null as values to any variable in cURL command or Browser command for REST ATG? - rest

First call:
curl -L -v \
-c customer_cookies.txt \
-b customer_cookies.txt \
-H "Content-Type: application/json" \
-d "{\"couponClaimCode\":\"0001\"}" \
"http://localhost:7103/rest/model/atg/commerce/promotion/CouponActor/claimCoupon"
Second call:
http://localhost:7103/rest/model/atg/commerce/promotion/CouponActor/claimCoupon?couponClaimCode=0001
Both calls are doing the same thing: passing coupon code. Suppose if i want to pass null as a value, then how should i do that?

JSON supports null. This
{"couponClaimCode": null}
is valid JSON. If the code that accepts the POST handles JSON correctly, this should work.
Passing a null value of couponClaimCode as a query param depends on what your backend understands. Would
?couponClaimCode=
be interpreted as the empty string "" or as null? What about
?couponClaimCode=null
Is this the string "null" or null? You will have to look into your backend code to find out.

This worked for me
curl -L -v
-c customer_cookies.txt
-b customer_cookies.txt
-H "Content-Type: application/json"
-d "{\"couponClaimCode\":\"\"}"
"http://localhost:7103/rest/model/atg/commerce/promotion/CouponActor/claimCoupon"

Related

curl no URL specified error, even though URL is being specified

I'm attempting to execute the following CURL call via commandline:
curl -i -H "Content-Type:application/json" \
-u "m19389#dev.acp.co.com:qE2P/N7y1k.\(" \
-X GET -d "https://wefd.it.co.com:3905/events/com.co.mpm.dev.29160-wgdhfgd-v1/dsd/dsdfds-0-0-1-7c49768976-2g7kq"
I've added quotes around the arguments and all, and I'm definitely inclusing the curl url, so I'm not sure what's going on here. Where did I go wrong?

MarkLogic ingest JSON from external API

I am using Marklogic 9 and try to ingest data from external source into MarkLogic. I made an REST API on port 8031. When I try to execute the following curl command:
curl --anyauth --user admin:admin -i -X POST -d https://services7.arcgis.com/21GdwfcLrnTpiju8/arcgis/rest/services/Geluidsbelasting/FeatureServer/0/query?where=1%3D1&outFields=*&outSR=4326&f=json
-H "Content-type: application/json" -H "Accept: application/json" \
'http://localhost:8031
After executing this statement I receive the error:
Curl: URL is not specified
Can you please help me out!
Many thanks
Erik
Your -d parameter has special characters that are not escaped. Try putting quotes around your -d url. It will prevent your command from getting truncated and misinterpreted at & signs..
HTH!

How to send a curl request to timekit.io API

I am trying to follow the documentation from timekit.io. I am attempting to do something as simple as send a curl request to do basic authentication as seen in this section of the docs. I have replaced the Timekit-App:name-of-app with the name of my app which I found in the app-settings of my timekit account. I also replaced the email & password with the one's I use to login into my account.
I simply copied and pasted the curl command as is into my terminal and I get a response that says {"error":"Content-type should be json!"} I am not sure if I am not supposed to copy and paste it as is, or what I may be doing wrong, but my understanding is I am supposed to get a json response with a email and a api token among some other data.
Here is my curl command.
curl -X POST \
-H 'Timekit-App: jl-fit' \
-d '{
"email": "email#email.com",
"password": "password"
}' \
https://api.timekit.io/v2/auth
Looks like you have discovered a bug in their docs/examples.
The API you're connecting to expects JSON content type, but curl by default (for POSTing data) uses application/x-www-form-urlencoded. You can fix it by adding the header field explicitly with: -H 'Content-Type: application/json'.
Also, when you use the -d/--data option, method defaults to POST, so it doesn't have to be specified explicitly.
All put together, this should work:
curl \
-H 'Content-Type: application/json' \
-H 'Timekit-App: jl-fit' \
-d '{"email": "email#email.com", "password": "password"}' \
"https://api.timekit.io/v2/auth"
When having multiple arguments, it can be convenient to keep them in an array (no need to escape newlines). For example:
args=(
-H 'Content-Type: application/json'
-H 'Timekit-App: jl-fit'
-d '{"email": "email#email.com", "password": "password"}'
"https://api.timekit.io/v2/auth"
)
curl "${args[#]}"

curl calling REST API response into a file

I am using curl to call a REST API. The REST call returns a file mar21.tar.gz
But the format of the file is data but it has to be in gzip format for me to run tar -xvf on it.
How can I get the file to save in the original format in which it is returned.
curl -u #{user}:#{password} -k -i -H "Content-type: application/json" -o #{tmp_dir}/#{filename} -X GET #{url}
Try this:
curl -u #{user}:#{password} -k -i -H "Content-type: application/json" -o #{tmp_dir}/#{filename} -X GET #{url} > mar21.tar.gz

Calling an PingAccess APIs from Powershell

I am trying to call PingAccess APIs to configure my PingAccess.
I am new to using APIs to do this, and have a question.
I am trying to use CURL to the API .
curl -k -u Administrator:dummypsswd -H "X-Xsrf-Header: PingAccess" -H "Content-Type: application/json" -d '{"alias":"PLACEHOLDER_STAR_MINGLE","fileData": [[System.IO.File]::ReadAllBytes("C:\test.pfx")],"password": "1234"}' https://localhost:9000/pa-admin-api/v1/keyPairs/import -v
When I run this I get the following error.
I still dont know why am I unauthorized. Any help is appreciated.
When you have special characters in your password you'll need to enclose the username/password tuple in double quotes:
curl -k -u "Administrator:dummypsswdwithspecialcharslike&&" -H "X-Xsrf-Header: PingAccess" -H "Content-Type: application/json" -d '{"alias":"PLACEHOLDER_STAR_MINGLE","fileData": [[System.IO.File]::ReadAllBytes("C:\test.pfx")],"password": "1234"}' https://localhost:9000/pa-admin-api/v1/keyPairs/import -v