├── .gitignore ├── C# ├── Basic Auth │ └── BasicAuth.cs ├── Pagination with JSON │ └── Pagination.cs ├── Searching │ └── Searching.cs └── Update an Item │ └── UpdateItem.cs ├── Java ├── Basic Auth │ └── BasicAuth.java ├── Pagination with JSON │ └── Pagination.java ├── Searching │ └── Searching.java └── Update an Item │ └── UpdateItem.java ├── LICENSE ├── PHP ├── Basic Auth │ ├── basic_auth.php │ └── using_curl.php ├── Pagination with JSON │ └── pagination.php ├── Searching │ └── searching.php └── Update an Item │ └── updateItem.php ├── Perl ├── Basic Auth │ └── BasicAuth.pl ├── Pagination with JSON │ └── Pagination.pl ├── Searching │ └── Searching.pl └── Update an Item │ └── Update_Item.pl ├── Python ├── Basic Auth │ ├── basic_auth.py │ └── with_request.py ├── Pagination with JSON │ └── pagination.py ├── Searching │ └── searching.py └── Update an Item │ └── update_item.py ├── README.md └── Ruby ├── Basic Auth └── basic_auth.rb ├── Pagination with JSON └── pagination.rb ├── Searching └── searching.rb └── Update an Item └── update_item.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /C#/Basic Auth/BasicAuth.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | 5 | public class BasicAuth 6 | { 7 | static public void Main() 8 | { 9 | string baseUrl = "{base url}.jamacloud.com/rest/latest/"; 10 | 11 | // Username and password should be stored according 12 | // to your organization's security policies 13 | string username = "API_User"; 14 | string password = "********"; 15 | 16 | string resource = "projects"; 17 | 18 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(baseUrl + resource); 19 | request.Method = WebRequestMethods.Http.Get; 20 | 21 | string credentials = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password)); 22 | request.Headers["Authorization"] = "Basic " + credentials; 23 | 24 | HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 25 | 26 | Stream stream = response.GetResponseStream(); 27 | StreamReader streamReader = new StreamReader(stream); 28 | string s = streamReader.ReadToEnd(); 29 | 30 | Console.WriteLine(s); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /C#/Pagination with JSON/Pagination.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Collections.Generic; 5 | 6 | // Newtonsoft.Json is available from http://www.newtonsoft.com/json 7 | using Newtonsoft.Json; 8 | using Newtonsoft.Json.Linq; 9 | 10 | public class BasicAuth 11 | { 12 | static public void Main() 13 | { 14 | string baseURL = "{base url}/rest/latest/"; 15 | 16 | // Username and password should be stored according 17 | // to your organization's security policies 18 | string username = "API_User"; 19 | string password = "********"; 20 | 21 | string resource = "projects"; 22 | 23 | int allowedResults = 20; 24 | string maxResults = "maxResults=" + allowedResults; 25 | 26 | long resultCount = -1; 27 | long startIndex = 0; 28 | 29 | while (resultCount != 0) 30 | { 31 | string startAt = "startAt=" + startIndex; 32 | 33 | string url = baseURL + resource + "?" + startAt + "&" + maxResults; 34 | 35 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 36 | request.Credentials = new NetworkCredential(username, password); 37 | request.Method = WebRequestMethods.Http.Get; 38 | request.PreAuthenticate = true; 39 | 40 | HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 41 | 42 | Stream stream = response.GetResponseStream(); 43 | StreamReader streamReader = new StreamReader(stream); 44 | 45 | JObject jsonResponse = JObject.Parse(streamReader.ReadToEnd()); 46 | JObject meta = (JObject) jsonResponse["meta"]; 47 | JObject pageInfo = (JObject) meta["pageInfo"]; 48 | 49 | startIndex = (long) pageInfo["startIndex"] + allowedResults; 50 | resultCount = (long) pageInfo["resultCount"]; 51 | 52 | JArray projects = (JArray) jsonResponse["data"]; 53 | foreach (JObject project in projects) 54 | { 55 | JObject fields = (JObject) project["fields"]; 56 | string name = (string) fields["name"]; 57 | Console.WriteLine(name); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /C#/Searching/Searching.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Collections.Generic; 5 | 6 | // Newtonsoft.Json is available from http://www.newtonsoft.com/json 7 | using Newtonsoft.Json; 8 | using Newtonsoft.Json.Linq; 9 | 10 | public class Searching 11 | { 12 | static public void Main() 13 | { 14 | string baseURL = "{base url}/rest/latest/"; 15 | 16 | // Username and password should be stored according 17 | // to your organization's security policies 18 | string username = "API_User"; 19 | string password = "********"; 20 | 21 | string stringToFind = "Unique string"; 22 | 23 | string containsParameter = "contains=" + WebUtility.UrlEncode(stringToFind); 24 | 25 | string url = baseURL + "abstractitems?" + containsParameter; 26 | 27 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 28 | request.Credentials = new NetworkCredential(username, password); 29 | request.Method = WebRequestMethods.Http.Get; 30 | request.PreAuthenticate = true; 31 | 32 | HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 33 | 34 | Stream stream = response.GetResponseStream(); 35 | StreamReader streamReader = new StreamReader(stream); 36 | 37 | JObject jsonResponse = JObject.Parse(streamReader.ReadToEnd()); 38 | JObject meta = (JObject) jsonResponse["meta"]; 39 | JObject pageInfo = (JObject) meta["pageInfo"]; 40 | long totalResults = (long) pageInfo["totalResults"]; 41 | 42 | if (totalResults == 1) 43 | { 44 | JArray data = (JArray) jsonResponse["data"]; 45 | JObject item = (JObject) data[0]; 46 | 47 | JObject fields = (JObject) item["fields"]; 48 | string name = (string) fields["name"]; 49 | Console.WriteLine(name); 50 | } 51 | else 52 | { 53 | Console.WriteLine("stringToFind wasn't unique"); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /C#/Update an Item/UpdateItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Collections.Generic; 5 | 6 | // Newtonsoft.Json is available from http://www.newtonsoft.com/json 7 | using Newtonsoft.Json; 8 | using Newtonsoft.Json.Linq; 9 | 10 | public class Searching 11 | { 12 | static private string baseURL = "{base url}/rest/latest/"; 13 | 14 | // Username and password should be stored according 15 | // to your organization's security policies 16 | static private string username = "API_User"; 17 | static private string password = "********"; 18 | 19 | static private string stringToFind = "Unique string"; 20 | 21 | static public void Main() 22 | { 23 | long itemId = getId(stringToFind); 24 | updateItem(itemId); 25 | } 26 | 27 | static public JObject get(string requestURL) 28 | { 29 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestURL); 30 | request.Credentials = new NetworkCredential(username, password); 31 | request.Method = WebRequestMethods.Http.Get; 32 | request.PreAuthenticate = true; 33 | 34 | HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 35 | 36 | Stream stream = response.GetResponseStream(); 37 | StreamReader streamReader = new StreamReader(stream); 38 | 39 | return JObject.Parse(streamReader.ReadToEnd()); 40 | } 41 | 42 | static public int put(string requestURL, JObject payload) 43 | { 44 | HttpWebRequest request = (HttpWebRequest) WebRequest.Create(requestURL); 45 | request.Credentials = new NetworkCredential(username, password); 46 | request.Method = WebRequestMethods.Http.Put; 47 | request.ContentType = "application/json; charset=UTF-8"; 48 | request.PreAuthenticate = true; 49 | 50 | StreamWriter streamWriter = new StreamWriter(request.GetRequestStream()); 51 | streamWriter.Write(payload.ToString()); 52 | streamWriter.Flush(); 53 | 54 | HttpWebResponse response = (HttpWebResponse) request.GetResponse(); 55 | 56 | return (int)response.StatusCode; 57 | } 58 | 59 | static public long getId(string toFind) 60 | { 61 | string url = baseURL + "abstractitems?contains=" + WebUtility.UrlEncode(stringToFind); 62 | JObject response = get(url); 63 | JObject meta = (JObject) response["meta"]; 64 | JObject pageInfo = (JObject) meta["pageInfo"]; 65 | long totalResults = (long) pageInfo["totalResults"]; 66 | 67 | if(totalResults == 1) 68 | { 69 | JArray data = (JArray) response["data"]; 70 | JObject item = (JObject) data[0]; 71 | 72 | return (long) item["id"]; 73 | } 74 | else 75 | { 76 | Console.WriteLine("stringToFind wasn't unique"); 77 | Environment.Exit(1); 78 | } 79 | return -1; 80 | } 81 | 82 | static public void updateItem(long itemId) 83 | { 84 | setLockState(true, itemId); 85 | JObject item = getItem(itemId); 86 | item["fields"]["description"] += testResults(); 87 | putItem(itemId, item); 88 | setLockState(false, itemId); 89 | } 90 | 91 | static public void setLockState(bool locked, long itemId) 92 | { 93 | JObject payload = new JObject(); 94 | payload.Add("locked", locked); 95 | 96 | string url = baseURL + "items/" + itemId + "/lock"; 97 | put(url, payload); 98 | } 99 | 100 | static public JObject getItem(long itemId) 101 | { 102 | string url = baseURL + "items/" + itemId; 103 | JObject jsonResponse = get(url); 104 | return (JObject) jsonResponse["data"]; 105 | } 106 | 107 | static public void putItem(long itemId, JObject item) 108 | { 109 | string url = baseURL + "items/" + itemId; 110 | 111 | int responseCode = put(url, item); 112 | if(responseCode < 400) 113 | { 114 | Console.WriteLine("Success"); 115 | } 116 | } 117 | 118 | static public string testResults() 119 | { 120 | Random random = new Random(); 121 | string htmlTemplate = "

Imported test results:

Status: "; 122 | 123 | bool testPassed = random.Next(2) == 1; 124 | 125 | if(testPassed) 126 | { 127 | return htmlTemplate + "pass"; 128 | } 129 | return htmlTemplate + "fail"; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /Java/Basic Auth/BasicAuth.java: -------------------------------------------------------------------------------- 1 | import java.util.Base64; // Java 8 2 | import java.io.BufferedReader; 3 | import java.io.InputStream; 4 | import java.io.InputStreamReader; 5 | import java.net.HttpURLConnection; 6 | import java.net.URL; 7 | import java.net.MalformedURLException; 8 | import java.io.IOException; 9 | 10 | public class BasicAuth { 11 | public static void main(String[] args) throws MalformedURLException, IOException { 12 | String baseURL = "{base url}/rest/latest/"; 13 | 14 | // Username and password should be stored according 15 | // to your organization's security policies 16 | String username = "API_User"; 17 | String password = "********"; 18 | String auth = Base64.getEncoder().encodeToString((username + ":" + password).getBytes()); 19 | 20 | String resource = "projects"; 21 | 22 | URL url = new URL(baseURL + resource); 23 | HttpURLConnection connection = (HttpURLConnection)url.openConnection(); 24 | connection.setRequestProperty("Authorization", "Basic " + auth); 25 | 26 | InputStream content = connection.getInputStream(); 27 | 28 | BufferedReader in = new BufferedReader(new InputStreamReader(content)); 29 | System.out.println(in.readLine()); 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Java/Pagination with JSON/Pagination.java: -------------------------------------------------------------------------------- 1 | import java.util.Base64; // Java 8 2 | import java.io.BufferedReader; 3 | import java.io.InputStream; 4 | import java.io.InputStreamReader; 5 | import java.net.HttpURLConnection; 6 | import java.net.URL; 7 | import java.net.MalformedURLException; 8 | import java.io.IOException; 9 | 10 | // Simple json available here: https://code.google.com/p/json-simple/ 11 | import org.json.simple.JSONArray; 12 | import org.json.simple.JSONObject; 13 | import org.json.simple.parser.JSONParser; 14 | import org.json.simple.parser.ParseException; 15 | 16 | public class Pagination { 17 | public static void main(String[] args) throws MalformedURLException, IOException, ParseException { 18 | String baseURL = "{base url}/rest/latest/"; 19 | 20 | // Username and password should be stored according 21 | // to your organization's security policies 22 | String username = "API_User"; 23 | String password = "********"; 24 | String auth = Base64.getEncoder().encodeToString((username + ":" + password).getBytes()); 25 | 26 | String resource = "projects"; 27 | 28 | int allowedResults = 20; 29 | String maxResults = "maxResults=" + allowedResults; 30 | 31 | long resultCount = -1; 32 | long startIndex = 0; 33 | 34 | JSONParser parser = new JSONParser(); 35 | 36 | while(resultCount != 0) { 37 | String startAt = "startAt=" + startIndex; 38 | 39 | String requestURL = baseURL + resource + "?" + startAt + "&" + maxResults; 40 | 41 | URL url = new URL(requestURL); 42 | HttpURLConnection connection = (HttpURLConnection)url.openConnection(); 43 | connection.setRequestProperty("Authorization", "Basic " + auth); 44 | 45 | InputStream content = connection.getInputStream(); 46 | 47 | BufferedReader in = new BufferedReader(new InputStreamReader(content)); 48 | 49 | JSONObject response = (JSONObject) parser.parse(in.readLine()); 50 | JSONObject meta = (JSONObject) response.get("meta"); 51 | JSONObject pageInfo = (JSONObject) meta.get("pageInfo"); 52 | 53 | startIndex = (long)pageInfo.get("startIndex") + allowedResults; 54 | resultCount = (long) pageInfo.get("resultCount"); 55 | 56 | JSONArray projects = (JSONArray) response.get("data"); 57 | for(Object arrayElement : projects) { 58 | JSONObject project = (JSONObject) arrayElement; 59 | JSONObject fields = (JSONObject) project.get("fields"); 60 | System.out.println(fields.get("name")); 61 | } 62 | } 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /Java/Searching/Searching.java: -------------------------------------------------------------------------------- 1 | import java.util.Base64; // Java 8 2 | import java.io.BufferedReader; 3 | import java.io.InputStream; 4 | import java.io.InputStreamReader; 5 | import java.net.HttpURLConnection; 6 | import java.net.URL; 7 | import java.net.MalformedURLException; 8 | import java.io.IOException; 9 | import java.net.URLEncoder; 10 | 11 | // Simple json available here: https://code.google.com/p/json-simple/ 12 | import org.json.simple.JSONArray; 13 | import org.json.simple.JSONObject; 14 | import org.json.simple.parser.JSONParser; 15 | import org.json.simple.parser.ParseException; 16 | 17 | public class Searching { 18 | 19 | public static void main(String[] args) throws Exception { 20 | String baseURL = "{base url}/rest/latest/"; 21 | 22 | // Username and password should be stored according 23 | // to your organization's security policies 24 | String username = "API_User"; 25 | String password = "********"; 26 | String auth = Base64.getEncoder().encodeToString((username + ":" + password).getBytes()); 27 | 28 | String stringToFind = "Unique string"; 29 | 30 | String containsParameter = "contains=" + URLEncoder.encode(stringToFind, "UTF-8"); 31 | 32 | String requestURL = baseURL + "abstractitems?" + containsParameter; 33 | 34 | URL url = new URL(requestURL); 35 | HttpURLConnection connection = (HttpURLConnection)url.openConnection(); 36 | connection.setRequestProperty("Authorization", "Basic " + auth); 37 | 38 | InputStream content = connection.getInputStream(); 39 | 40 | BufferedReader in = new BufferedReader(new InputStreamReader(content)); 41 | 42 | JSONParser parser = new JSONParser(); 43 | JSONObject response = (JSONObject) parser.parse(in.readLine()); 44 | JSONObject meta = (JSONObject) response.get("meta"); 45 | JSONObject pageInfo = (JSONObject) meta.get("pageInfo"); 46 | long totalResults = (long) pageInfo.get("totalResults"); 47 | 48 | if(totalResults == 1) { 49 | JSONArray data = (JSONArray) response.get("data"); 50 | JSONObject item = (JSONObject) data.get(0); 51 | 52 | JSONObject fields = (JSONObject) item.get("fields"); 53 | String name = (String) fields.get("name"); 54 | System.out.println(name); 55 | 56 | } else { 57 | System.out.println("stringToFind wasn't unique"); 58 | } 59 | } 60 | } 61 | 62 | -------------------------------------------------------------------------------- /Java/Update an Item/UpdateItem.java: -------------------------------------------------------------------------------- 1 | import java.util.Base64; // Java 8 2 | import java.io.BufferedReader; 3 | import java.io.InputStream; 4 | import java.io.InputStreamReader; 5 | import java.net.HttpURLConnection; 6 | import java.net.URL; 7 | import java.util.Random; 8 | import java.net.MalformedURLException; 9 | import java.io.IOException; 10 | import java.io.OutputStreamWriter; 11 | import java.net.URLEncoder; 12 | 13 | // Simple json available here: https://code.google.com/p/json-simple/ 14 | import org.json.simple.JSONArray; 15 | import org.json.simple.JSONObject; 16 | import org.json.simple.parser.JSONParser; 17 | import org.json.simple.parser.ParseException; 18 | 19 | public class UpdateItem { 20 | private static String baseURL = "{base url}/rest/latest/"; 21 | 22 | // Username and password should be stored according 23 | // to your organization's security policies 24 | private static String username = "API_User"; 25 | private static String password = "********"; 26 | private static String auth = Base64.getEncoder().encodeToString((username + ":" + password).getBytes()); 27 | 28 | private static String stringToFind = "Unique string"; 29 | 30 | public static void main(String[] args) throws Exception { 31 | long itemId = getId(stringToFind); 32 | updateItem(itemId); 33 | } 34 | 35 | public static JSONObject get(String requestURL) throws Exception { 36 | JSONParser parser = new JSONParser(); 37 | URL url = new URL(requestURL); 38 | HttpURLConnection connection = (HttpURLConnection)url.openConnection(); 39 | connection.setRequestProperty("Authorization", "Basic " + auth); 40 | 41 | InputStream content = connection.getInputStream(); 42 | 43 | BufferedReader in = new BufferedReader(new InputStreamReader(content)); 44 | return (JSONObject) parser.parse(in.readLine()); 45 | } 46 | 47 | public static int put(String requestURL, JSONObject payload) throws Exception { 48 | URL url = new URL(requestURL); 49 | HttpURLConnection connection = (HttpURLConnection)url.openConnection(); 50 | connection.setRequestMethod("PUT"); 51 | connection.setDoOutput(true); 52 | connection.setRequestProperty("Authorization", "Basic " + auth); 53 | connection.setRequestProperty("Content-Type", "application/json"); 54 | OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream()); 55 | out.write(payload.toString()); 56 | out.flush(); 57 | out.close(); 58 | return connection.getResponseCode(); 59 | } 60 | 61 | public static long getId(String toFind) throws Exception { 62 | String url = baseURL + "abstractitems?contains=" + URLEncoder.encode(toFind, "UTF-8"); 63 | JSONObject response = get(url); 64 | JSONObject meta = (JSONObject) response.get("meta"); 65 | JSONObject pageInfo = (JSONObject) meta.get("pageInfo"); 66 | long totalResults = (long) pageInfo.get("totalResults"); 67 | 68 | if(totalResults == 1) { 69 | JSONArray data = (JSONArray) response.get("data"); 70 | JSONObject item = (JSONObject) data.get(0); 71 | 72 | return (long) item.get("id"); 73 | } else { 74 | System.out.println("stringToFind wasn't unique"); 75 | System.exit(1); 76 | } 77 | return -1; 78 | } 79 | 80 | public static void updateItem(long itemId) throws Exception { 81 | setLockState(true, itemId); 82 | JSONObject item = getItem(itemId); 83 | JSONObject fields = (JSONObject) item.get("fields"); 84 | String description = (String) fields.get("description"); 85 | fields.put("description", description + testResults()); 86 | putItem(itemId, item); 87 | setLockState(false, itemId); 88 | } 89 | 90 | public static void setLockState(boolean locked, long itemId) throws Exception { 91 | JSONObject payload = new JSONObject(); 92 | payload.put("locked", locked); 93 | 94 | String url = baseURL + "items/" + itemId + "/lock"; 95 | put(url, payload); 96 | } 97 | 98 | public static JSONObject getItem(long itemId) throws Exception { 99 | String url = baseURL + "items/" + itemId; 100 | JSONObject jsonResponse = get(url); 101 | return (JSONObject) jsonResponse.get("data"); 102 | } 103 | 104 | public static void putItem(long itemId, JSONObject item) throws Exception { 105 | String url = baseURL + "items/" + itemId; 106 | int responseCode = put(url, item); 107 | if(responseCode < 400) { 108 | System.out.println("Success"); 109 | } 110 | } 111 | 112 | public static String testResults() throws Exception { 113 | Random random = new Random(); 114 | String htmlTemplate = "

Imported test results:

Status: "; 115 | 116 | boolean testPassed = random.nextBoolean(); 117 | 118 | if(testPassed) { 119 | return htmlTemplate + "pass"; 120 | } 121 | return htmlTemplate + "fail"; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jama-Software 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /PHP/Basic Auth/basic_auth.php: -------------------------------------------------------------------------------- 1 | array( 13 | "method"=>"GET", 14 | "header"=> "Authorization: Basic " . base64_encode("$username:$password") 15 | ) 16 | ); 17 | $context = stream_context_create($options); 18 | 19 | $result = file_get_contents($base_url . $resource, false, $context); 20 | 21 | echo $result; 22 | ?> 23 | 24 | -------------------------------------------------------------------------------- /PHP/Basic Auth/using_curl.php: -------------------------------------------------------------------------------- 1 | 21 | -------------------------------------------------------------------------------- /PHP/Pagination with JSON/pagination.php: -------------------------------------------------------------------------------- 1 | 41 | -------------------------------------------------------------------------------- /PHP/Searching/searching.php: -------------------------------------------------------------------------------- 1 | 37 | -------------------------------------------------------------------------------- /PHP/Update an Item/updateItem.php: -------------------------------------------------------------------------------- 1 | $new_lock_state); 77 | $url = $base_url . "items/" . $item_id . "/lock"; 78 | put($url, $payload); 79 | } 80 | 81 | function get_item($item_id) { 82 | global $base_url; 83 | 84 | $url = $base_url . "items/" . $item_id; 85 | $json_response = get($url); 86 | 87 | return $json_response['data']; 88 | } 89 | 90 | function put_item($item_id, $item) { 91 | global $base_url; 92 | 93 | $url = $base_url . "items/" . $item_id; 94 | $status_code = put($url, $item); 95 | if($status_code < 400) { 96 | echo "Success"; 97 | } 98 | } 99 | 100 | function test_results() { 101 | $template = "

Imported test results:

Status: "; 102 | $test_passed = rand(0, 1); 103 | if($test_passed == 1) { 104 | return $template . "pass"; 105 | } 106 | return $template . "fail"; 107 | } 108 | 109 | 110 | ?> 111 | -------------------------------------------------------------------------------- /Perl/Basic Auth/BasicAuth.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | use LWP; 3 | 4 | $base_url = "{base url}/rest/latest/"; 5 | 6 | # Username and password should be stored according 7 | # to your organization's security policies 8 | $username = "API_User"; 9 | $password = "********"; 10 | 11 | $resource = "projects"; 12 | 13 | my $browser = LWP::UserAgent->new; 14 | my $req = HTTP::Request->new( GET => $base_url . $resource ); 15 | $req->authorization_basic( $username, $password ); 16 | my $res = $browser->request( $req ); 17 | 18 | print $res->content; 19 | 20 | -------------------------------------------------------------------------------- /Perl/Pagination with JSON/Pagination.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | use LWP; 3 | use JSON; 4 | 5 | $base_url = "{base url}/rest/latest/"; 6 | 7 | # Username and password should be stored according 8 | # to your organization's security policies 9 | $username = "API_User"; 10 | $password = "********"; 11 | 12 | $resource = "projects"; 13 | 14 | my $browser = LWP::UserAgent->new; 15 | 16 | my $allowed_results = 20; 17 | my $max_results = "maxResults=" . $allowed_results; 18 | 19 | my $result_count = -1; 20 | my $start_index = 0; 21 | 22 | while ($result_count != 0) { 23 | my $start_at = "startAt=" . $start_index; 24 | my $url = $base_url . $resource . "?" . $start_at . "&" . $max_results; 25 | my $req = HTTP::Request->new( GET => $url ); 26 | $req->authorization_basic( $username, $password ); 27 | my $res = $browser->request( $req ); 28 | 29 | my $json_response = from_json( $res->content ); 30 | 31 | my $page_info = $json_response->{"meta"}{"pageInfo"}; 32 | $start_index = $page_info->{"startIndex"} + $allowed_results; 33 | $result_count = $page_info->{"resultCount"}; 34 | 35 | 36 | foreach (@{ $json_response->{"data"} }) { 37 | print $_->{"fields"}->{"name"} . "\n"; 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /Perl/Searching/Searching.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | use LWP; 3 | use JSON; 4 | use URI::Escape; 5 | 6 | $base_url = "{base url}/rest/latest/"; 7 | 8 | # Username and password should be stored according 9 | # to your organization's security policies 10 | $username = "API_User"; 11 | $password = "********"; 12 | 13 | my $string_to_find = "Unique string"; 14 | 15 | my $contains_parameter = "contains=" . uri_escape($string_to_find); 16 | 17 | my $browser = LWP::UserAgent->new; 18 | my $url = $base_url . "abstractitems?" . $contains_parameter; 19 | my $req = HTTP::Request->new( GET => $url ); 20 | $req->authorization_basic( $username, $password ); 21 | my $res = $browser->request( $req ); 22 | 23 | my $json_response = from_json( $res->content ); 24 | 25 | my $total_results = $json_response->{"meta"}->{"pageInfo"}->{"totalResults"}; 26 | 27 | if($total_results == 1) { 28 | my $data = $json_response->{"data"}; 29 | my $item = $data->[0]; 30 | 31 | print $item->{"fields"}->{"name"} . "\n"; 32 | } 33 | else { 34 | print "string_to_find wasn't unique" . "\n"; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Perl/Update an Item/Update_Item.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | use LWP; 3 | use JSON; 4 | use URI::Escape; 5 | 6 | $base_url = "{base url}/rest/latest/"; 7 | 8 | # Username and password should be stored according 9 | # to your organization's security policies 10 | $username = "API_User"; 11 | $password = "********"; 12 | 13 | my $string_to_find = "Unique string"; 14 | 15 | my $item_id = get_id($string_to_find); 16 | update_item($item_id); 17 | 18 | sub get { 19 | my ($url) = @_; 20 | 21 | my $browser = LWP::UserAgent->new; 22 | my $req = HTTP::Request->new( GET => $url ); 23 | $req->authorization_basic( $username, $password ); 24 | my $res = $browser->request( $req ); 25 | 26 | return from_json( $res->content ); 27 | } 28 | 29 | sub put { 30 | my ($url, $payload) = @_; 31 | my $json = JSON->new->encode($payload); 32 | 33 | my $browser = LWP::UserAgent->new; 34 | my $req = HTTP::Request->new( PUT => $url); 35 | $req->authorization_basic( $username, $password ); 36 | $req->header( "Content-Type" => "application/json" ); 37 | $req->content( "$json" ); 38 | 39 | my $res = $browser->request( $req ); 40 | return $res->code(); 41 | } 42 | 43 | sub get_id { 44 | my ($string_to_find) = @_; 45 | 46 | my $url = $base_url . "abstractitems?contains=" . $string_to_find; 47 | my $json_response = get($url); 48 | 49 | my $total_results = $json_response->{"meta"}->{"pageInfo"}->{"totalResults"}; 50 | 51 | if($total_results == 1) { 52 | my $data = $json_response->{"data"}; 53 | my $item = $data->[0]; 54 | return $item->{"id"}; 55 | } 56 | else { 57 | print "string_to_find wasn't unique\n"; 58 | exit 1; 59 | } 60 | } 61 | 62 | sub update_item { 63 | my ($item_id) = @_; 64 | 65 | set_lock_state("true", $item_id); 66 | my $item = get_item($item_id); 67 | $item->{"fields"}->{"description"} .= test_results(); 68 | put_item($item_id, $item); 69 | set_lock_state("false", $item_id); 70 | 71 | } 72 | 73 | sub set_lock_state { 74 | my ($lock_state, $item_id) = @_; 75 | 76 | my $payload = {"locked" => $lock_state}; 77 | my $url = $base_url . "items/" . $item_id . "/lock"; 78 | put($url, $payload); 79 | } 80 | 81 | sub get_item { 82 | my ($item_id) = @_; 83 | 84 | my $url = $base_url . "items/" . $item_id; 85 | my $json_response = get($url); 86 | 87 | return $json_response->{"data"}; 88 | } 89 | 90 | sub put_item { 91 | my ($item_id, $item) = @_; 92 | 93 | my $url = $base_url . "items/" . $item_id; 94 | my $status_code = put($url, $item); 95 | 96 | if($status_code < 400) { 97 | print "Success\n"; 98 | } 99 | } 100 | 101 | sub test_results { 102 | my $template = "

Imported test results:

Status: "; 103 | my $test_passed = int(rand(2)); 104 | if($test_passed) { 105 | return $template . "pass"; 106 | } 107 | return $template . "fail"; 108 | } 109 | 110 | 111 | -------------------------------------------------------------------------------- /Python/Basic Auth/basic_auth.py: -------------------------------------------------------------------------------- 1 | import urllib2 2 | import base64 3 | 4 | base_url = "{base url}/rest/latest/" 5 | 6 | # Username and password should be stored according 7 | # to your organization's security policies 8 | username = "API_User" 9 | password = "********" 10 | 11 | resource = "projects" 12 | 13 | request = urllib2.Request(base_url + resource) 14 | base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '') 15 | request.add_header("Authorization", "Basic %s" % base64string) 16 | 17 | response = urllib2.urlopen(request); 18 | 19 | print response.read(); 20 | -------------------------------------------------------------------------------- /Python/Basic Auth/with_request.py: -------------------------------------------------------------------------------- 1 | # This example makes use of the excellent library at python-requests.org 2 | import requests 3 | 4 | base_url = "{base url}/rest/latest/" 5 | 6 | # Username and password should be stored according 7 | # to your organization's security policies 8 | username = "API_User" 9 | password = "********" 10 | 11 | resource = "projects" 12 | 13 | response = requests.get(base_url + resource, auth=(username, password)) 14 | 15 | print response.text 16 | 17 | -------------------------------------------------------------------------------- /Python/Pagination with JSON/pagination.py: -------------------------------------------------------------------------------- 1 | # This example makes use of the excellent library at python-requests.org 2 | import requests 3 | import json 4 | 5 | base_url = "{base url}/rest/latest/" 6 | 7 | # Username and password should be stored according 8 | # to your organization's security policies 9 | username = "API_User" 10 | password = "********" 11 | 12 | resource = "projects" 13 | 14 | allowed_results = 20 15 | max_results = "maxResults=" + str(allowed_results) 16 | 17 | result_count = -1 18 | start_index = 0 19 | 20 | while result_count != 0: 21 | startAt = "startAt=" + str(start_index) 22 | 23 | url = base_url + resource + "?" + startAt + "&" + max_results 24 | response = requests.get(url, auth=(username, password)) 25 | json_response = json.loads(response.text) 26 | 27 | page_info = json_response["meta"]["pageInfo"] 28 | start_index = page_info["startIndex"] + allowed_results 29 | result_count = page_info["resultCount"] 30 | 31 | projects = json_response["data"] 32 | for project in projects: 33 | print project["fields"]["name"] 34 | 35 | -------------------------------------------------------------------------------- /Python/Searching/searching.py: -------------------------------------------------------------------------------- 1 | # This example makes use of the excellent library at python-requests.org 2 | import requests 3 | import urllib 4 | import json 5 | 6 | base_url = "{base url}/rest/latest/" 7 | 8 | # Username and password should be stored according 9 | # to your organization's security policies 10 | username = "API_User" 11 | password = "********" 12 | 13 | string_to_find = "Unique string" 14 | 15 | contains_parameter = "contains=" + urllib.quote_plus(string_to_find) 16 | 17 | url = base_url + "abstractitems?" + contains_parameter 18 | response = requests.get(url, auth=(username, password)) 19 | 20 | json_response = json.loads(response.text) 21 | total_results = json_response["meta"]["pageInfo"]["totalResults"] 22 | 23 | if total_results == 1: 24 | data = json_response["data"] 25 | item = data[0] 26 | 27 | print item["fields"]["name"] 28 | 29 | else: 30 | print "string_to_find wasn't unique" 31 | 32 | -------------------------------------------------------------------------------- /Python/Update an Item/update_item.py: -------------------------------------------------------------------------------- 1 | # This example makes use of the excellent library at python-requests.org 2 | import requests 3 | import random 4 | import urllib 5 | import json 6 | import sys 7 | 8 | base_url = "{base url}/rest/latest/" 9 | 10 | # Username and password should be stored according 11 | # to your organization's security policies 12 | username = "API_User" 13 | password = "********" 14 | 15 | string_to_find = "Unique string" 16 | 17 | def main(): 18 | item_id = get_id(string_to_find) 19 | update_item(item_id) 20 | 21 | def get(url): 22 | response = requests.get(url, auth=(username, password)) 23 | return json.loads(response.text) 24 | 25 | def put(url, payload): 26 | response = requests.put(url, json=payload, auth=(username, password)) 27 | return response.status_code 28 | 29 | def get_id(string_to_find): 30 | url = base_url + "abstractitems?contains=" + string_to_find 31 | json_response = get(url) 32 | 33 | total_results = json_response["meta"]["pageInfo"]["totalResults"] 34 | 35 | if total_results == 1: 36 | data = json_response["data"] 37 | item = data[0] 38 | return item["id"] 39 | 40 | else: 41 | print "string_to_find wasn't unique" 42 | sys.exit(1) 43 | 44 | def update_item(item_id): 45 | set_lock_state(True, item_id) 46 | item = get_item(item_id) 47 | item["fields"]["description"] += test_results() 48 | put_item(item_id, item) 49 | set_lock_state(False, item_id) 50 | 51 | def set_lock_state(new_lock_state, item_id): 52 | payload = { 53 | "locked": new_lock_state 54 | } 55 | url = base_url + "items/" + str(item_id) + "/lock" 56 | put(url, payload) 57 | 58 | def get_item(item_id): 59 | url = base_url + "items/" + str(item_id) 60 | json_response = get(url) 61 | 62 | return json_response["data"] 63 | 64 | def put_item(item_id, item): 65 | url = base_url + "items/" + str(item_id) 66 | status_code = put(url, item) 67 | if status_code < 400: 68 | print "Success" 69 | 70 | def test_results(): 71 | template = "

Imported test results:

Status: " 72 | test_passed = random.randrange(0,2) 73 | if test_passed == 1: 74 | return template + "pass" 75 | return template + "fail" 76 | 77 | if __name__ == "__main__": 78 | main() 79 | 80 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jama Software 2 | Jama Software is the definitive system of record and action for product development. The company’s modern requirements and test management solution helps enterprises accelerate development time, mitigate risk, slash complexity and verify regulatory compliance. More than 600 product-centric organizations, including NASA, Boeing and Caterpillar use Jama to modernize their process for bringing complex products to market. The venture-backed company is headquartered in Portland, Oregon. For more information, visit [jamasoftware.com](http://jamasoftware.com). 3 | 4 | This repository provides a set of examples for getting started with our REST API. Please visit [dev.jamasoftware.com](http://dev.jamasoftware.com) for additional resources and join the discussion in our community [community.jamasoftware.com](http://community.jamasoftware.com). 5 | 6 | ### Basic Auth 7 | 8 | Authenticating to the Jama REST API using basic authentication. 9 | 10 | ### Pagination with JSON 11 | 12 | Moving through multiple pages of results by consuming JSON responses. 13 | 14 | ### Searching 15 | 16 | Using the abstractitems endpoint to search for an Item in Jama. 17 | 18 | ### Update an Item 19 | 20 | Updating an Item's description. 21 | 22 | -------------------------------------------------------------------------------- /Ruby/Basic Auth/basic_auth.rb: -------------------------------------------------------------------------------- 1 | require "net/http" 2 | 3 | base_url = "{base url}/rest/latest/" 4 | 5 | # Username and password should be stored according 6 | # to your organization's security policies 7 | username = "API_User" 8 | password = "********" 9 | 10 | resource = "projects" 11 | 12 | uri = URI(base_url + resource) 13 | 14 | Net::HTTP.start(uri.host, uri.port, 15 | :use_ssl => uri.scheme == 'https') do |http| 16 | request = Net::HTTP::Get.new(uri) 17 | request.basic_auth(username, password) 18 | response = http.request(request) 19 | 20 | puts response.body 21 | end 22 | -------------------------------------------------------------------------------- /Ruby/Pagination with JSON/pagination.rb: -------------------------------------------------------------------------------- 1 | require "net/http" 2 | require "json" 3 | 4 | base_url = "{base url}/rest/latest/" 5 | 6 | # Username and password should be stored according 7 | # to your organization's security policies 8 | username = "API_User" 9 | password = "********" 10 | 11 | resource = "projects" 12 | 13 | allowed_results = 20 14 | max_results = "maxResults=#{allowed_results}" 15 | 16 | result_count = -1 17 | start_index = 0 18 | 19 | while result_count != 0 do 20 | start_at = "startAt=#{start_index}" 21 | 22 | uri = URI("#{base_url}#{resource}?#{start_at}&#{max_results}") 23 | Net::HTTP.start(uri.host, uri.port, 24 | :use_ssl => uri.scheme == 'https') do |http| 25 | request = Net::HTTP::Get.new(uri) 26 | request.basic_auth(username, password) 27 | response = http.request(request) 28 | 29 | json_response = JSON.parse(response.body) 30 | 31 | page_info = json_response["meta"]["pageInfo"] 32 | start_index = page_info["startIndex"] + allowed_results 33 | result_count = page_info["resultCount"] 34 | 35 | projects = json_response["data"] 36 | projects.each do |project| 37 | puts project["fields"]["name"] 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /Ruby/Searching/searching.rb: -------------------------------------------------------------------------------- 1 | require "net/http" 2 | require "json" 3 | require "uri" 4 | 5 | base_url = "{base url}/rest/latest/" 6 | 7 | # Username and password should be stored according 8 | # to your organization's security policies 9 | username = "API_User" 10 | password = "********" 11 | 12 | string_to_find = "Unique string" 13 | 14 | contains_parameter = URI.escape("contains=#{string_to_find}") 15 | 16 | uri = URI("#{base_url}abstractitems?#{contains_parameter}") 17 | Net::HTTP.start(uri.host, uri.port, 18 | :use_ssl => uri.scheme == 'https') do |http| 19 | request = Net::HTTP::Get.new(uri) 20 | request.basic_auth(username, password) 21 | response = http.request(request) 22 | 23 | json_response = JSON.parse(response.body) 24 | total_results = json_response["meta"]["pageInfo"]["totalResults"] 25 | 26 | if total_results == 1 then 27 | data = json_response["data"] 28 | item = data[0] 29 | 30 | puts item["fields"]["name"] 31 | else 32 | puts "string_to_find wasn't unique" 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /Ruby/Update an Item/update_item.rb: -------------------------------------------------------------------------------- 1 | require "net/http" 2 | require "json" 3 | require "uri" 4 | 5 | $base_url = "{base url}/rest/latest/" 6 | 7 | # Username and password should be stored according 8 | # to your organization's security policies 9 | $username = "API_User" 10 | $password = "********" 11 | 12 | string_to_find = "Unique string" 13 | 14 | def get(url) 15 | uri = URI(url) 16 | Net::HTTP.start(uri.host, uri.port, 17 | :use_ssl => uri.scheme == 'https') do |http| 18 | request = Net::HTTP::Get.new(uri) 19 | request.basic_auth($username, $password) 20 | response = http.request(request) 21 | 22 | return JSON.parse(response.body) 23 | end 24 | end 25 | 26 | def put(url, payload) 27 | uri = URI(url) 28 | Net::HTTP.start(uri.host, uri.port, 29 | :use_ssl => uri.scheme == 'https') do |http| 30 | request = Net::HTTP::Put.new( 31 | uri, 32 | initheader = {"Content-Type" => "application/json"} 33 | ) 34 | request.basic_auth($username, $password) 35 | request.body = payload.to_json 36 | response = http.request(request) 37 | return response.code 38 | end 39 | end 40 | 41 | def get_id(string_to_find) 42 | url = "#{$base_url}abstractitems?contains=#{URI.escape(string_to_find)}" 43 | json_response = get(url) 44 | 45 | total_results = json_response["meta"]["pageInfo"]["totalResults"] 46 | 47 | if total_results == 1 48 | data = json_response["data"] 49 | item = data[0] 50 | return item["id"] 51 | else 52 | puts "string_to_find wasn't unique" 53 | exit 54 | end 55 | end 56 | 57 | def update_item(item_id) 58 | set_lock_state(true, item_id) 59 | item = get_item(item_id) 60 | item["fields"]["description"] += test_results 61 | put_item(item_id, item) 62 | set_lock_state(false, item_id) 63 | end 64 | 65 | def set_lock_state(new_lock_state, item_id) 66 | payload = { 67 | "locked" => new_lock_state 68 | } 69 | 70 | url = "#{$base_url}items/#{item_id}/lock" 71 | put(url, payload) 72 | end 73 | 74 | def get_item(item_id) 75 | url = "#{$base_url}items/#{item_id}" 76 | json_response = get(url) 77 | 78 | return json_response["data"] 79 | end 80 | 81 | def put_item(item_id, item) 82 | url = "#{$base_url}items/#{item_id}" 83 | status_code = put(url, item) 84 | if status_code.to_i < 400 85 | puts "Success" 86 | end 87 | end 88 | 89 | def test_results() 90 | template = "

Imported test results:

Status: " 91 | test_passed = rand(2) 92 | if test_passed == 1 93 | return "#{template}pass" 94 | end 95 | return "#{template}fail" 96 | end 97 | 98 | item_id = get_id(string_to_find) 99 | update_item(item_id) 100 | 101 | --------------------------------------------------------------------------------