0

I am trying to use Pivotal API with PHP. As the version 5 use JSON instead of XML in previous version, I tried it. Here is the code :

public function updateStory($id) {
    $update = '{"name":"Here is a test"}';
    $url = "https://www.pivotaltracker.com/services/v5/projects/$this->project/stories/$id";
    $cmd = 'curl -H "X-TrackerToken: ' . $this->token . '" -X PUT -H "Content-Type: application/json" -d \'' . $update . '\'  ' . $url;
    $xml = shell_exec($cmd);

    echo "<pre>";
    echo $cmd;
    var_dump(json_decode($xml, true));
    echo "</pre>";
}

The output of this code is :

curl -H "X-TrackerToken: TOKEN" -X PUT -H "Content-Type: application/json" -d '{"name":"Here is a test"}' https://www.pivotaltracker.com/services/v5/projects/IDPROJECT/stories/IDSTORY

array (size=5)
    'code' => string 'could_not_parse_body'
    'kind' => string 'error'
    'error' => string 'Cannot parse the JSON-encoded request body.'
    'general_problem' => string 'Couldn't parse the content of the request's body.'
    'possible_fix' => string 'The parser returned the following error message:  lexical error: invalid char in json text.
                                       '{name:Here is a test
                     (right here) ------^
'

When I execute the created command above using Cygwin, it works. Using PHP, it don't.

Does anyone knows the solution?


Actually I already tried that but it doesn't work.

Anyway, I tried to use curl API in PHP. Knowing that the url use SSL I followed this thread : http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/

I generated the certificate but then when I use it with PHP curl, I have a blank page.

Using Cygwin, I have this error :

curl --cacert pivotal.crt https://www.pivotaltracker.com/services/v5/projects/1202004/stories/

curl: (60) SSL certificate problem: unable to get local issuer certificate More details here: http://curl.haxx.se/docs/sslcerts.html curl performs SSL certificate verification by default, using a "bundle" of Certificate Authority (CA) public keys (CA certs). If the default bundle file isn't adequate, you can specify an alternate file using the --cacert option. If this HTTPS server uses a certificate signed by a CA represented in the bundle, the certificate verification probably failed due to a problem with the certificate (it might be expired, or the name might not match the domain name in the URL). If you'd like to turn off curl's verification of the certificate, use the -k (or --insecure) option.

Any solution ??

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Mahcih
  • 23
  • 5

1 Answers1

0

try var_dump(json_decode(stripslashes($xml), true));. You could also do some preg function to remove suspect chars that you think might be there like tab or linebreak. Just run $xml through a custom function which does some sanity checks before passing to json_decode

raidenace
  • 12,789
  • 1
  • 32
  • 35