Default language.

Example of using the REST API to retrieve an attachment from a form


You can use the GET operation to retrieve an attachment for a particular entry. The following table lists details about this GET operation.

URL qualifier

/entry/{formName}/{entryId}/attach/{fieldName}

formName - The form for which an entry is to be created.
entryId - The entry ID.
fieldName - The name of an attachment field.

Method

GET

Header

Header

Value

Authorization

token

(Optional) X-AR-Client-Type

Client Type ID

(Optional) X-AR-RPC-Queue

RPC queue to which the client calls are routed

(Optional) X-AR-Timeout

Timeout (in seconds) for REST request

Default value —120 seconds

(Optional) X-AR-TR-Core-Id

The core ID in a trace ID

(Optional) X-AR-TR-Counter

The counter in a trace ID

(Optional) X-AR-Trace-Id

The complete trace ID

(Optional) X-AR-TR-Is-Counter-Locked

The lock counter

Returns

The attachment binary data is returned as Content-Type: application/octet-stream. Remedy AR System does not save the MIME types of attachment values, so the application/octet-stream is used to return arbitrary binary data.

All possible error codes

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 Error-handling-for-the-REST-API.

Important

REST API does not support attachments in Base64 mode.


The following example returns an entry with attachment.

Request URL

GET http://localhost:8008/api/arsys/v1/entry/AttachTest/000000000000001/attach/Attachment

Request header

Authorization: AR-JWT eyJhbGciOiJIUzI1NiJ9.
eyJleHAiOjE0MTc2NTM1ODgsInN1YiI6IkFsbGVuIiwibmJmIjoxNDE3NjQ5ODY4LCJpc3MiOi
JXLUNTRUlFUk9FLTI5LmFkcHJvZC5ibWMuY29tIiwianRpI
joiSURHQUFCRFVDMllHSUFONkJGUTJBQUFFUEZBNVFXIiwiX2NhY2hlSWQiOjQ3LCJpYXQiOjE0MTc2NDk5ODh9.
V4LGLcEdwD8V_I4rzoWYYSZmEMA82LBB_lEfz4Xnz9Y

Following is a sample code snippet for the GET operation with attachments.

package com.example;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;
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;

public class GetAttachment {

    public static void main(String[] args) throws Exception {
        String token = args[0];

       // start HTTP GET to get the attachment
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet(
               "http://localhost:8008/api/arsys/v1/entry/AttachTest/000000000000001/attach/Attachment");

       // add the token to the header
        httpGet.addHeader("Authorization", "AR-JWT " + token);

       // make the call and write to a file
       try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
            HttpEntity entity = response.getEntity();
            InputStream input = entity.getContent();

            File tempFile = File.createTempFile("screenshot", ".png");
           try (BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(
                    tempFile))) {
                IOUtils.copy(input, output);
                System.out.println("Attachment written to: " + tempFile);
            }
        }
    }

}

Response Body

HTTP/1.1 200 OK
Date: Wed, 03 Dec 2014 23:01:40 GMT
Content-Type: application/octet-stream
Server: Jetty(8.1.15.v20140411)
...
<binary data>

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*