How to interpret Parse REST API without --data-url-encode? - json

For Prase REST API, we can have
curl -X GET \
-H "X-Parse-Application-Id: Y6i5v9PQOAAGlnKnULJJu5odT72ffSCpOnqqPhx9" \
-H "X-Parse-REST-API-Key: T6STkwY6XqVMySTbqeSZfmli3naZZK9KoxnAcEhR" \
-G \
--data-url-encode 'where={"username":"someUser"}' \
https://api.parse.com/1/users
Now I'm trying to send the request without --data-url-encode, but to append the related query into the URL https://api.parse.com/1/users, what shall I do?
I tried
curl -X GET \
-H "X-Parse-Application-Id: Y6i5v9PQOAAGlnKnULJJu5odT72ffSCpOnqqPhx9" \
-H "X-Parse-REST-API-Key: T6STkwY6XqVMySTbqeSZfmli3naZZK9KoxnAcEhR" \
-G \
https://api.parse.com/1/users?where={"username":"someUser"}
but it doesn't work.
Thank you.

First encode where={"username":"someUser"} to where%3D%7B%22username%22%3A%22someUser%22%7D, then
curl -X GET \
-H "X-Parse-Application-Id: Y6i5v9PQOAAGlnKnULJJu5odT72ffSCpOnqqPhx9" \
-H "X-Parse-REST-API-Key: T6STkwY6XqVMySTbqeSZfmli3naZZK9KoxnAcEhR" \
-G \
https://api.parse.com/1/users?where%3D%7B%22username%22%3A%22someUser%22%7D
works

Related

Passing user name and password dynamically to Curl POST command

trying to pass user name and password dynamically to Curl POST command, but it is throwing errors as unable to Validate user name and password
The command is working fine if the username and password is hardcoded.
Static Command:
curl -i -X POST https://somewebsite.com/service/nonuilogin \
-H 'Accept:application/json' \
-H 'content-type:application/json' \
-H 'host:somewebsite.com' \
-d '{"ping_uname":"serviceaccount","ping_pwd":"acc#123"}'
Dynamic command:
curl -i -X POST https://somewebsite.com/service/nonuilogin \
-H 'Accept:application/json' \
-H 'content-type:application/json' \
-H 'host:somewebsite.com' \
-d '{"ping_uname":"$user_name","ping_pwd":"$password"}'
{
"error": "Unable to log in user. Validate that the username/password are valid",
"translationKey": "FD_AUTH_USER_UNABLE_TO_VALIDATE"
Thanks in Advance

How to send double quotes inside JSON curl request

I want to send this string inside a CURL request from shell script :
"google-site-verification=O_Kd7lqvCvpBz7fzEeUKGVKBmsAsfJgaJuh3PZRnrsk"
To do that I'm using this script :
OVH_HTTP_METHOD="POST"
OVH_HTTP_QUERY="$OVH_API_URL/$OVH_API_END_POINT_DOMAIN_ZONE_DNS/domain.com/$OVH_API_END_POINT_DOMAIN_ZONE_DNS_RECORD"
OVH_FIELD_TYPE="TXT"
OVH_SUB_DOMAIN=""
OVH_TARGET=""google-site-verification=O_Kd7lqvCvpBz7fzEeUKGVKBmsAsfJgaJuh3PZRnrsk""
OVH_HTTP_BODY="{\"fieldType\":\"$OVH_FIELD_TYPE\",\"subDomain\":\"$OVH_SUB_DOMAIN\",\"target\":\"$OVH_TARGET\"}"
curl -X $OVH_HTTP_METHOD \
$OVH_HTTP_QUERY \
-H "Content-Type: application/json" \
-H "X-Ovh-Application: $OVH_API_APPLICATION_KEY" \
-H "X-Ovh-Timestamp: $OVH_TIME" \
-H "X-Ovh-Signature: $OVH_SIG" \
-H "X-Ovh-Consumer: $OVH_API_CONSUMER_KEY" \
--data "$OVH_HTTP_BODY"
But I get systematically this error message :
{"message":"Invalid JSON received","httpCode":"400 Bad Request","errorCode":"INVALID_JSON"}
UPDATE with curl -v :
Do you have any idea to solve that?
Thanks
L.
solution found below : variable has to be escaped like this :
OVH_TARGET="\\\"google-site-verification=O_Kd7lqvCvpBz7fzEeUKGVKBmsAsfJgaJuh3PZRnrsk\\\""

curl command for REST API which takes json input

I want to call REST API by passing json input.
I have following details-
username
apitoken
apiurl
Jsonfile
I have already tried
curl -d #Metadata.json -H "Content-Type: application/json" <> --user xyz:apitoken --insecure
but i m getting null values for all the parameters in the json file.
What am i doing wrong here?
Simple Solution would be to create a sample postman with above details then follow below steps -
Click on the code icon.
Choose cURL from the drop-down.
There’s your cURL command
Sample curl command -
curl -X POST \
https://something.com/endpoint \
-H 'Content-Type: application/json' \
-H 'Postman-Token: 1f0fcc007739' \
-H 'apikey: CSZftBtR0WaN' \
-H 'cache-control: no-cache' \
-d '{
"Id": "5de675",
"xxxxx": "500081"
}'

Forge request fails on postman and curl

Hello i'm trying the introduction to the design automation ofr inventor but i'm stuck on the upload parameters.
this is the article:
https://forge.autodesk.com/blog/simple-introduction-design-automation-inventor
my last curl request:
curl -X POST \
https://dasprod-store.s3.amazonaws.com \
-H 'content-type: application/octet-stream' \
-F key=apps/Hf3jB7SzAGmZnHhBdRFvVHJEaCa7xPzN/ThumbnailBundle/1 \
-F policy=eyJleHBpcmF0aW9uIjoiMjAxOS0wMi0xMlQxNzowNDozMi43NTIxNDc0WiIsImNvbmRpdGlvbnMiOlt7ImtleSI6ImFwcHMvSGYzakI3U3pBR21abkhoQmRSRnZWSEpFYUNhN3hQek4vVGh1bWJuYWlsQnVuZGxlLzEifSx7ImJ1Y2tldCI6ImRhc3Byb2Qtc3RvcmUifSx7InN1Y2Nlc3NfYWN0aW9uX3N0YXR1cyI6IjIwMCJ9LFsic3RhcnRzLXdpdGgiLCIkc3VjY2Vzc19hY3Rpb25fcmVkaXJlY3QiLCIiXSxbInN0YXJ0cy13aXRoIiwiJGNvbnRlbnQtVHlwZSIsImFwcGxpY2F0aW9uL29jdGV0LXN0cmVhbSJdLHsieC1hbXotc2VydmVyLXNpZGUtZW5jcnlwdGlvbiI6IkFFUzI1NiJ9LFsiY29udGVudC1sZW5ndGgtcmFuZ2UiLCIwIiwiMTA0ODU3NjAwIl0seyJ4LWFtei1jcmVkZW50aWFsIjoiQVNJQVRHVkpaS00zQUtFWk9ER0gvMjAxOTAyMTIvdXMtZWFzdC0xL3MzL2F3czRfcmVxdWVzdC8ifSx7IngtYW16LWFsZ29yaXRobSI6IkFXUzQtSE1BQy1TSEEyNTYifSx7IngtYW16LWRhdGUiOiIyMDE5MDIxMlQxNjA0MzJaIn0seyJ4LWFtei1zZWN1cml0eS10b2tlbiI6IkZRb0daWEl2WVhkekVHa2FERS9kN1ZqY09aQWU2UXBrdVNMdkFWeUxPUkJaditZSHhGUGZUZi85THVBMnQ4NlZYYlhYeGhDV2QxZTgzbGNVSnhmSGQ4bjNkRmlzc291dGpIWG5pcGxwcW5rR2l2bXdFK0w1NkJMQ1JCcDRzYnBXVkVVNVFZcEQ0MkE1VC81Nlgvc2Z5UU5WRzFwMlY5VDBpMTZqWS9ybVpWZ2FLeXU2a0Job2duRGlia0dxb2EvK3FDYmZGcklTVEVJNGdYOWtNTC8wS2xZTFZ0endsbTN0MFpMZlV6Wit1cHlBMGhBaEh3aVlkcHk0TWFkTEU0N245Qi91VHpPMUo0cVdiY1dLaXMrbkMvTy96SlhuTnVhZ2JnV3FoK1NuZjJRM2hyaGlWQTQySVVxZG0xZmtoMVhsdHRCOEZrMDU3dnlUaVFsT1FjY21zczh4cEUrbUNHR0FEMFRYS0tuVmkrTUYifV19 \
-F content-type=application/octet-stream \
-F success_action_status=200 \
-F success_action_redirect= \
-F x-amz-signature=2583b27e19fdb5ff23950d6866dc3765c1f1bcd9c9b43d2fb2cbeb252e9e6507 \
-F x-amz-credential=ASIATGVJZKM3AKEZODGH/20190212/us-east-1/s3/aws4_request/ \
-F x-amz-algorithm=AWS4-HMAC-SHA256 \
-F x-amz-date=20190212T160432Z \
-F x-amz-server-side-encryption=AES256 \
-F x-amz-security-token=FQoGZXIvYXdzEGkaDE/d7VjcOZAe6QpkuSLvAVyLORBZv+YHxFPfTf/9LuA2t86VXbXXxhCWd1e83lcUJxfHd8n3dFissoutjHXniplpqnkGivmwE+L56BLCRBp4sbpWVEU5QYpD42A5T/56X/sfyQNVG1p2V9T0i16jY/rmZVgaKyu6kBhognDibkGqoa/+qCbfFrISTEI4gX9kML/0KlYLVtzwlm3t0ZLfUzZ+upyA0hAhHwiYdpy4MadLE47n9B/uTzO1J4qWbcWKis+nC/O/zJXnNuagbgWqh+Snf2Q3hrhiVA42IUqdm1fkh1XlttB8Fk057vyTiQlOQccmss8xpE+mCGGAD0TXKKnVi+MF \
-F file=#/C:\Users\sejjilali\Desktop\InventorForgeAddInServer.zip
From your postman request, it look like you have a space at the end of your x-amz-algorithm form-data value. Try removing it after "AWS4-HMAC-SHA256".
You are using Policy to specify an authorization token, the token needs to be a Header both in your Postman and cURL command "-H 'Authorization: Bearer [token]".
Use -H 'Content-Type: application/x-www-form-urlencoded' instead of the octet-stream.

Extract token from a curl request and use in another shell command

I've started picking up bash scripting and I'm stuck at something I'm trying to wrap my head around.
I have a curl command that outputs a token and I need to use it in the following command:
curl -k 'https://server:port/session' -X POST -H 'Content-Type: application/json' -d '{"username":"admin","password":"password"}'
It then outputs a token here:
{"token":"ac07098ad59ca6f3fccea0e2a2f6cb080df55c9a52fc9d65"}
I then need to use it in the follow up command
curl https://server:port/ -k -X POST -H 'Content-Type: application/json' -H 'X-Cookie:token=token' -d '
I was thinking I could output the token to a file, then have a sed command write the token to a file, then the new command use a variable where token=$token
Thanks!
This is where a JSON parsing tool comes in handy (such as jq):
$ echo '{"token":"ac07098ad59ca6f3fccea0e2a2f6cb080df55c9a52fc9d65"}' | jq -r .token
ac07098ad59ca6f3fccea0e2a2f6cb080df55c9a52fc9d65
So
json=$( curl -k 'https://server:port/session' -X POST -H 'Content-Type: application/json' -d '{"username":"admin","password":"password"}' )
token=$( jq -r ".token" <<<"$json" )
curl https://server:port/ -k -X POST -H "X-Cookie:token=$token" ...
With no further tool than a bash (tested Centos/Rhel7/GitBash) :
json=$(curl -k 'https://server:port/session' \
-X POST -H 'Content-Type: application/json' \
-d '{"username":"admin","password":"password"}') \
&& token=$(echo $json | sed "s/{.*\"token\":\"\([^\"]*\).*}/\1/g") \
&& echo "token = $token"
then use your authentication needing commands like that :
curl https://server:port/ -k -X POST \
-H 'Content-Type: application/json' \
-H 'X-Cookie:token=$token' -d ...'
If Python is installed, and hopefully it is on modern systems, you can do something like:
OUTPUT="$(curl -k 'https://server:port/session' -X POST -H 'Content-Type: application/json' -d '{"username":"admin","password":"password"}' | python -c "import sys, json; print json.load(sys.stdin)['token']")"
This will give you:
echo $OUTPUT
ec2e99a1d294fd4bc0a04da852ecbdeed3b55671c08cc09f
Use the `` syntax:
cmd1result=$(command1 | cut -d ':' -f 2 | grep -Po "[a-z0-9-]+")
command2 $cmd1result