So, in-order to send a POST request to gists (github), you can do something like this as seen in https://gist.github.com/caspyi...
curl --user "user" -X POST --data '{"description":"Created via API","public":"true","files":{"file1.txt":{"content":"Demo"}}' https://api.github.com/gists
But, in the above example, the file name and the content of the file are hard coded which is the part ..file1.txt":{"content":"Demo"}
..
I am replacing the above part with my variable $file":{"content":"$content"}
but initialize the variable, the json request must be enclosed in double quotes, which I did as
curl --user "user" -X POST --data "{\"description\":\"Created via API\",\"public\":\"true\",\"files\":{\"$file\":{\"content\":\"$content\"}}' https://api.github.com/gists
But this does not work, I get json error.
{
"message": "Problems parsing JSON",
"documentation_url": "https://developer.github.com/v3/gists/#create-a-gist"
}
Even, if I replaced all the escaped double-quotes with \'
single quotes.
Does anyone know how to include a variable inside this json request? btw: I have used all headers such as
-H "Content-Type: application/json; charset=UTF-8"
and many combinations to validate the request but to no avail
UPDATE.
This is what the entire content looks like.
function gist_controller(){
content=$(cat $1)
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
read -p "enter your password - " pass
public="false"
gist_content=$(cat $1)
curl --user "samserayo" -H "Content-Type: application/json; charset=UTF-8" -X POST -d "{ 'description': 'Created via API', 'public': 'true', 'files':{ ' '$1 ':{ 'content': '$gist_content'}}" https://api.github.com/gists
}
UPDATE 2
The file that causes the script to break (the file I am trying to upload is)
<?php echo 'hello world' ?>
;
afterecho 'hello world'