# Documents

Source: https://swapcard.dev/content-api/examples/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](../graphql-event-api-schema/objects/document.mdx)

On this page you can:

- [Fetch the documents of an event](#fetch-the-first-hundred-documents).
- [Create](#create-event-document), [update](#update-event-document) and [delete](#delete-event-documents) event documents.
- [Create a document in a community or an event](#create-document), and choose whether Swapcard embeds or copies the file.
- [Update a document](#update-document).

## 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](/organizer/authentication).
- The ID of the event (`eventId`). See [Events](./graphql-event-api-examples-event.md).
- 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. |

```graphql title="Query"
query EventDocuments($eventId: ID!, $page: Int!) {
  event(id: $eventId) {
    documents(page: $page, pageSize: 100) {
      pageInfo {
        endCursor
        totalItems
      }
      results {
        description
        id
        name
        type
        url
      }
    }
  }
}
```

```json title="Variables"
{
  "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`. |

```graphql title="Mutation"
mutation CreateEventDocument($eventId: ID!, $document: CreateDocumentInput! ){
  createEventDocument(eventId: $eventId, document: $document) {
    description
    id
    name
    type
    url
  }
}
```

```json title="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.

| Argument | Description |
| --- | --- |
| `documentId` | The ID of the document to update, passed to the `id` argument. |
| `document` | The new details of the document. |

```graphql title="Mutation"
mutation UpdateEventDocument($document: UpdateDocumentInput!, $documentId: ID!) {
  updateEventDocument(document: $document, id: $documentId) {
    description
    id
    name
    type
    url
  }
}
```

```json title="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.

| 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. |

```graphql title="Mutation"
mutation DeleteEventDocument($eventId: ID!, $documentIds: [ID!]!) {
  deleteEventDocument(eventId: $eventId, ids: $documentIds)
}
```

```json title="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.

| 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. |

```graphql title="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
    }
  }
}
```

```json title="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](#create-document)).

| Argument | Description |
| --- | --- |
| `id` | The ID of the document to update. |
| `document` | The new details of the document. |

```graphql title="Mutation"
mutation UpdateDocument($document: UpdateDocumentInput!, $id: ID!) {
  updateDocument(document: $document, id: $id) {
    document {
      description
      id
      name
      type
      embeddedUrl
    }
    errors {
      code
      message
    }
  }
}
```

```json title="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"
  }
}
```
