Uploading presentation documents
The GraphQL API supports presentation documents in the createPresentation
and updatePresentation
mutations.
Prerequisites
Please make sure you take the time to get familiar with uploading files before continuing.
Overview
To upload new presentation documents, the process is:
- Upload a new file through the dedicated endpoint, which will return a temporary file identifier.
- Use that identifier in the mutation.
Create presentation
Documents can be passed through the CreatePresentationInput.attachedDocuments
input field, which is an array of CreatePresentationAttachedDocumentInput
.
Please note that at this stage, only attached documents of type IMAGE
, PDF
, or UPLOADED_DOCUMENT
are supported.
Get document types
You can issue a query to get the available document types for an event.
query PresentationDocumentTypes {
event(id: "<event-id>") {
setup {
presentation {
documentTypes {
id
name
format
}
}
}
}
}
A sample response might look like:
{
"data": {
"event": {
"setup": {
"presentation": {
"documentTypes": [
{
"id": "01E33D09-75C1-472A-A2A4-75B54D66D764",
"name": "Uploaded document",
"format": "UPLOADED_DOCUMENT"
},
{
"id": "2EA464C9-89EA-4C3E-96F6-F4FD6D22B1C8",
"name": "Image",
"format": "IMAGE"
}
]
}
}
}
}
}
The identifiers of the document types will be used in the mutation to create a presentation with attached documents.
Issue mutation
The following is an example mutation operation that creates a presentation and attaches two documents using the document type identifiers (obtained above) and temporary file identifiers (obtained by uploading files):
mutation CreatePresentationWithAttachedFile {
createPresentation(
input: {
eventId: "<event-id>"
presenterId: "<contact-id>"
title: "Uploading documents with GraphQL"
attachedDocuments: [
{
documentTypeId: "01E33D09-75C1-472A-A2A4-75B54D66D764"
temporaryFileId: "<file-id-1-obtained-through-dedicated-endpoint>"
notes: "<optional-notes>"
}
{
documentTypeId: "2EA464C9-89EA-4C3E-96F6-F4FD6D22B1C8"
temporaryFileId: "<file-id-2-obtained-through-dedicated-endpoint>"
notes: "<optional-notes>"
}
]
}
) {
presentation {
id
documents {
... on ImageDocument {
originalFilename
url
notes
type {
id
name
format
}
}
... on UploadedDocumentDocument {
originalFilename
url
notes
type {
id
name
format
}
}
}
}
}
}
The response will contain the original name of the file that was uploaded, along with the file's URL.
Update presentation
When updating a presentation, you may want to add new documents, and update or remove existing ones.
Similar to the create operation, this can be achieved through the UpdatePresentationInput.attachedDocuments
input field, which is an array of UpdatePresentationAttachedDocumentInput
.
However, different operations will require different fields to be specified. We will go through them individually, however be aware that all these actions can be performed in a single mutation.
The notes
input field is always optional and will be omitted from the next samples for brevity.
Add a new document
This is similar to the create presentation mutation, we need to pass in the document type identifier and the temporary file identifier.
mutation UpdatePresentationWithAttachedFile {
updatePresentation(
input: {
eventId: "<event-id>"
presentationId: "<presentation-id>"
title: "Uploading documents with GraphQL"
attachedDocuments: [{ documentTypeId: "<document-type-id>", temporaryFileId: "<file-id>" }]
}
) {
presentation {
id
documents {
... on ImageDocument {
originalFilename
url
notes
type {
id
name
format
}
}
... on UploadedDocumentDocument {
originalFilename
url
notes
type {
id
name
format
}
}
}
}
}
}
Update an existing document
In this case, only the identifier of the document type associated with the existing attached document needs to be passed. While attached documents have their own identifiers, we use the associated document type ID to identify them, since a document type can be associated with at most one attached document.
The file associated with the attached document can be replaced with the temporaryFileId
input field, and the notes with the notes
input field.
mutation UpdatePresentationWithAttachedFile {
updatePresentation(
input: {
eventId: "<event-id>"
presentationId: "<presentation-id>"
title: "Uploading documents with GraphQL"
attachedDocuments: [{ documentTypeId: "<document-type-id>", temporaryFileId: "<new-file-id>" }]
}
) {
presentation {
id
documents {
... on ImageDocument {
originalFilename
url
notes
type {
id
name
format
}
}
... on UploadedDocumentDocument {
originalFilename
url
notes
type {
id
name
format
}
}
}
}
}
}
Remove an existing document
To remove an attached document, omit it from the attachedDocuments
array.
For example, given an existing presentation with two documents represented as below:
{
"data": {
"createPresentation": {
"presentation": {
"id": "<presentation-id>",
"documents": [
{
"originalFilename": "<original-file-name>",
"url": "<file-url>",
"type": {
"id": "11111111-1111-1111-1111-111111111111"
}
},
{
"originalFilename": "<original-file-name>",
"url": "<file-url>",
"type": {
"id": "22222222-2222-2222-2222-222222222222"
}
}
]
}
}
}
}
To remove the second file, the following mutation can be issued — note only the ID of the document type of the first attached document identifier is present in the attachedDocuments
input field.
mutation UpdatePresentationWithAttachedFile {
updatePresentation(
input: {
eventId: "<event-id>"
presentationId: "<presentation-id>"
attachedDocuments: [{ documentTypeId: "11111111-1111-1111-1111-111111111111" }]
}
) {
presentation {
id
documents {
... on ImageDocument {
id
originalFilename
url
notes
type {
id
name
format
}
}
... on UploadedDocumentDocument {
id
originalFilename
url
notes
type {
id
name
format
}
}
}
}
}
}
Putting it all together
Let us imagine an existing presentation:
{
"data": {
"createPresentation": {
"presentation": {
"id": "<presentation-id>",
"documents": [
{
"originalFilename": "<original-file-name>",
"url": "<file-url>",
"type": {
"id": "11111111-1111-1111-1111-111111111111"
}
},
{
"originalFilename": "<original-file-name>",
"url": "<file-url>",
"type": {
"id": "22222222-2222-2222-2222-222222222222"
}
}
]
}
}
}
}
And we want to make the following changes:
- Remove the first attached document.
- Update the second document.
- Add a new document.
The mutation would look as follows:
mutation UpdatePresentationWithAttachedFile {
updatePresentation(
input: {
eventId: "<event-id>"
presentationId: "<presentation-id>"
attachedDocuments: [
# We do not specify the attached document with the document type id 11111111-1111-1111-1111-111111111111, so it's removed
# We specify the document type ID of the second attached document identifier, with the desired changes
{ documentTypeId: "22222222-2222-2222-2222-222222222222", temporaryFileId: "<new-file-id-1>" }
# We add a new attached document
{ documentTypeId: "<other-document-type-id>", temporaryFileId: "<new-file-id-2>" }
]
}
) {
presentation {
id
documents {
... on ImageDocument {
id
originalFilename
url
notes
type {
id
name
format
}
}
... on UploadedDocumentDocument {
id
originalFilename
url
notes
type {
id
name
format
}
}
}
}
}
}