Retrieving, updating, and deleting an entry using REST API
The following operations are available on the resource:
GET
The GET operation is used to get an entry from the form. The details of the GET operation are tabulated below:
Get single entry
Description | Get an entry from a particular form. | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
URL qualifier | /entry/{formName}/{entryId} formName - The form for which an entry is to be read. | ||||||||||
Method | GET | ||||||||||
Headers |
| ||||||||||
Parameters |
For more information, see Common parameters. | ||||||||||
Returns | An entry object. | ||||||||||
All possible error codes | If the request is not successful, one of the following error codes is returned: 400 - Request body is incorrect 403 - Forbidden 404 - Form does not exist 500 - Internal Server Error For more information, see HTTP status codes. | ||||||||||
Notes | The entry object will contain field values for all data fields to which the user has permission. |
Request URL
GET http://localhost:8008/api/arsys/v1/entry/SimpleForm/000000000000002
Request header
Authorization: AR-JWT eyJhbGciOiJIUzI1NiJ9.
eyJleHAiOjE0MTc2NTM1ODgsInN1YiI6IkFsbGVuIiwibmJmIjoxNDE3NjQ5ODY4LCJpc3MiOi
JXLUNTRUlFUk9FLTI5LmFkcHJvZC5ibWMuY29tIiwianRpI
joiSURHQUFCRFVDMllHSUFONkJGUTJBQUFFUEZBNVFXIiwiX2NhY2hlSWQiOjQ3LCJpYXQiOjE0MTc2NDk5ODh9.
V4LGLcEdwD8V_I4rzoWYYSZmEMA82LBB_lEfz4Xnz9Y
Response Body
HTTP/1.1 200 OK
Date: Wed, 03 Dec 2014 22:53:46 GMT
Content-Type: application/json
Server: Jetty(8.1.15.v20140411)
{
"values":{
"Request ID":"000000000000103",
"Submitter":"Allen",
"Create Date":"2014-12-03T22:53:37.000+0000",
"Assigned To":null,
"Last Modified By":"chris",
"Modified Date":"2014-12-03T22:53:37.000+0000",
"Status":"New",
"Short Description":"testing 123",
"Status History":{
"New":{
"user":"chris",
"timestamp":"2014-12-03T22:53:37.000+0000"
}
}
},
"_links":{
"self":[
{
"href":"http://localhost:8008/api/arsys/v1/entry/SimpleForm/000000000000103"
}
]
}
}
The following is a sample code snippet for the GET operation.
package com.example;
import java.nio.charset.StandardCharsets;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class Get {
public static void main(String[] args) throws Exception {
String token = args[0];
// start HTTP GET to get an entry
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(
"http://localhost:8008/api/arsys/v1/entry/SimpleForm/000000000000002");
// add the token to the header
httpGet.addHeader("Authorization", "AR-JWT " + token);
// make the call and print the status
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
HttpEntity entity = response.getEntity();
String jsonEntry = EntityUtils.toString(entity, StandardCharsets.UTF_8);
System.out.println(jsonEntry);
}
}
}
PUT
The PUT operation allows you to modify an entry on the form. The PUT operation also allows you to modify an attachment for a particular entry or from list of entries. The details of the PUT operation are tabulated below:
Update an entry
This operation updates a single entry on the form.
Description | This operation updates an entry on a form. | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
URL qualifier | /entry/{formName}/{entryId} formName - The form for which an entry is to be updated. | ||||||||||||||
Method | PUT | ||||||||||||||
Headers |
| ||||||||||||||
Request Body | An entry object in a JSON format | ||||||||||||||
Returns | HTTP status code 204 indicates a successful update. If the client sends If-Unmodified-Since and the entry is modified since that time, then the entry is not updated and status code 412 is returned. | ||||||||||||||
Errors | If the request is not successful, one of the following error codes are returned 400 - Request body is incorrect 403 - Forbidden 404 - Form does not exist 500 - Internal Server Error For more information, see HTTP status codes. |
The following example returns an updated entry in a Simple form.
Request URL
PUT http://localhost:8008/api/arsys/v1/entry/SimpleForm/000000000000002
Request headers
Authorization: AR-JWT eyJhbGciOiJIUzI1NiJ9.
eyJleHAiOjE0MTc2NTM1ODgsInN1YiI6IkFsbGVuIiwibmJmIjoxNDE3NjQ5ODY4LCJpc3MiOi
JXLUNTRUlFUk9FLTI5LmFkcHJvZC5ibWMuY29tIiwianRpI
joiSURHQUFCRFVDMllHSUFONkJGUTJBQUFFUEZBNVFXIiwiX2NhY2hlSWQiOjQ3LCJpYXQiOjE0MTc2NDk5ODh9.
V4LGLcEdwD8V_I4rzoWYYSZmEMA82LBB_lEfz4Xnz9Y
Content-Length: 59
Content-Type: application/json
Request Body
{
"values":{
"Submitter":"Allen",
"Short Description":"testing 123"
}
}
The following is a sample code snippet for the PUT operation.
package com.example;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
public class Put {
public static void main(String[] args) throws Exception {
String token = args[0];
// start HTTP PUT to modify an entry
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPut httpPut = new HttpPut(
"http://localhost:8008/api/arsys/v1/entry/SimpleForm/000000000000002");
// build the JSON entry
String json = "{ \"values\" : { ";
json += "\"Short Description\" : \"updated via REST\"";
json += " } }";
httpPut.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
httpPut.addHeader("Authorization", "AR-JWT " + token);
// make the call and print the status
try (CloseableHttpResponse response = httpClient.execute(httpPut)) {
StatusLine status = response.getStatusLine();
System.out.println(status);
}
}
}
Update an entry with attachments
Description | This operation updates an entry with an attachment. | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
URL qualifier | /entry/{formName}/{entryId} formName - The form for which an entry is to be updated. | ||||||||||||||
Method | PUT | ||||||||||||||
Headers |
| ||||||||||||||
Request Body | A multipart/form-data entity. Each part of a multipart entity has a name, a Content-Type and the value. There is one part named as entry with Content-Type as application/json and the value is a JSON entry. There are 0 or more parts with names like attach-{fieldName} with any Content-Type and any value. The name is a prefix indicating that it is an attachment binary data, the part after the hyphen is the name of the attachment field. This updates an entry with attachment data. | ||||||||||||||
Returns | HTTP status code 204 indicates a successful update. If the client sends If-Unmodified-Since and the entry is modified since that time, then the entry is not updated and status code 412 is returned. | ||||||||||||||
Errors | If the request is not successful, one of the following error codes are returned 400 - Request body is incorrect 403 - Forbidden 404 - Form does not exist 500 - Internal Server Error For more information, see HTTP status codes. |
DELETE
The DELETE operation allows you to delete an entry from a particular form. The details of the DELETE operation are tabulated below:
Description | Delete an entry from a particular form. | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
URL qualifier | /entry/{formName}/{entryId} formName - The form for which entry is to be deleted. | ||||||||||
Method | DELETE | ||||||||||
Headers |
| ||||||||||
Returns | No request body, but HTTP status 204 indicates successful deletion. | ||||||||||
All possible error codes | If the request is not successful, one of the following error codes are returned 403 - Forbidden 404 - Form does not exist 500 - Internal Server Error For more information, see HTTP status codes. | ||||||||||
Notes | You can also use the option FORCE to force delete all the list of entries, for example, ?options=FORCE |
The following example allows you to delete an entry from the form.
Request URL
DELETE http://localhost:8008/api/arsys/v1/entry/SimpleForm/000000000000002
Request header
Authorization: AR-JWT eyJhbGciOiJIUzI1NiJ9.
eyJleHAiOjE0MTc2NTM1ODgsInN1YiI6IkFsbGVuIiwibmJmIjoxNDE3NjQ5ODY4LCJpc3MiOi
JXLUNTRUlFUk9FLTI5LmFkcHJvZC5ibWMuY29tIiwianRpI
joiSURHQUFCRFVDMllHSUFONkJGUTJBQUFFUEZBNVFXIiwiX2NhY2hlSWQiOjQ3LCJpYXQiOjE0MTc2NDk5ODh9.
V4LGLcEdwD8V_I4rzoWYYSZmEMA82LBB_lEfz4Xnz9Y
Response Body
HTTP/1.1 204 No Content
Date: Wed, 03 Dec 2014 22:38:14 GMT
Server: Jetty(8.1.15.v20140411)
The following is a sample code snippet for the DELETE operation.
package com.example;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
public class Delete {
public static void main(String[] args) throws Exception {
String token = args[0];
// start HTTP DELETE to delete an entry
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpDelete httpDelete = new HttpDelete(
"http://localhost:8008/api/arsys/v1/entry/SimpleForm/000000000000002");
// add the token to the header
httpDelete.addHeader("Authorization", "AR-JWT " + token);
// make the call and print the status
try (CloseableHttpResponse response = httpClient.execute(httpDelete)) {
StatusLine status = response.getStatusLine();
System.out.println(status);
}
}
}
Comments
Hi, Can we do a PUT by search ?
Example:
Search incident Number INC002312425768 and update it. Please not Incident number is not a request ID field.
URL: https://servername:8443/api/arsys/v1/entry/HPD:IncidentInterface/?q=%27Incident%20Number%27%20%3D%20%22INC000012425768%22
Hello Vara,
We are working on your query. We will respond soon.
Regards,
Anagha
Hello Vara,
You cannot use Put by search.
Regards,
Anagha
Can i delete multiple entries with single REST call ? In above example for delete its only mentioned for one request id. Could you please give more details on how to delete multiple entries with single request.
You can't. This is a REST interface. And the standard DELETE requires the unique reference and in this case, it's the requesId: https://restfulapi.net/http-methods/#delete Therefore, you would have to use a GET with a query parameter to get the list to delete, then iterate over that list, calling DELETE for each one.
Log in or register to comment.