> ## Documentation Index
> Fetch the complete documentation index at: https://nango.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Prune records

> Prunes synced records for a given connection and model using cursor-based pagination.

**What is pruning:**
Pruning empties the record payload while preserving the record metadata.

**Cursor behavior:**
Records are pruned up to and including the specified cursor.

<Info>
  Requires an API key with the `environment:records:write` scope. [Learn more about API key scopes](/reference/backend/http-api/api-keys#scopes).
</Info>

Prunes synced records for a given connection and model using cursor-based pagination.

## What is pruning?

Pruning empties the record payload while preserving the record metadata.
This is useful for compliance requirements, ensuring Nango doesn't hold onto your records data while maintaining the ability to track record state. The payload can be restored by re-syncing the data.

<Tip>
  Pruning is not the same as marking a record as deleted from the external API.
  This endpoint prunes data from Nango’s cache only. It does not delete anything on the external API, and it is not the same as [detecting a deletion from the source](/guides/functions/syncs/deletion-detection).

  If you need to tell your customers that a record was deleted on the external API while keeping its last-known payload in cache, use `batchDelete` or `trackDeletesStart`/`trackDeletesEnd` in your sync functions instead.
</Tip>

## Cursor behavior

Records are pruned up to and including the specified `until_cursor` value. Use the `_nango_metadata.cursor` value from the record you want to prune up to.

## Response

<Tip>
  The `has_more` field indicates whether there are potentially more records to prune. When `true`, make another request with the same `until_cursor` to continue pruning. When `false`, all records up to the cursor have been pruned.
</Tip>

```json theme={null}
{
  "count": 150,
  "has_more": true
}
```


## OpenAPI

````yaml PATCH /records/prune
openapi: 3.1.0
info:
  title: Nango API
  description: Nango API specs used to authorize & sync data with external APIs.
  version: 1.0.0
servers:
  - url: https://api.nango.dev
    description: Production server
  - url: http://localhost:3003
    description: Local server
security:
  - bearerAuth: []
externalDocs:
  url: https://nango.dev/docs/reference/backend/http-api/authentication
paths:
  /records/prune:
    patch:
      summary: Prune records
      description: >-
        Prunes synced records for a given connection and model using
        cursor-based pagination.


        **What is pruning:**

        Pruning empties the record payload while preserving the record metadata.


        **Cursor behavior:**

        Records are pruned up to and including the specified cursor.
      parameters:
        - name: Connection-Id
          in: header
          required: true
          description: The connection ID used to create the connection.
          schema:
            type: string
        - name: Provider-Config-Key
          in: header
          required: true
          description: The integration ID used to create the connection (aka Unique Key).
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - until_cursor
              properties:
                model:
                  type: string
                  description: The data model to prune records from
                variant:
                  type: string
                  description: The variant of the model
                until_cursor:
                  type: string
                  description: >-
                    Prune all records up to and including this cursor. Use the
                    cursor value from _nango_metadata.cursor of the record you
                    want to prune up to.
                limit:
                  type: integer
                  minimum: 1
                  maximum: 10000
                  description: >-
                    The maximum number of records to prune in this request.
                    Defaults to 1000.
      responses:
        '200':
          description: Successfully pruned records
          content:
            application/json:
              schema:
                type: object
                required:
                  - count
                  - has_more
                properties:
                  count:
                    type: integer
                    description: The number of records pruned in this request
                    example: 150
                  has_more:
                    type: boolean
                    description: |-
                      Indicates if there are potentially more records to prune.
                      - `true`: There may be more records that need pruning
                      - `false`: All records up to the cursor have been pruned
                    example: true
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
components:
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/StdError'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/StdError'
  schemas:
    StdError:
      type: object
      additionalProperties: false
      properties:
        error:
          type: object
          additionalProperties: false
          required:
            - code
          properties:
            code:
              type: string
            message:
              type: string
            errors:
              type: array
              items:
                type: object
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: The secret key from your Nango environment.

````