Skip to content

Instantly share code, notes, and snippets.

@JonnyFunFun
Created November 25, 2013 15:14
Show Gist options
  • Save JonnyFunFun/7642759 to your computer and use it in GitHub Desktop.
Save JonnyFunFun/7642759 to your computer and use it in GitHub Desktop.
Example on how to consume Targetprocess' REST API with PHP
<?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);
@abdul-sami
Copy link

There was an error which I have removed. Please check my https://gist.github.com/abdul-sami/11081901#file-tp-api-example-php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment