Created
November 25, 2013 15:14
-
-
Save JonnyFunFun/7642759 to your computer and use it in GitHub Desktop.
Example on how to consume Targetprocess' REST API with PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('TP_URL', 'http://enzinna.tpondemand.com/'); | |
define('TP_USER', 'admin'); | |
define('TP_PASS', 'admin'); | |
# GET a story | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, TP_URL."api/v1/UserStories/201?format=json"); | |
# set our authorization header and content-type | |
curl_setopt($data, CURLOPT_HTTPHEADER, | |
array( | |
"Authorization: Basic " . base64_encode(TP_USER . ":" . TP_PASS), | |
"Content-type: application/json", | |
"Accept: application/json" | |
)); | |
$story = json_decode(curl_exec($ch)); | |
curl_close($ch); | |
# $story is now an associative array. | |
# CREATE a new story | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, TP_URL."api/v1/UserStories"); | |
# set our authorization header and content-type | |
curl_setopt($data, CURLOPT_HTTPHEADER, | |
array( | |
"Authorization: Basic " . base64_encode(TP_USER . ":" . TP_PASS), | |
"Content-type: application/json", | |
"Accept: application/json" | |
)); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
# You can find all applicable and required fields for stories and other resources here: | |
# http://md5.tpondemand.com/api/v1/UserStories/meta | |
$story = array( | |
"Name" => "Story created by REST API", | |
"Project" => array( | |
"Id": 2 #we'll create the story in the project with ID = 2 | |
), | |
"EntityState" => array( | |
"Name": "Open" | |
), | |
"Priority" => array( | |
"Name": "Nice to Have" | |
) | |
); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($story)); | |
$result = curl_exec($ch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There was an error which I have removed. Please check my https://gist.github.com/abdul-sami/11081901#file-tp-api-example-php