curl POST not giving me result - json

I'm trying to do a curl POST request for json-rpc however it's not giving me any error when I use it and I'm unsure what I'm doing incorrectly. Been trying to figure out how to do it for an hour
The request I'm trying to perform:
http post https://rpc.nearprotocol.com jsonrpc=2.0
method=query params:='["account/near.test", ""]' id=dontcare
I've tried:
curl -X POST https://rpc.nearprotocol.com -d
'{"jsonrpc":"2.0","id":"0","method":"query",
"account/near.test”:”snailbail45"}' -H 'Content-Type: application/json'```
However it's just returning the next line.
This Works for me though:
curl -X POST https://rpc.nearprotocol.com -d
'{"jsonrpc":"2.0","id":"0","method":"status"}' -H 'Content-Type:
application/json'
What am I doing incorrectly in the first one?

You have stylized quotation marks (” instead of ") between test and snailbail45:
"account/near.test”:”snailbail45"

Related

base64 conversion in context with curl

I would like to send a message and attachment via signal-cli.
I successfully set up docker a container by bbernhard/signal-cli-rest-api.
Normal message sending with curl-statement works fine and statement looks like:
curl -X POST -H "Content-Type: application/json" -d '{\"message\": \"Hello World!\", \"number\": \"+490000000\", \"recipients\": [\"+4900000000"]}' 'http://localhost:48080/v2/send'
The message will be sent to one recipient or many. Also working for a group by groupID.
Question: How to add an attachment like a JPG?
If I add \"base64_attachments\": [\"${ENCODED_IMAGE}")\"] to the statement, then i get the error message {"error":"Couldn't process request - invalid request"}
Full bash script looks like :
#!/bin/bash
INPUT_FILE="/path/to/file/IMG_5098.JPG"
TMPFILE=$(mktemp)
base64 "${INPUT_FILE}" --wrap=0 > "${TMPFILE}"
ENCODED_IMAGE=$(cat "${TMPFILE}")
curl -X POST -H "Content-Type: application/json" -d '{\"message\": \"Hello World!\", \"base64_attachments\": [\"${ENCODED_IMAGE}")\"], \"number\": \"+4900000\", \"recipients\": [\"+4900000000\"]}' 'http://localhost:48080/v2/send'
rm "${TMPFILE}"
I expected the image send as well as the message

How to GET data of a key in json using curl?

Sorry Pretty noob to json.
Basically I have a simple server where I can upload data in there.
E.g:
curl -vX PUT "http://IP:port/ABC" -H "Content-Type: application/json" -d #"Once Upon a time."
After when I do:
curl -vX GET "http://IP:port/ABC" -H "Content-Type: application/json"
I get:
{"reverse_shell":
{"aliases":{},"mappings":{},"settings":
{"index":{"creation_date":"1561863982371","number_of_shards":"5","number_of_replicas":"1","uuid":"IAWE83rYQqmtKW-9svkBVg","version":{"created":"6040299"},"provided_name":"ABC"}
}
}
}
As you can see there is no where mentioning Once Upon a time, so is there I am missing? or how do I get that data from json using curl?
I am in kali linux env.
It looks like you are trying to post a string as a file.
When you specify a "#" with -d this tells curl to send the data from a file called "Once Upon a time."
If you are trying to put a file then you should do:
my_text_file.txt
Once Upon a time.
curl -vX PUT "http://IP:port/ABC" -H "Content-Type: application/json" -d #./my_text_file.txt https://server/api/path

pushbullet api decoding (v2/push)

I want to use the pushbullet api (v2/push) for pushing messages, but if I include '%' character inside title or body the server gives me the following error:
{"error":{"type":"invalid_request","message":"Failed to decode urlencoded POST form body.","cat":"~(=^‥^)ノ"}}
How can I fix this problem?
request: curl https://api.pushbullet.com/v2/pushes -k -u token: -d type=note -d title="%test" -d body="%%test" -X POST
x-www-form-urlencoded is not the most straightforward of formats. You can probably use curl with the --data-urlencode option. You can also try encoding your values with this tool: http://meyerweb.com/eric/tools/dencoder/
That should produce urlencoded output, for instance your request would look more like:
curl -u token: https://api.pushbullet.com/v2/pushes --header "Content-Type: application/x-www-form-urlencoded" --data-binary 'type=note&title=TITLETEXT&body=%25BODYTEXT'

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