Curl commands fails when data is send from file - json

Hi I am sending the data through json file and sending that in curl command using the following command and I am getting following error
curl -k https://localhost:25678/api-name -H "Content-Type:application/json" -X POST --data #test.json
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>
The contents of my file is like this
"{'secret': 'toMwVie86l8qlYG2dEiEmZQldZhiAYW6UDwXRkLLRR3qtoONwsSqhd5fPctTQzGSnlSpZPwb4MheUnLQ4z4wyrCd6jDQb3wqfqE3lDnrNpiQhfEU0qVKdBIDIbIck3WmhRqN9YXNEy/XSnsla6ZAUid5RkAZLOx8Lvg91NmgSog='}"
Could someone please help me if I am doing something wrong

Related

Redis Json parsing error in Ubuntu 16.04

I wanted to implement the recommender system from https://github.com/groveco/content-engine
(Look at web.py in that github, I've followed Readme steps)
But the Redis server has some problem and throws up JSON parse error. I've added the screenshots below
Redis server is set up
JSON parse error
Your curl request has the problem. It has a quotation issue:
try using: '{"data-url": "sample-data.csv"}'
curl -X GET -H "X-API-TOKEN: FOOBAR1" -H "Content-Type: application/json; charset=utf-8" http://127.0.0.1:5000/train -d '{"data-url": "sample-data.csv"}'
mind the single quote ' vs double quote "

Syntax of the JSON body in CURL call to a REST API

When I try to send a curl req from terminal on OSX as:
curl --anyauth --user usr:pwd -X PUT -d ‘{"events":{"event":"Database Replicate"}}’ -i -H "Content-type: application/json" URL
it gives me below error:
{"errorResponse":{"statusCode":"400", "status":"Bad Request", "messageCode":"XDMP-JSONDOC", "message":"XDMP-JSONDOC: xdmp:unquote(\"‘{events:{event:Database Replicate}}’\", (), \"format-json\") -- Document is not JSON"}}
I tried to escape the quotes, ensured its UTF-8, still doesn't work. When I simply save it in a file and then attach as -d#filename.json to the CURL req, it just works.
Any idea if I am missing something? Thanks in advance.
Typing the request directly on terminal solved the issue. Do not trust on any 3rd party app when it comes to encoding.

Error "invalid json" in inserting document in Couchdb through command line

I am getting any "error: bad request,invalid json" while running
curl -X PUT "http://localhost:5984/test" -d '{"valid":"json"}'
what to do for inserting document in database test through command line???
When doing a PUT the _id of the document should be provided in the URL. So e.g.:
curl -X PUT "http://localhost:5984/test/my-id" -d '{"valid":"json"}'
If you want Couch to generate the id, use a POST instead.

Invalid cartridge specified with exit_code 109

i want to create app with REST API Openshift i do this curl Command with smarterclayton cartridge :
curl -k -X POST https://openshift.redhat.com/broker/rest/domains/jhaopenshift/applications
--user "user#gmail.com:passwd"
--data "name=myapp&cartridge=https://github.com/smarterclayton/openshift-cdk-cart/blob/master/metadata/manifest.yml&scale=false"
but i still have and Invalid Cartridge error :
{
"api_version":1.6,
"data":null,
"messages":[{"exit_code":109,
"field":"cartridge",
"index":null,
"severity":"error",
"text":"Invalid cartridge 'https://github.com/smarterclayton/openshift-cdk-cart/blob/master/metadata/manifest.yml' specified."}],
"status":"unprocessable_entity",
"supported_api_versions":[1.0,1.1,1.2,1.3,1.4,1.5,1.6],
"type":null,"version":"1.6"
}
and with -H 'Accept: application/xml' option i get this :
curl: (6) Could not resolve host: Accept
curl: (6) Could not resolve host: POST
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
root#localhost and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apache/2.2.15 (Red Hat) Server at openshift.redhat.com Port 80</address>
</body></html>
any ideas how to fix this error?
This should work:
curl -k -X POST https://openshift.redhat.com/broker/rest/domains/jhaopenshift/applications --user "user:pass" --data "name=myapp&cartridge[url]=https://cartreflect-claytondev.rhcloud.com/reflect?github=smarterclayton/openshift-cdk-cart&scale=false"
You need to supply the [url] after the cartridge parameter, you also need to either point to a manifest.yml file that has the Source-Url element included, or use the cartridge reflector to point to the partial github url with the format user/repo

Wget windows and multiple --header switches

I'm trying to use wget 1.11.4 running on Windows Server 2003 to do some JSON with a web site. I can retrieve info OK but I can't send any. I'm not positive that my JSON is formatted correctly but there seems to be a more fundamental problem.
If I do:
wget --header="Authorization: Bearer <redacted>" --no-check-certificate --post-data="{'workspaces':{'title':'CMC Regulatory Support','creator_role':'maven'}}" https://api.mavenlink.com/api/v1/workspaces.json
I get a JSON error back from the site "ERROR 422: Unprocessable Entity." But if I add another --header:
wget -S --header="Authorization: Bearer <redacted>" -–header="Content-Type: application/json" --no-check-certificate --post-data="{'workspaces':{'title':'CMC Regulatory Support','creator_role':'maven'}}" https://api.mavenlink.com/api/v1/workspaces.json
I get:
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\Program Files\GnuWin32/etc/wgetrc
wget: invalid option -- û
Usage: wget [OPTION]... [URL]...
Try `wget --help' for more options.
but the manual clearly states that multiple --header switches are allowed, and I see that swithc used in examples on the web?. WTF?
Your second --header parameter before the Content-Type contains different dashes.
-–header="Content-Type
If you fix it wget will send the request.