---
category: [Administration & Integrations, Platform and Product Extensions, Platform and Product Extensions/Integration, Administration & Integrations/Custom Integrations & Apps, Platform and Product Extensions/Workday Extend]
keyword: [Extend, Workday Graph API, Graph API, GraphQL]
nav: wcp_docs
parent_url: /wcp_docs/
title: Download Files with Graph API
layout: subsection
---

### Prerequisites

-   A view or edit page for downloading file attachments.
-   A Graph API query whose return data type includes the `downloadID` of the files attached to the business object.


### Context

You can use a Graph API query and the the Attachments REST API with the [fileUploader](/wcp_docs/icc1518036830536.html) widget to download file attachments. Here are things to consider:

-   You’ll need to run a query that returns the `downloadID` of the file attachments. Use a data source filter or where clause to get the file attachment instances. The query must return these fields:

    -   downloadID
    -   descriptor containing the filename
    -   contentType

-   Call the Attachments REST API to download each file using its `downloadID`, which has a 1-hour expiration.
-   In the `fileUploader` tag, specify the `on` attribute using the Graph API endpoint and field path to the data collection containing the file attachment fields.
-   Use the `attachmentList` in the `fileUploaderRow` to call the Attachments REST API.


In this procedure, we’ll use these samples:

-   An app named <i>myApp</i> containing a sample <i>Logo</i> model attachment object.
-   The app’s corresponding <i>myApp_Logo</i> query. The input logos field is an object collection that includes the `attachmentContent` field of the `File` type.
-   A flow definition in the AMD that passes the flow variable containing a list of uploaded file attachments from a previous page in the flow. See the sample flow definition and upload page in the <i>Example</i> section of [Upload Files with Graph API](/wcp_docs/GUID-82f497c2-062b-4768-b56f-6d27c43b9ff9-enHYPHENus.html).


### Steps

1.  Build the query that gets the file attachments.

    Example: This sample query gets the logo file attachments using a where filter.

    ```
    query myApp_Logo($myApp_Logo_where: MyApp_Logo_Criteria) {
    myApp_Logo(dataSource: { myApp_logos: {} }, where: $myApp_Logo_where) {
     data {
       contentType
       descriptor
       downloadID
     }
    }
    }
    ```

2.  Build the query variables.

    Example: This sample variable is the where filter that contains the attachment Workday IDs.

    ```
    {
    "myApp_Logo_where": {
     "workdayID": {
       "in": [
         {
           "id": "5743e501a36a81002ab6735f26670001",
           "type": "WID"
         },
         {
           "id": "5743e501a36a81002ab6735f26670002",
           "type": "WID"
         }
       ]
     }
    }
    }
    ```

3.  Submit the query.

    Example: This sample mutation response displays the Workday ID of the new file attachment object.

    ```
    {
    "data": {
     "myApp_Logo": {
       "data": [
         {
           "contentType": "image/jpeg",
           "descriptor": "spcaLogo.jpg",
           "downloadID": "VjBSRFF6RXVNSUVBRVFBQURHcGdJZE5vakdrNHc0ZGpQZ0FBakFBV0FURUFFQUwwK2dZN2pQZlFiZHMxbnVjWFhTQUFBQUQvb282Q3kweDhTUisyOEhyUVpzM0R0dks5RU1KQVdPMWdlY2FLdTZ2NnJCcDlWcnp1SUMva0JLdllvRUw1OTBid2ZCbGNubnNEOE9rTVZTY1hGWlZGY2NYbi9PMjYzRTA9"
         },
         {
           "contentType": "image/png",
           "descriptor": "ebspca.png",
           "downloadID": "VjBSRFF6RXVNSUVBRVFBQURNb3psbFNJeEs3MzlncVU1Z0FBakFBV0FURUFFSGhJdlJKcHNtMVhrQU5BR0RQOS8zQUFBQURIRzZKV2k4d0d1NnJ0U1liREJ3RU8wOTJlTDJxUmxpT2dNc05RSGROSk5QWDdyVGpUUzh4NXRUTXZBaUlGV25tL2NSR3Jibk5RMVNGTW5YRHV1Q1NyTW96QkswQ3RLUkk9"
         }
       ]
     }
    }
    }
    ```

4.  In App Builder, create a Graph Query component.

    Example: This sample <i>getLogos</i> Graph Query component contains the <i>myApp_Logo</i> query.

    ```
    {
    "id": "getLogos",
    "query": "
       query myApp_Logo(
          $myApp_Logo_where: MyApp_Logo_Criteria) {
       myApp_Logo(
         dataSource: {myApp_logos:{}},
         where: $myApp_Logo_where)
       {
         data {
           contentType
           descriptor
           downloadID
         }
       }
     }
    "  
    }
    ```

5.  In the AMD of the app, add the Graph API data provider.

    Example:

    ```
    {
    "key": "workday-graphql",
    "value": "https://api.workday.com/graphql/v1/"
    }
     
    ```

6.  In the page (using Code mode), add the inbound endpoint that calls Graph API with the query and variables.

    Specify the `graphQuery` attribute with these properties:

    -   `queryId`: The `id` of the Graph Query component containing the query that gets the file attachments.
    -   `variables`: The JSON map containing the variables.

    Example: This sample inbound endpoint submits the Graph API query that gets the file attachments. In this example, the variables include the hard-coded values used from testing the mutation in a client tool such as the Graph API Explorer. We'll replace the hard-coded values after we add the `fileUploader` in the next step.

    ```
    "endPoints": [
    {
     "name": "getAttachments",
     "httpMethod": "POST",
     "authType": "sso",
     "baseUrlType": "workday-graphql",
     "graphQuery": {
       "queryId": "getLogos",
       "variables": {
         "myApp_Logo_where": {
           "workdayID": {
             "in": [
               {
                 "id": "b7d09523f06c810015d3ae3d4f110000",
                 "type": "WID"
               },
               {
                 "id": "b7d09523f06c810015d3ad08374d0001",
                 "type": "WID"
               }
             ]
           }
         }
       }
     },
     "failOnStatusCodes": [
       {
         "code": "400"
       }
     ]
    }
    ]
    ```

7.  In the `graphQuery.variables` attribute, replace the hard-coded Workday ID values.

    Use the saved WorkdayID values from the mutation that created the file attachment instances. In the upload example, we saved them in the <i>logos</i> flow variable. Note that the field path of the id value in the model attachment mutation response is `WorkdayID.id`.

    Example: This sample where variable gets the saved WorkdayID values in <i>flowVariables.logos</i>.

    ```
    "myApp_Logo_where": {
    "workdayID": {
     "in": "<% flowVariables.logos.map(logo => {
       {
           'id': logo.workdayID.id,
           'type': 'WID'
       }
    }) %>"
    }
    }
    ```

8.  Add the `fileUploader` tag to the page.

    In the `on` attribute of the `loop` tag, specify the field path to the query data containing the file attachment fields. In the `as` attribute, specify a variable name such as “<i>file</i>”.

    In the `attachmentList` within the `fileUploaderRow`, specify these attributes:

    -   `attachmentURL`: The Attachments REST API with the downloadID.
    -   `attachmentName`: The descriptor field from the query response.
    -   `fileName`: The descriptor field from the query response.
    -   `fileType`: The contentType from the query response.

    See the `fileUploader` tag in the <b>Example</b> section.



### Example

This sample PMD is a view page containing the Graph API inbound endpoint with the `getAttachments` query. This page also contains the `fileUploader` that uses the `attachmentList`, which displays the file attachments and allows users to download them. This sample assumes a script module,<i>fileTypes.script</i>, which contains the Workday IDs of the mime types. (You can get this script from the Charitable Donations sample app.)

```
{
"id": "downloadLogos",
"include": [
 "fileTypes.script"
],
"endPoints": [
 {
     "name": "getAttachments",
     "httpMethod": "POST",
     "authType": "sso",
     "baseUrlType": "workday-graphql",
     "graphQuery": {
       "queryId": "getLogos",
       "variables": {
         "myApp_Logo_where": {
           "workdayID": {
             "in": "<% flowVariables.logos.map(logo => {
               {
                   'id': logo.workdayID.id,
                   'type': 'WID'
               }
           }) %>"
           }
         }
       }
     },
     "failOnStatusCodes": [
       {
         "code": "400"
       }
     ]
   }
],
"presentation": {
 "title": {
   "type": "title",
   "label": "Get Logos"
 },
 "body": {
   "type": "section",
   "horizontal": true,
   "children": [
     {
       "type": "section",
       "children": [
         {
           "type": "section",
           "horizontal": false,
           "children": [
             {
               "type": "fileUploader",
               "label": "Logos:",
               "id": "myFileUploader",
               "enabled": "false",
               "fileTypes": "png,jpeg,jpg,pdf,doc",
               "singular": false,
               "children": [
                 {
                   "type": "loop",
                   "on": "<% getAttachments.data.myApp_Logo.data %>",
                   "as": "file",
                   "children": [
                     {
                       "type": "fileUploaderRow",
                       "render": "<% !(empty file.descriptor) %>",
                       "attachment": {
                         "type": "attachmentList",
                         "attachmentURL": "https://api.workday.com/attachments/v1/graphql/<% file.downloadID %>"  ,
                         "attachmentAuth": "sso",
                         "attachmentName": "<% file.descriptor %>",
                         "attachmentUriTemplate": "[Target]",
                         "instanceList": [
                           {
                             "action": "attachment",
                             "descriptor": "<% file.descriptor%>",
                             "mimeType": "<% fileType:getFileType(file.descriptor) %>"
                           }
                         ]
                       },
                       "fileName": "<% file.descriptor%>",
                       "fileType": "<% fileTypes.getMimeTypeIDbyContentType(file.contentType) %>"
                     }
                   ]
                 }
               ],
               "fileUploaderRowTemplate": [ ]
             }
           ]
         }            
       ]
     }
   ]
 }
}
}
```

### Related Information

[Graph API Attachments](/wcp_docs/GUID-f55baa31-61f8-441e-bd0a-2482ad551254-enHYPHENus.html)

[Upload Files with Graph API](/wcp_docs/GUID-82f497c2-062b-4768-b56f-6d27c43b9ff9-enHYPHENus.html)

