Skip to main content
View as Markdown

Documents

Fetch, create, update and delete the documents of an event or a community.

Swapcard supports these document formats:

  • Documents: .doc and .docx
  • Presentations: .ppt and .pptx
  • Images: .png and .jpg
  • PDF files

When you import a document, Swapcard associates a URL with the file. Users open this URL to download or display the document.

Reference: Document object

On this page you can:

Before you begin​

  • An API key, sent in the Authorization header. The key acts with the roles and permissions of the user who created it. See Authentication.
  • The ID of the event (eventId). See Events.
  • To create a document in a community, the ID of the community (communityId).

Fetch the first 100 documents​

Use the event query with the documents field to fetch the documents of an event. The field is paginated by page: page sets the page number and pageSize the number of documents per page (100 here).

ArgumentDescription
eventIdThe ID of the event.
pageThe page number, starting at 1 in this example.
Query
query EventDocuments($eventId: ID!, $page: Int!) {
event(id: $eventId) {
documents(page: $page, pageSize: 100) {
pageInfo {
endCursor
totalItems
}
results {
description
id
name
type
url
}
}
}
}
Variables
{
"eventId": "RXZlbnRfMQ==",
"page": 1
}

Create an event document​

Use the createEventDocument mutation to create a document in an event.

ArgumentDescription
eventIdThe ID of the event where you create the document.
documentThe details of the document: name, url and description.
Mutation
mutation CreateEventDocument($eventId: ID!, $document: CreateDocumentInput! ){
createEventDocument(eventId: $eventId, document: $document) {
description
id
name
type
url
}
}
Variables
{
"eventId": "RXZlbnRfNTUxMDI0",
"document": {
"name": "test-document",
"url": "https://www.testdocument.com/links/TestPDFfile.pdf",
"description": "this is a test document"
}
}

Update an event document​

Use the updateEventDocument mutation to update a document of an event.

ArgumentDescription
documentIdThe ID of the document to update, passed to the id argument.
documentThe new details of the document.
Mutation
mutation UpdateEventDocument($document: UpdateDocumentInput!, $documentId: ID!) {
updateEventDocument(document: $document, id: $documentId) {
description
id
name
type
url
}
}
Variables
{
"documentId":"RG9jdW1lbnRfNTY1Mzky",
"document": {
"name": "test-document-update",
"url": "https://www.testdocument.com/links/UpdatedTestPDFfile.pdf",
"description": "this is an updated test document"
}
}

Delete event documents​

Use the deleteEventDocument mutation to delete one or more documents from an event.

ArgumentDescription
eventIdThe ID of the event that contains the documents.
documentIdsArray of the IDs of the documents to delete, passed to the ids argument.
Mutation
mutation DeleteEventDocument($eventId: ID!, $documentIds: [ID!]!) {
deleteEventDocument(eventId: $eventId, ids: $documentIds)
}
Variables
{
"eventId": "RXZlbnRfNTUxMDI0",
"documentIds":["RG9jfNTY1Mzky","RG9jdW1lbnRMzky"]
}

Create a document in a community or an event​

Use the createDocument mutation to create a document in a community, and optionally in one of its events.

ArgumentDescription
communityIdRequired. The ID of the community where you create the document.
eventIdOptional. The ID of the event where you create the document.
documentThe details of the document, including actionType.

document.actionType sets how Swapcard handles the file at document.url:

ValueBehavior
EMBED_URLDefault when you omit actionType. Swapcard retrieves the media from the URL you provide, returned in document.embeddedUrl.
UPLOAD_URLSwapcard copies the document from the URL to its CDN. document.embeddedUrl is then null: to get a URL for the file, generate a presigned URL with the getMediaDocumentUrl mutation.
Mutation
mutation CreateDocument($communityId: ID!, $eventId: ID, $document: CreateDocumentInput! ){
createDocument(communityId: $communityId, document: $document, eventId: $eventId) {
document {
description
id
name
type
embeddedUrl
}
errors {
code
message
}
}
}
Variables
{
"communityId": "Q29tbXVuaXR5XzEyMw==",
"eventId": "RXZlbnRfNTUxMDI0",
"document": {
"name": "test-document",
"url": "https://www.testdocument.com/links/TestPDFfile.pdf",
"description": "this is a test document",
"actionType": "UPLOAD_URL"
}
}

Update a document​

Use the updateDocument mutation to update a document. The example also sets document.actionType (see Create a document in a community or an event).

ArgumentDescription
idThe ID of the document to update.
documentThe new details of the document.
Mutation
mutation UpdateDocument($document: UpdateDocumentInput!, $id: ID!) {
updateDocument(document: $document, id: $id) {
document {
description
id
name
type
embeddedUrl
}
errors {
code
message
}
}
}
Variables
{
"id":"RG9jdW1lbnRfNTY1Mzky",
"document": {
"name": "test-document-update",
"url": "https://www.testdocument.com/links/UpdatedTestPDFfile.pdf",
"description": "this is an updated test document",
"actionType": "EMBED_URL"
}
}