Code Samples

Python

🚧

Support for TLS v1.2

Starting from January 2017, HTTPS mode with TLS v1.2 encryption is used for all API connections when Targetprocess is hosted in cloud. Python v2.7.9+ supports this encryption. Earlier versions of Python do not have such support.

import base64 
import urllib2 
import urllib 
class Target_Process(): 
    user = '' 
    password = '' 
    tp_uri = '' 
     
    def __init__(self, tp_name, username, password):
        self.user = username 
        self.password = password 
        self.tp_uri = tp_name 
    def get_object(self, type, id): 
        auth = base64.encodestring("%s:%s" % (self.user, self.password))
        ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
        request = urllib2.Request(self.tp_uri + type + '/' + id) 
        request.add_header("Authorization", "Basic %s" % auth) 
        request.add_header('Content-Type', 'application/json')
        response = urllib2.urlopen(request, context=ctx)
        return response.read()

PHP

<?php
$url = "http://localhost/Targetprocess/api/v1/userStories.asmx/?skip=0&take=999&include=[".implode(',', array(
    'id', 'effort', 'entityState', 'customFields'
))."]";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_HTTPHEADER,array (
    "Accept: application/json"
));
ob_start();
curl_exec ($ch);
curl_close ($ch);
$cache = json_decode(ob_get_contents());
ob_clean();
var_dump($cache->Items[0]->Id); // id of first user story

JavaScript

JavaScript examples are gathered in the standalone article.

VBA for Excel

Sub GetUserStories()
    Set objHTTP = CreateObject("MSXML2.XMLHTTP")
    
    objHTTP.Open "GET", "https://Targetprocess/api/v1/UserStories?include=[Id,Name]&take=1000", False, "login", "password"
    objHTTP.send
    
    Set result = objHTTP.responseXML
    
    Dim i As Integer
    For Each Node In result.SelectNodes("//UserStory")
        i = i + 1
        Range("a" & i) = Node.Attributes.getNamedItem("Id").Value
        Range("b" & i) = Node.Attributes.getNamedItem("Name").Value
    Next
    
End Sub

More samples

https://github.com/TargetProcess/RestAPISamples