How can I send a message to the github API with curl? - html

I am trying to modify the label color like this: LABEL API
curl -k -u "xx:yy" https://api.github.com/repos/xx/zz/labels -H "Content-Type: application/x-www-form-urlencoded" -d "{'name':'Bug','color':'ff00ff'}"
The format looks okay to me but it returns:
{
"message": "Problems parsing JSON"
}
Does anyone have any idea what might be wrong with my Json.

You should be using Content-Type: application/json.

Related

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

Sending POST Request from bash script

I want to execute a bash script after i make a POST request.So far i am using Postman for sending the request , but i was wondering if i can somehow do it from a bash script as well with a json file as parameter.
I have looked into curl so far but it does not work:
bash file
curl -X POST -d req.json http://localhost:9500
Json file (req.json)
{
"id":5,
"name":"Dan",
"age":33,
"cnp":33,
"children":100,
"isMarried":0
}
I just get the error :
HTTP/1.0 503 Service Unavailable
with the trailing HTML
curl should do the job. This will send a normal POST request using the data in req.json as the body:
curl -X POST -H "Content-Type: application/json" -d #req.json http://localhost:9500
The elements you were missing are -H "Content-Type: application/json" and the # in the data flag. Without the -H flag as above curl will send a content type of application/x-www-form-urlencoded, which most applications won't accept if they expect JSON. The # in the -d flag informs curl that you are passing a file name; otherwise it uses the text itself (i.e. "req.json") as the data.

Unable to simulate curl in postman

I have a curl request as below:
curl -i -H "Content-Type: application/json" -X PUT -d '[]' http://localhost:3000/v1/api/current.json
When I hit the above request in command prompt I get status 200 which is ok. I'm trying to simulate this request using Postman but not sure how to handle it, specifically -d '[]'.
-d should be data param which I expect a key-value pair but from above I don't see any key involved?
-d means it is the request body data
Choose the PUT method, then in the Body tab, choose raw with application/json
And fill the [] into the text editor area.

CouchDB replication error: {"error":"bad_content_type","reason":"Content-Type must be application/json"}

I'm trying to use the replication in CouchDB.
When I enter the following code :
curl -X POST http://127.0.0.1:5984/_replicate \
-d ’{"source":"musica","target":"musica-replica"}’
I receive the following error:
{"error":"bad_content_type","reason":"Content-Type must be application/json"}
Can you help me?
As the reason said, you need to add a header that looks like: Content-Type: application/json
You can add this to curl via the -H "Content-Type: application/json" flag.

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'