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

# Get a free preview

> Return the first pages of a PDF book as an inline PDF.

## Request

```http theme={null}
GET /digital-products/6702c1a4e1b3a40012cd2001/preview
x-shop-id: {{shopId}}
```

## Headers

| Header | Type | Description |
| - | - | - |
| `x-shop-id` | string | Identify the shop context. |

## Path parameters

| Parameter | Type | Description |
| - | - | - |
| `id` | string | The digital product id. |

<Note>
  Public, like `/products`: no sign-in is needed. Show a "Read a sample" button only when the item's `preview.available` is `true` (see [List products](/api-reference/endpoint/products/get-all)).
</Note>

## What the preview contains

* The first **N pages** of the book, where N is the seller's setting (default 3, between 1 and 20) but **never more than half of the book** and at least one. A book of fewer than two pages has no preview.
* A footer on every page, for example `Preview: first 3 of 120 pages`.
* Only the chosen pages: the rest of the book is not hidden inside the file, it is simply not there.
* PDFs only, up to 60 MB. The result is cached for an hour.

## Successful response

`200` with `Content-Type: application/pdf`, `Content-Disposition: inline; filename="the-lagos-cookbook-preview.pdf"` and `Cache-Control: public, max-age=300`. The body is the PDF, so open it in a new tab or an embedded viewer.

## Error responses

Errors are JSON. A `404` carries a `code`:

| `code` | Meaning |
| - | - |
| `not_found` | No such listed book in this store. |
| `no_file` | The book has no file yet. |
| `not_pdf` | Previews work for PDF files only. |
| `disabled` | The seller switched the preview off for this book. |
| `unavailable` | A preview could not be made: the file is encrypted, damaged, over 60 MB, or has fewer than two pages. |

Other statuses: `429` when one visitor makes more than 40 preview requests in 5 minutes (`Retry-After` tells them when to try again), and `503` with `code: "busy"` and `Retry-After: 5` when previews are busy.

```json theme={null}
{
    "status": 404,
    "success": false,
    "message": "The seller has not enabled a preview for this book",
    "code": "disabled",
    "data": {}
}
```


## OpenAPI

````yaml api-reference/openapi.json GET /digital-products/{id}/preview
openapi: 3.1.0
info:
  title: Salesive Store API
  description: >-
    REST interface for querying products, categories, and merchandising banners
    exposed by Salesive storefronts.
  version: 1.0.0
servers:
  - description: Production
    url: https://store.salesive.com/api/v1
security:
  - BearerAuth: []
    ShopIdHeader: []
paths:
  /digital-products/{id}/preview:
    get:
      summary: Get a free preview
      description: >-
        Returns the first pages of a listed PDF book as an inline PDF, cut on
        demand from the private file. Public and shop scoped like `/products`.
        The page count is the seller's setting (default 3, 1 to 20), never more
        than half of the book and at least one; a book of fewer than two pages
        has no preview. Every page carries a footer such as `Preview: first 3 of
        120 pages`. The result is cached for an hour. Each visitor gets 40
        requests per 5 minutes.
      parameters:
        - $ref: '#/components/parameters/XShopIdHeader'
        - name: id
          in: path
          required: true
          schema:
            type: string
          description: The digital product id.
      responses:
        '200':
          description: >-
            The preview PDF (`Content-Disposition: inline`, `Cache-Control:
            public, max-age=300`).
          content:
            application/pdf:
              schema:
                type: string
                format: binary
        '404':
          description: >-
            No preview exists. `code` is `not_found` (no such listed book),
            `no_file`, `not_pdf` (previews work for PDFs only), `disabled` (the
            seller switched it off) or `unavailable` (the file is encrypted,
            broken, over 60 MB or has fewer than two pages).
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: integer
                  success:
                    type: boolean
                  message:
                    type: string
                  data:
                    type: object
                  code:
                    type: string
                    description: Machine-readable reason.
                example:
                  status: 404
                  success: false
                  message: The seller has not enabled a preview for this book
                  code: disabled
                  data: {}
        '429':
          description: >-
            Too many preview requests from this visitor. `Retry-After` says when
            to try again.
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: integer
                  success:
                    type: boolean
                  message:
                    type: string
                  data:
                    type: object
                example:
                  status: 429
                  success: false
                  message: Too many preview requests. Please try again in 4 minutes.
                  data: {}
        '503':
          description: 'Previews are busy. `Retry-After: 5`.'
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: integer
                  success:
                    type: boolean
                  message:
                    type: string
                  data:
                    type: object
                  code:
                    type: string
                    description: Machine-readable reason.
                example:
                  status: 503
                  success: false
                  message: Previews are busy right now. Please try again in a moment
                  code: busy
                  data: {}
      security: []
components:
  parameters:
    XShopIdHeader:
      name: x-shop-id
      in: header
      description: >-
        Optional identifier that scopes responses to a specific storefront when
        the referer cannot be inferred.
      required: false
      schema:
        type: string
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT issued by the Salesive Store API for authenticated shoppers.
    ShopIdHeader:
      type: apiKey
      in: header
      name: x-shop-id
      description: >-
        Optional storefront identifier sent as a header to scope responses to a
        specific shop. Try It requests remember this value once provided.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.