Documents
Fetch, create, update and delete the documents of an event or a community.
Swapcard supports these document formats:
- Documents:
.docand.docx - Presentations:
.pptand.pptx - Images:
.pngand.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:
- Fetch the documents of an event.
- Create, update and delete event documents.
- Create a document in a community or an event, and choose whether Swapcard embeds or copies the file.
- Update a document.
Before you begin
- An API key, sent in the
Authorizationheader. 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).
| Argument | Description |
|---|---|
eventId | The ID of the event. |
page | The page number, starting at 1 in this example. |
query EventDocuments($eventId: ID!, $page: Int!) {
event(id: $eventId) {
documents(page: $page, pageSize: 100) {
pageInfo {
endCursor
totalItems
}
results {
description
id
name
type
url
}
}
}
}
{
"eventId": "RXZlbnRfMQ==",
"page": 1
}
Create an event document
Use the createEventDocument mutation to create a document in an event.
| Argument | Description |
|---|---|
eventId | The ID of the event where you create the document. |
document | The details of the document: name, url and description. |
mutation CreateEventDocument($eventId: ID!, $document: CreateDocumentInput! ){
createEventDocument(eventId: $eventId, document: $document) {
description
id
name
type
url
}
}
{
"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.
| Argument | Description |
|---|---|
documentId | The ID of the document to update, passed to the id argument. |
document | The new details of the document. |
mutation UpdateEventDocument($document: UpdateDocumentInput!, $documentId: ID!) {
updateEventDocument(document: $document, id: $documentId) {
description
id
name
type
url
}
}
{
"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.
| Argument | Description |
|---|---|
eventId | The ID of the event that contains the documents. |
documentIds | Array of the IDs of the documents to delete, passed to the ids argument. |
mutation DeleteEventDocument($eventId: ID!, $documentIds: [ID!]!) {
deleteEventDocument(eventId: $eventId, ids: $documentIds)
}
{
"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.
| Argument | Description |
|---|---|
communityId | Required. The ID of the community where you create the document. |
eventId | Optional. The ID of the event where you create the document. |
document | The details of the document, including actionType. |
document.actionType sets how Swapcard handles the file at document.url:
| Value | Behavior |
|---|---|
EMBED_URL | Default when you omit actionType. Swapcard retrieves the media from the URL you provide, returned in document.embeddedUrl. |
UPLOAD_URL | Swapcard 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 CreateDocument($communityId: ID!, $eventId: ID, $document: CreateDocumentInput! ){
createDocument(communityId: $communityId, document: $document, eventId: $eventId) {
document {
description
id
name
type
embeddedUrl
}
errors {
code
message
}
}
}
{
"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).
| Argument | Description |
|---|---|
id | The ID of the document to update. |
document | The new details of the document. |
mutation UpdateDocument($document: UpdateDocumentInput!, $id: ID!) {
updateDocument(document: $document, id: $id) {
document {
description
id
name
type
embeddedUrl
}
errors {
code
message
}
}
}
{
"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"
}
}