Skip to content

Instantly share code, notes, and snippets.

@abdul-sami
Forked from JonnyFunFun/tp api example.php
Last active August 9, 2018 07:46
Show Gist options
  • Save abdul-sami/11081901 to your computer and use it in GitHub Desktop.
Save abdul-sami/11081901 to your computer and use it in GitHub Desktop.
<?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($ch, 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($ch, 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