Convert cURL To Applescript - json

I am trying to convert a cURL command to AppleScript Using "do shell script".
I've used various hints from previous posts but I'm still running into errors.
Can anyone point out errors in my syntax.
The below script works fine when run in terminal.
curl -X POST https://content.dropboxapi.com/2/files/upload \
--header 'Authorization: Bearer MYTOKEN' \
--header 'Content-Type: application/octet-stream' \
--header 'Dropbox-API-Arg: {"path":"/RoomVT/Clown2.jpeg"}'
--data-binary #"/Splash.jpeg"
I then adapt as.
--Add do shell script Command--
--Place The cURL Inside Double Quotes--
--Replace Double Quotes With Single Quotes--
--Remove Backslashes At End Of Lines--
--You May Also Need To Place All In A Single Line--
do shell script "curl -X POST https://content.dropboxapi.com/2/files/upload --header 'Authorization: Bearer MYTOKEN' --header 'Content-Type: application/octet-stream' --header 'Dropbox-API-Arg: {'path':'/RoomVT/Clown2.jpeg'}' --data-binary #'/Splash.jpeg'"
I still get the error.
"Error in call to API function \"files/upload\": HTTP header \"Dropbox-API-Arg\": could not decode input as JSON"

Thanks for your comments.
I went with #RobC suggestion and it worked first time.
do shell script "curl -X POST https://content.dropboxapi.com/2/files/upload --header 'Authorization: Bearer b4Itg9wetFIAAAAAAAAD7PPkCmoIE2oXvkx_-nq1L2D5G7Bfla-5LHKHtJqoeBMc' --header 'Content-Type: application/octet-stream' --header 'Dropbox-API-Arg: {\"path\":\"/EngineRoomVT/Clown2.jpeg\"}' --data-binary #\"/Splash.jpeg\""

Related

How to return the full view of the data while using rest api

There is POST here which is calling a rest API to fetch the data.
Below is Just the Short code using rest API Call to fetch the data using /rest/resource-alerts, but it only displays max 500 Critical alerts not all. Below is the Code I'm using:
sessionID=$(curl -k -H "accept: application/json" -H "content-type: application/json" -H "x-api-version: 120" -d '{"userName":"administrator","password":"123456"}' -X POST https://synergy.ksg.com/rest/login-sessions | jq -r ".sessionID")
# cUrl command with header and payload information to ftech the Data using API call
CMD=$(curl -k -H 'accept: application/json' \
-H 'content-type: text/csv' \
-H 'x-api-version: 2' \
-H "auth: $sessionID" \
-X
GET https://synergy.ksg.com/rest/resource-alerts)
echo "$CMD"
However, while today going via API DOC I see the Query Parameters , The section says about the count, does anyone know how to get the full list of messages?
Below is the

IBM QRadar search event using APIs

I wanted to know if it is possible to search for an Event using IBM QRadar APIs. please find the screenshot below as an example.
in the above, image when we hit the search button, we will get over events which contain text in the text bar. I want to do the same thing with the help of API. please help.
I found the answer to my question-
to fetch the payload or Event information via QRadar APIs first use the search API to get the search ID
curl --location --request POST 'https://qradar-2.as.local/api/ariel/searches?query_expression=select%20payload%20from%20events%20WHERE%20UTF8%28payload%29%20ILIKE%20%27%25xyz-xyzzyx-07.xy.as.local-51995-596966-1%25%27%20START%20%272020-08-21%2004%3A00%27%20STOP%20%272020-08-21%2006%3A00%27%20' \
--header 'Version: 12.0' \
--header 'Accept: application/json' \
--header 'SEC: {{your token here}}' \
--header 'Cookie: JSESSIONID=F988AE8612EDF61A67249876B783CEA7'
then use this search ID in the API below
curl --location --request GET 'https://qradar-2.as.local/api/ariel/searches/{{search_id}}/results' \
--header 'Range: items=0-49' \
--header 'Version: 12.0' \
--header 'Accept: application/json' \
--header 'SEC: {{your token here}}' \
--header 'Cookie: JSESSIONID=E6568B30B3615UUIUD5672AB56578F9E66'
now the response of this API will be base64 encoded so you visit any site to decode.
eg. https://www.base64decode.org/
hope this will help people

JSON data is invalid

I am trying to cURL an API for speech transcription, but am getting the error JSON data is invalid. It is very likely that this is an API specific error, however, I was wondering whether it was an issue with my cURL command.
curl --request POST --url "https://api.assemblyai.com/transcript" \
--header "authorization: abc123" --data \
"{audio_src_url: https://s3-us-west-2.amazonaws.com/blog.assemblyai.com/audio/8-7-2018-post/7510.mp3}"
The documentation is the first example at this link and I am using Windows cmd.
You need double quotes around the keys and the values.
curl --request POST --url "https://api.assemblyai.com/transcript" \
--header "authorization: abc123" --data \
"{\"audio_src_url\": \"https://s3-us-west-2.amazonaws.com/blog.assemblyai.com/audio/8-7-2018-post/7510.mp3\"}"

How to use curl command with data from a variable

I'm trying to make a script that execute a curl command to create a Rabbit Exchange with Rest API.
If I use --data with the definition like the follow:
HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -u $USR:$PWD --header "Content-Type: application/json" --request PUT --data '{"type": "topic","auto_delete": false,"durable": true,"internal": false,"arguments": {}}' $URL_GENERATE_EXCHANGE)
It runs
But I want to pass the data from a variable like this
EXCHANGE_DEFINITION='{"type": "topic","auto_delete": false,"durable": true,"internal": false,"arguments": {}}'
HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -u $USR:$PWD --header "Content-Type: application/json" --request PUT --data $EXCHANGE_DEFINITION $URL_GENERATE_EXCHANGE)
but It doesn't work...and I don't understand why....Can anyone help me please?
Thank you

Elasticsearch API insert data from path

The following cURL command is working:
curl -XPOST http://localhost:9200/test/test -d '{"name":"John", "age":31}' -H 'Content-Type: application/json'
However, when I execute the following command:
curl -XPOST http://localhost:9200/test/test -d '/mnt/c/path/to/filename/test.json' -H 'Content-Type: application/json'
I receive the following error:
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse"}],"type":"mapper_parsing_exception","reason":"failed to parse","caused_by":{"type":"not_x_content_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"}},"status":400}
This is kind of weird since the content of this 'test.json' is exactly the same as in the first command. Namely: A compressed version of: '{"name":"John", "age":31}'.
When sending a file you need to use the --data-binary flag instead of -d:
curl -XPOST http://localhost:9200/test/test --data-binary #'/mnt/c/path/to/filename/test.json' -H 'Content-Type: application/json'