0

I'm making a web app to create issues on my GitHub repo, the problem is I can't use the JSON string below this text because the GitHub API responds with "Cannot parse JSON".

I tried this code, this gave me the parse error (because single ticks (') are not working with JSON):

$jsonin = "{'title': '$mytitle','body': '$subject','labels': ['TEST']}";
$exec = shell_exec("curl -u username:AUTHTOKEN  --data '$jsonin' https://api.github.com/repos/username/reponame/issues");

This code is working perfectly (it creates the issue), except it is (obviously) passing the string not the variable value ($mytitle and $subject):

$jsonin = '{"title": "$mytitle","body": "$subject","labels": ["TEST"]}';
$exec = shell_exec("curl -u username:AUTHTOKEN  --data '$jsonin' https://api.github.com/repos/username/reponame/issues");

Any help is appreciated!

NovyLevi
  • 522
  • 2
  • 7
  • 18
  • 2
    Do not create your own json! You'll always end up with some sort of syntax error. Instead, create an array and use [json_encode](https://www.php.net/manual/en/function.json-encode.php) – aynber Jun 28 '19 at 14:07
  • 1
    Also json string is __usually__ created via `json_encode`. – u_mulder Jun 28 '19 at 14:07
  • 2
    why are you sending the command to the shell and not use the curl php functions ? – Vidal Jun 28 '19 at 14:09

0 Answers0