> For the complete documentation index, see [llms.txt](https://docs.pyck.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pyck.cloud/graphql-api/queries/attachments.md).

# Attachments

attachments Query

Audience: Programmer

Retrieves a paginated list of attachments with support for filtering and ordering. This query returns all attachments across the system that the user has access to.

## Arguments

| Name      | Type                   | Description                                                          |
| --------- | ---------------------- | -------------------------------------------------------------------- |
| `after`   | `Cursor`               | Returns elements after the specified cursor for forward pagination   |
| `first`   | `Int`                  | Returns the first n elements from the list                           |
| `before`  | `Cursor`               | Returns elements before the specified cursor for backward pagination |
| `last`    | `Int`                  | Returns the last n elements from the list                            |
| `orderBy` | `AttachmentOrder`      | Ordering options for the returned attachments                        |
| `where`   | `AttachmentWhereInput` | Filtering criteria for the attachments                               |

## Return Type

`AttachmentConnection!` - A Relay-style connection containing:

* `edges`: Array of attachment edges with cursor information
* `nodes`: Array of attachment objects
* `pageInfo`: Information about pagination (hasNextPage, hasPreviousPage, etc.)
* `totalCount`: Total number of attachments matching the filter

## Usage Example

### GraphQL Query

```graphql
query GetAttachments($first: Int!, $where: AttachmentWhereInput) {
  attachments(first: $first, where: $where) {
    edges {
      node {
        id
        filename
        contentType
        size
        url
        createdAt
        updatedAt
      }
      cursor
    }
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
    totalCount
  }
}
```

### Query Variables

```json
{
  "first": 20,
  "where": {
    "contentType": {
      "startsWith": "image/"
    }
  }
}
```

### JavaScript Example

```javascript
const getAttachments = async (limit = 20, filters = {}) => {
  const query = `
    query GetAttachments($first: Int!, $where: AttachmentWhereInput) {
      attachments(first: $first, where: $where) {
        edges {
          node {
            id
            filename
            contentType
            size
            url
            createdAt
          }
          cursor
        }
        pageInfo {
          hasNextPage
          endCursor
        }
        totalCount
      }
    }
  `;

  const response = await fetch('/graphql', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${accessToken}`
    },
    body: JSON.stringify({
      query,
      variables: { 
        first: limit,
        where: filters
      }
    })
  });

  const { data } = await response.json();
  return data.attachments;
};

// Get all image attachments
const images = await getAttachments(20, {
  contentType: { startsWith: "image/" }
});

// Get attachments created in the last week
const recent = await getAttachments(10, {
  createdAt: { 
    gte: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString()
  }
});
```

## Filtering Options

The `where` parameter supports various filtering options:

```javascript
// Filter by content type
{
  contentType: { 
    equals: "application/pdf",
    startsWith: "image/",
    in: ["image/jpeg", "image/png"]
  }
}

// Filter by filename
{
  filename: {
    contains: "report",
    startsWith: "invoice_"
  }
}

// Filter by file size
{
  size: {
    gte: 1024,      // Greater than or equal to 1KB
    lte: 10485760   // Less than or equal to 10MB
  }
}

// Filter by creation date
{
  createdAt: {
    gte: "2024-01-01T00:00:00Z",
    lte: "2024-12-31T23:59:59Z"
  }
}
```

## Ordering Options

Sort attachments using the `orderBy` parameter:

```javascript
// Sort by creation date (newest first)
{ createdAt: "DESC" }

// Sort by filename (alphabetical)
{ filename: "ASC" }

// Sort by file size (largest first)
{ size: "DESC" }
```

## Related

* [nodeAttachments Query](/graphql-api/queries/nodeattachments.md)
* [Attachment Type](https://github.com/pyck-ai/docs/blob/main/graphql/types/Attachment.md)
* [File Management Guide](https://github.com/pyck-ai/docs/blob/main/development/file-management.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.pyck.cloud/graphql-api/queries/attachments.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
