Availability
This routine is available starting with katl-commons 4.1.0.
Syntax
httpPut(url, request [, putDataObject])
Description
Executes an HTTP PUT for the given URL using the specified HttpRequest object. The data used for the PUT can be either included in the request object (as name-value parameters) or it can be added as a separate parameter (in the case of JSON, struct etc).Parameters
Parameter name | Type | Required | Description |
---|---|---|---|
url | string | Yes | The URL. |
request | HttpRequest | Yes | An HttpRequest object containing headers, cookies, parameters. |
putDataObject | variable: string, array or struct | No | Data to be used for the PUT method. |
The request parameter should have the type HttpRequest described here.
Return type
variable return type - depending on the left hand side operator type
Example
The following example calls an HTTP PUT using the JIRA REST API that updates the assignee for the current ticket.
string baseUrl = getJIRABaseUrl(); string requestUrl = baseUrl + "/rest/api/2/issue/" + key; HttpRequest request; HttpHeader authHeader = httpBasicAuthHeader("admin", "admin"); request.headers += authHeader; request.headers += httpCreateHeader("Content-Type", "application/json"); string updateInfo = "{\"fields\": {\"assignee\":{\"name\":\"guest1\"}}}"; httpPut(requestUrl, request, updateInfo);
You can get the same result if, instead of the JSON, you use a SIL structure to store the data to be updated.
string baseUrl = getJIRABaseUrl(); string requestUrl = baseUrl + "/rest/api/2/issue/" + key; HttpRequest request; HttpHeader authHeader = httpBasicAuthHeader("admin", "admin"); request.headers += authHeader; request.headers += httpCreateHeader("Content-Type", "application/json"); struct Assignee { string name; } struct Field { Assignee assignee; } struct UpdateInfo { Field fields; } UpdateInfo updateInfo; updateInfo.fields.assignee.name = "guest1"; httpPut(requestUrl, request, updateInfo);
See also