JSON data is invalid - json

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\"}"

Related

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

Convert cURL To Applescript

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\""

Is it possible to tag TeamCity builds using service messages (or some other programatic way)?

Is it possible to tag TeamCity builds using service messages or some other programmatic way from a build step maybe...?
How can this be done?
See also the following stackoverflow discussion:
Programatically pin a build in Teamcity
Moreover, since there were two open questions on stackoverflow and I had the same problem, I wrote a TeamCity plugin that solves it:
https://github.com/echocat/teamcity-buildTagsViaBuildLog-plugin
There is a VCS labelling in TeamCity, you can tag when a build successful, or on each build. Does it correspond to what you're looking for?
Yes, there is. You can use the REST API, as described here. Basically,
Adding a tag using plain text
curl -s --header "Authorization: Bearer $TOKEN" \
-H 'Content-Type: text/plain' \
"https://ci.ACME.com/app/rest/builds/5375/tags --data tag-1
tag-1
Reading the list of tags as json
curl -s -H 'Accept: application/json' \
-H "Authorization: Bearer $TOKEN" \
"https://ci.ACME.com/app/rest/builds/5375/tags"
{"count":1,"tag":[{"name":"tag-1"}]}
Overwriting tags using json, getting it back as xml (the default)
curl -s --header "Authorization: Bearer $TOKEN" \
-H 'Content-Type: application/json' -X PUT \
"https://ci.ACME.com/app/rest/builds/5375/tags \
--data '{"count":2,"tag":[{"name":"tag-A"},{"name":"tag-B"}]}'
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><tags count="2"><tag name="tag-A"/><tag name="tag-B"/></tags>

How to PUT a json object with an array using curl

I have a series of data to enter into database. The user interface to enter the data isn't good for bulk entry, so I'm trying to formulate a command line equivalent. When I examine the network request of the UI in chrome, I see a PUT request of a json object. When I try to replicate the request
curl -H 'Accept: application/json' -X PUT '{"tags":["tag1","tag2"],"question":"Which band?","answers":[{"id":"a0","answer":"Answer1"},{"id":"a1","answer":"answer2"}]}' http://example.com/service`
I get a error
curl: (3) [globbing] nested braces not supported at pos X
Where X is the character position of first "[".
How can I PUT a json object that includes an array?
Your command line should have a -d/--data inserted before the string you want to send in the PUT, and you want to set the Content-Type and not Accept.
curl -H 'Content-Type: application/json' -X PUT -d '[JSON]' \
http://example.com/service
Using the exact JSON data from the question, the full command line would become:
curl -H 'Content-Type: application/json' -X PUT \
-d '{"tags":["tag1","tag2"],
"question":"Which band?",
"answers":[{"id":"a0","answer":"Answer1"},
{"id":"a1","answer":"answer2"}]}' \
http://example.com/service
Note: JSON data wrapped only for readability, not valid for curl request.
Although the original post had other issues (i.e. the missing "-d"), the error message is more generic.
curl: (3) [globbing] nested braces not supported at pos X
This is because curly braces {} and square brackets [] are special globbing characters in curl.
To turn this globbing off, use the "-g" option.
As an example, the following Solr facet query will fail without the "-g" to turn off curl globbing:
curl -g 'http://localhost:8983/solr/query?json.facet={x:{terms:"myfield"}}'
It should be mentioned that the Accept header tells the server something about what we are accepting back, whereas the relevant header in this context is Content-Type
It's often advisable to specify Content-Type as application/json when sending JSON. For curl the syntax is:
-H 'Content-Type: application/json'
So the complete curl command will be:
curl -H 'Content-Type: application/json' -H 'Accept: application/json' -X PUT -d '{"tags":["tag1","tag2"],"question":"Which band?","answers":[{"id":"a0","answer":"Answer1"},{"id":"a1","answer":"answer2"}]}' http://example.com/service`
The only thing that helped is to use a file of JSON instead of json body text. Based on How to send file contents as body entity using cURL
Try using a single quote instead of double quotes along with -g
Following scenario worked for me
curl -g -d '{"collection":[{"NumberOfParcels":1,"Weight":1,"Length":1,"Width":1,"Height":1}]}" -H "Accept: application/json" -H "Content-Type: application/json" --user test#testmail.com:123456 -X POST https://yoururl.com
WITH
curl -g -d "{'collection':[{'NumberOfParcels':1,'Weight':1,'Length':1,'Width':1,'Height':1}]}" -H "Accept: application/json" -H "Content-Type: application/json" --user test#testmail.com:123456 -X POST https://yoururl.com
This especially resolved my error curl command error : bad url colon is first character

POST JSON over CURL with basic authentication

I am using Curl from the command line to debug a small web api I am working on. The web api expects basic authentication and a JSON object as input (POST). Currently this basic authentications works fine:
curl -i --user validuser:70e12a10-83c7-11e0-9d78-0800200c9a65 http://example.com/api.php
but I also want to send a JSON object as a POST request:
curl -i --user validuser:70e12a10-83c7-11e0-9d78-0800200c9a65 -X POST -d '{"person":{"name":"bob"}}' http://example.com/api.php
I'm getting a 400 Bad Request response with the above command, any ideas on how I bundle a json object in this POST request?
Try it with:
curl -i --user validuser:70e12a10-83c7-11e0-9d78-0800200c9a65 -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"person":{"name":"bob"}}' http://mysite.com/api.php
I've removed the json= bit in the body content.
Alternatively, this post might be helpful: How to post JSON to PHP with curl
curl --request POST \
--url http://host/api/content/ \
--header 'authorization: Basic Esdfkjhsdft4934hdfksjdf'
Don't use
$person = file_get_contents("php://input");
instead use
$person = $_POST['person'];
And if you're using curl from the command-line this is the syntax for wanting to POST json data:
curl -d 'person={"name":"bob"}'