This documentation supports the 19.02 version of Remedy Action Request System.

To view the latest version, select the version from the Product version menu.

Retrieving an attachment using REST API

The following operation is available on the resource:

Get an attachment

This operation retrieves an attachment for a particular entry.

DescriptionGets an attachment's binary data
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.

MethodGET
Header
HeaderValue
Authorizationtoken
(optional) X-AR-Client-TypeClient Type ID
(optional) X-AR-RPC-QueueRPC queue to which the client calls are routed
(optional) X-AR-Timeout

Timeout (in seconds) for REST request

Default value —120 seconds

ReturnsThe attachment binary data is returned as Content-Type: application/octet-stream. The BMC 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 HTTP status codes.

    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

    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>


    The 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);
                }
            }
        }
    
    }

    Related topics

    Was this page helpful? Yes No Submitting... Thank you

    Comments

    1. Stefan Srbljanin

      I could not find any information how to access Attachments that are on HPD:WorkLog form. When trying to get data with link: "http://localhost:8008/api/arsys/v1/entry/HPD%3AWorkLog/WLG000000000101/attach/Attachment%201"); I get error: [{"messageType":"ERROR","messageText":"Field does not exist on current form","messageNumber":314,"messageAppendedText":"schema HPD:WorkLog, fieldName Attachment 1"}]

      Aug 04, 2020 08:27
    2. Stefan Srbljanin

      The issue was in the link I used. I got the correct link by running a REST GET on HPD:WorkLog form and in the list of attributes I got a 'href' attribute associated with attachment in question. The correct link is: http://localhost:8008/api/arsys/v1/entry/HPD:WorkLog/WLG000000000101/attach/z2AF%20Work%20Log01 Where field needed is: z2AF%20Work%20Log01

      Aug 05, 2020 02:51
      1. Anagha Deshpande

        Hello Stefan,

        Thanks for the confirmation.

        Regards,

        Anagha

        Aug 05, 2020 04:31
    3. Yousef Bayari

      The response will have the file binary , how can we retrieve the file name ?

      Aug 14, 2020 09:51
      1. Anagha Deshpande

        Hello Yousef,

        If you are using the Postman client, you can see the file name under the Header tab in the Content-Disposition row.

        Hope this helps.

        Regards,

        Anagha

        Aug 19, 2020 06:11