Failed to read body as a JSON Object on curl command - json

I am testing out push notifications for iOS Development and am currently using Pusher. When I run this command in terminal
curl -H "Content-Type:application/json" -H "Authorization: Bearer 7FF3763C208E26F2198CE44624E9486B1EC8B02A489DCF2F476FD511763887AE" -X POST 'https://d3ca6e4b-3222-49c9-8028-f9c2d28b3ad7.pushnotifications.pusher.com/publish_api/v1/instances/d3ca6e4b-3222-49c9-8028-f9c2d28b3ad7/publishes' -d#publish-body.json
It gives me this warning
Warning: Couldn't read data from file "publish-body.json", this makes an empty
Warning: POST.
{"error":"Bad Request","description":"Failed to read body as a JSON
object"}
Here is my JSON file
{
"interests": [
"Reminder"
],
"apns": {
"aps": {
"alert": {
"title": "Hello",
"body": "Hello, world!"
}
}
}
}
I tried going to the Pusher API and all it told me is that the error is due to a bad request. Any ideas on how to fix this? This app is a gift for my girlfriend and I would love to have this working!

Related

autodesk translate to svf failed

I was following the steps from this tutorial to convert a file to svf format in order to be able to view it using the autodesk viewer.
https://forge.autodesk.com/en/docs/model-derivative/v2/tutorials/prep-file4viewer/
I was trying to convert a dwg file to svf. I got to task 3 step 1 with no problem, but in step 2, when I make the request, I get the following response :
{"urn":"dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6YnVja2V0MTJzL3Zpc3VhbGl6YXRpb25fLV9hZXJpYWwuZHdn",
"derivatives":[{"hasThumbnail":"false","name":"visualization_-_aerial.dwg","progress":"complete",
"messages":[{"type":"error","code":"AutoCAD-InvalidFile",
"message":"Sorry, the drawing file is invalid and cannot be viewed.
\n- Please try to recover the file in AutoCAD, and upload it again to view."},
{"type":"error","message":"Unrecoverable exit code from extractor: -1073741831",
"code":"TranslationWorker-InternalFailure"}],
"outputType":"svf","status":"failed"}],
"hasThumbnail":"false","progress":"complete","type":"manifest","region":"US","version":"1.0",
"status":"failed"}
I tried to view the file using their online viewer and was able to view it perfectly so I know that there's nothing wrong with the file. What could be the possible reason for this error?
Edit :
After I obtained access token and created bucket, I used this request to upload file to the bucket (Step 2 of Task 2) :
curl -X PUT -v 'https://developer.api.autodesk.com/oss/v2/buckets/{bucketname}/objects/visualization_-_aerial.dwg' -H 'Authorization: Bearer {TOKEN}' -H 'Accept-Encoding: gzip, deflate' --data-binary '{PATH_TO_FILE}/visualization_-_aerial.dwg'
The response to this is 200OK.
Then I used the online tool given in the tutorial to convert urn to base 64 encoded urn.
Here's the job post request (Step 1 of task 3) I sent :
curl -X POST 'https://developer.api.autodesk.com/modelderivative/v2/designdata/job' -H 'Authorization: Bearer {TOKEN}' -H 'x-ads-force: true' -H 'Content-Type: application/json' -d '{ "input": { "urn": "{URN}", "compressedUrn": true, "rootFilename": "visualization_-_aerial.dwg" }, "output": { "destination": { "region": "us" }, "formats": [{ "type": "svf", "views": ["2d", "3d"], "advanced": {"generateMasterViews": true} } ] } }'
the response to this is "success"
and the get request to check the status of the translation :
curl -X GET 'https://developer.api.autodesk.com/modelderivative/v2/designdata/{URN}/manifest' -H 'Authorization: Bearer {TOKEN}'
the response to this is what I included above.
The file is actually uploaded to the bucket and I was able to view it at https://oss-manager.autodesk.io/# but even there, it shows translation failed.
Edit 2:
Here's an image of the response from https://oss-manager.autodesk.io/ get manifest request (used dev tools to get this)
enter image description here
Based on the comments added to the previous answer it seems like the issue is with the upload part. As you can see in the tutorial it's using
--data-binary '#PATH_TO_DOWNLOADED_ZIP_FILE'
The # symbol is important, without it you'll get a reply like this
{
"bucketKey" : "adam",
"objectId" : "urn:adsk.objects:os.object:adam/test.dwg",
"objectKey" : "test.dwg",
"sha1" : "cb54c0750e9201bbfa6da6adad6b496bec11a111",
"size" : 27,
"contentType" : "application/x-www-form-urlencoded",
"location" : "https://developer.api.autodesk.com/oss/v2/buckets/adam/objects/test.dwg"
* Connection #0 to host developer.api.autodesk.com left intact
}
Look at the size: 27 - that's definitely not right. And so when I try to translate the file I get the same error messages that you got.
However, if I add the # symbol then all is good:
curl -X PUT -v 'https://developer.api.autodesk.com/oss/v2/buckets/{bucketname}/objects/test.dwg' -H 'Authorization: Bearer {TOKEN}' -H 'Accept-Encoding: gzip, deflate' --data-binary '#/Users/nagyad/Downloads/test.dwg'
Note: I'm on a Mac, on Windows the path will look a bit different
Reply I got this time:
{
"bucketKey" : "adam",
"objectId" : "urn:adsk.objects:os.object:adam/test.dwg",
"objectKey" : "test.dwg",
"sha1" : "d17e9156c948caed3a98788836e6c1f3d5fddadc",
"size" : 55727,
"contentType" : "application/x-www-form-urlencoded",
"location" : "https://developer.api.autodesk.com/oss/v2/buckets/adam/objects/test.dwg"
* Connection #0 to host developer.api.autodesk.com left intact
}
And this time when I tried to translate the file, it succeeded.
Change the compressedUrn to false if you working with single file or if you working with zip file so, set to true also mention rootFilename file name(root file name) in response body.

Always getting "Not found" message when using mapbox datasets api

When making a request to the MapBox API to create a new dataset we keep getting a response 404 {
"name": "foo",
"description": "bar"
}.
We are sending the code:
curl -X POST “https://api.mapbox.com/datasets/v1/username?access_token=TOKEN” \
-d #mapboxtest.json \
--header “Content-Type:application/json
Problem Solved!!!
It's just a wierd message. My token key is not allowed to change datasets, that was the problem. It was the default public key!

How to use Google Natural Language processing from Google Cloud Storage?

I have a sample code here. It is json
{
"document":{
"type":"PLAIN_TEXT",
"content":"Joanne Rowling, who writes under the pen names J. K. Rowling and Robert Galbraith, is a British novelist and screenwriter who wrote the Harry Pott$
},
"encodingType":"UTF8"
}
I found a tutorial on google's documentation on Natural Language processing on reading from Google Cloud Storage.
curl -X POST \ -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \ --data "{
'document':{
'type':'PLAIN_TEXT',
'gcsContentUri':'gs://reubucket/textData'
}
}" "https://language.googleapis.com/v1/documents:analyzeEntitySentiment"
And the error that I got is
ERROR: (gcloud.auth) Invalid choice: '*************-_m6csS1Wzlj1pyC_J7vzC0'.
Usage: gcloud auth [optional flags] <group | command>
group may be application-default
command may be activate-service-account | configure-docker | list |
login | revoke
How do I call the command with my API key.
I need a way to change the "content" to entries into my CSV file.
Thank you.
Here is an example of the error that I am receiving please help:
mufaroshumba#reucybertextmining:~/myFolder$ gcloud auth activate-service-account --key-file="/home/mufaroshumba/myFolder/reucybertextmining-74fa66372251.json"
Activated service account credentials for: [starting-*******[CENSORED]#reucybertextmining.iam.gserviceaccount.com]
mufaroshumba#reucybertextmining:~/myFolder$ curl "https://language.googleapis.com/v1/documents:analyzeSentiment?key=${API_KEY}" \ -s -X POST -H "Content-Type: app
lication/json" --data-binary #request.json
{
"error": {
"code": 401,
"message": "Permission to access the GCS address is denied.",
"status": "UNAUTHENTICATED",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "document.gcs_content_uri",
"description": "Permission to access the GCS address is denied."
}
]
}
]
}
}
curl: (6) Could not resolve host: -s
mufaroshumba#reucybertextmining:~/myFolder$
I then used this website trying to get
It looks like your auth is not setup correctly. If you just run this command:
gcloud auth application-default print-access-token
it should be giving you a token, but it seems like it's not. Please follow the steps here to make sure that this command is working first:
https://cloud.google.com/natural-language/docs/quickstart#quickstart-analyze-entities-cli
Then, as long as you have permission to access the gcs bucket, you should be able to get content out of it. Note that the API is expecting to see the actual content in the gcs file, and not a CSV.

read Local audio file STT Google speech-to-text

I don't find how to send a local file using the Google STT in curl command line.
As followed in their tuto, here my request.json :
{
"config": {
"encoding":"FLAC",
"sample_rate": 16000,
"language_code": "fr-FR"
},
"audio": {
"uri":"audio-file.flac"
}
}
my command line is:
curl -s -X POST -H "Content-Type: application/json" --data-binary #request.json "https://speech.googleapis.com/v1beta1/speech:syncrecognize?key=MY_API_KEY"
But I receive the error result:
{
"error": {
"code": 400,
"message": "RecognitionAudio not set.",
"status": "INVALID_ARGUMENT"
}
}
How can I write the request.json to send a local audio file ??
Thanks for help
:)
You need to use the base64 in the content section of the request.json file. It should look something like this except with a lot more base64 data:
{
'config': {
"encoding":"FLAC",
"sample_rate": 16000,
"language_code": "fr-FR"
},
'audio': {
'content':'UklGRuRDFQBXQVZFZm10IBAAAAABAAEAQB8AAIA+AAACABAAZGF0YcBDFQAIAAgACAAIAAgA
CAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgA
CAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgA
CAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAD4/wgACAD4//j/+P8IAPj/+P8IAAgA
+P8IAAgACAAIAAgA+
'
}
}
Google doesn't provide an option to specify local file path in json object while using curl command.We are require to convert audio file into base64 and pass the output into json object
base64 source_audio_file -w 0 > dest_base64_audio_file_content
Alternatively one of the best approach to pass localfile is to use gcloud ml command.
gcloud ml speech recognize 'Clip48_Mike.wav' --language-code='en-US'
Example:
NOTE:
Following command to activate gcloud account if not already done.
gcloud auth activate-service-account --key-file /tmp/account-name.json

Curl - POST request using JSON with query parameter

I have a URL https://mylink/apply?data= for a server which accepts the data variable as valid JSON of following properties:-
name: String with your name (required)
email: String with your email address (required)
urls: Array of strings with links
comment: String with any comment/request you might have (optional)
My JSON file "data.json" is the following:
{
"data":
{
"name": "Rogers Bell",
"email": "xxxx#gmail.com",
"urls":["https://stackoverflow.com/users/3067241/imran", "https://github.com/i4ali"],
"comment":"none"
}
}
When I use the following CURL command to send a POST request, I get error code 400 Bad Request with a message from the server Error: no data passed. indicating something wrong with my JSON format or command. Not sure what I am doing wrong here
curl -v -i -X POST -d #data.json https://mylink/apply?data= -H "Accept: application/json" -H "Content-Type: application/json" -k
I am using Windows 7 if that matters
The API is pretty weird. But if you have to read JSON file and POST its content to server as URL parameter, you can cat the file, encode it and send it in curl. Here is an example:
curl -G -X POST https://requestb.in/1n88lah1 --data-urlencode data="$(cat input.json)"
The input.json would look like:
{
"name": "Rogers Bell",
"email": "xxxx#gmail.com",
"urls":["https://stackoverflow.com/users/3067241/imran", "https://github.com/i4ali"],
"comment":"none"
}
Using Postman I was able to send this POST request with the following complete URL. Got a 200 OK response
https://mylink/apply?data={
"name": "Rogers Bell",
"email": "xxxx#gmail.com",
"urls":["https://stackoverflow.com/users/3067241/imran", "https://github.com/i4ali"],
"comment":"none"
}