Kuali GraphQL Documentation

Guides

Pull and push attachments

Pull attachments from a document and push them to your document management system.


Overview

In this example we're working with a simple application form. It includes a table which allows the submitter to attach one or more files. The table is labeled Supporting files. The GraphQL API provides a way to extract information about the attachments that are uploaded with a form.

Steps

Each file attachment can be downloaded and uploaded to a separate storage location.

  1. Use a document GraphQL query to get the data for a given document.
  2. Parse the returned json data for the table of attachments.
  3. Loop through the array of file attachments getting the temporaryUrl attribute.
  4. Use the temporaryUrl to download the file to a temporary location.
  5. Upload the file from the temporary location to the other storage location.

See below for examples of the GraphQL query and results.

Query

When a submitter submits a form, it creates a document with a unique id. You can use the id of that document to pull the document's data with a document GraphQL query.

      
        query ($id: ID!) {
  document(id: $id) {
    id
    data
  }
}

      
    

Variables

            
{"id":"63eff2b9b303222b5ef823d2"}
            
          

Results

Notice the -IecmNozS2 id, the unique id for the Supporting files table. Attached to that id is an array which provides information about each of the attached files. Each column in a table has an id. In this case the id for the attachment column is FoE9Eo3DJl.

Parse this json to extract a list of the attachments. Use the temporaryUrl attribute to create a url. Use that url to download each file to a temporary location and then upload that file to your document management system. Be prepared to handle the temporary url redirecting to a secure download url.

        
          {
            "data": {
              "document": {
                "id": "63eff2b9b303222b5ef823d2",
                "data": {
                  "-IecmNozS2": [
                    {
                      "FoE9Eo3DJl": null,
                      "_rowId": "IWlVfmOehO",
                      "_isFooter": true
                    },
                    {
                      "FoE9Eo3DJl": null,
                      "_rowId": "eu4WJ-WYJD"
                    },
                    {
                      "FoE9Eo3DJl": null,
                      "_rowId": "GV0173PjOB"
                    },
                    {
                      "FoE9Eo3DJl": null,
                      "_rowId": "S5BGoTDy5"
                    },
                    {
                      "FoE9Eo3DJl": {
                        "filename": "attachment.pdf",
                        "contentType": "application/pdf",
                        "filesize": 104256,
                        "retrievalId": "1a9c36d9-ea87-4326-9937-4771e5e17a1b",
                        "permaLink": "/app/forms/api/v2/files/perma/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyZXRyaWV2YWxJZCI6IjFhOWMzNmQ5LWVhODctNDMyNi05OTM3LTQ3NzFlNWUxN2ExYiIsImlhdCI6MTY3Nzk1MDIzOX0.EATaWW6xNR5ZhNrazGTrbc0tx0VlZDLbBMypWR61J-4",
                        "temporaryUrl": "/app/forms/api/v2/files/63eff258b303222b5ef82342/1a9c36d9-ea87-4326-9937-4771e5e17a1b"
                      },
                      "_rowId": "apJEn25wx"
                    },
                    {
                      "FoE9Eo3DJl": {
                        "filename": "test.xlsx",
                        "contentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                        "filesize": 6343,
                        "retrievalId": "85c156b7-c2b5-4925-adb3-a1fd49de4030",
                        "permaLink": "/app/forms/api/v2/files/perma/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyZXRyaWV2YWxJZCI6Ijg1YzE1NmI3LWMyYjUtNDkyNS1hZGIzLWExZmQ0OWRlNDAzMCIsImlhdCI6MTY3Nzk1MDIzOX0.9wUe4SHCCFsBC5BPks2DYYWBUAbkFM9CvXre2gQg5BA",
                        "temporaryUrl": "/app/forms/api/v2/files/63eff258b303222b5ef82342/85c156b7-c2b5-4925-adb3-a1fd49de4030"
                      },
                      "_rowId": "XcBEG9v1t"
                    }
                  ]
                }
              }
            }
          }