# Pages

Source: https://developers.swell.is/backend-api/pages

The pages model contains data relating to content pages within your storefront and the content within them.

> **Tip:** We recommend not making changes via the API for the pages model when possible and suggest using the dashboard model editor instead. If you do wish to make changes via the API, see our [data model customization guide](https://developers.swell.is/guides/model-customization).

## The pages model

### Fields

- `id` (objectId): Unique identifier for the page.
- `name` (string, required): Human-friendly name of the page.
- `slug` (string, required): Lowercase, hyphenated identifier typically used in URLs. When creating a product, a slug will be generated automatically from the name. Maximum length of 1,000 characters.
- `content` (string): HTML formatted page content.
- `date_created` (date): Date and time the page was created.
- `date_published` (date): Date and time the page was published.
- `date_updated` (date): Date and time the page was updated.
- `meta_description` (string): Page description used for search engine optimization purposes.
- `published` (boolean): Indicates whether the page is published. Defaults to false. Default: `false`.
- `redirect` (string): URL to specify a page redirect.


## Create a page

Create a new content page.

### Arguments

- `id` (objectId, required): Unique identifier for the page.
- `slug` (string, auto): Slug identifier of the page. Defaults to a slug-formatted version of the `title`.
- `title` (string, required): Title of the page.
- `content` (string): HTML or text content of the page.
- `published` (boolean): Indicates whether the page is published and should be displayed in the storefront.
- `date_published` (date): Date the page was published. May be used to indicate the publish date in the storefront, or to delay publishing until a future date.
- `meta_title` (string): Title used for SEO purposes, if different than the page `title`.
- `meta_description` (string): Description used for SEO purposes. Typically the storefront will use a number of characters from the page's `content` if this is not defined.
- `meta_keywords` (string): Keywords used for SEO purposes.
- `theme_template` (string): Template used to render this page in a storefront theme, if applicable.

### Example request

`POST /content/pages`

**cURL**

```bash
$ curl https://api.swell.store/content/pages \
  -u store-id:secret-key \
  -d title="Example page"
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.post('/content/pages', {
  title: 'Example page'
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->post('/content/pages', [
  'title' => 'Example page'
]);
```

### Example response

```json
{
  "id": "60f199509111e70000000022",
  "title": "Example page",
  "slug": "example-page",
  "content": null,
  "published": true,
  "date_published": "2021-07-16T14:36:00.142Z",
  "meta_title": null,
  "meta_description": null,
  "date_created": "2021-07-16T14:36:00.142Z",
  "date_updated": "2021-07-16T14:36:00.142Z"
}
```


## Retrieve a page

Retrieve an existing content page using the ID that was returned when created.

### Arguments

- `id` (objectId, required): ID of the gift card to retrieve.
- `expand` (string): Expanding link fields and child collections is performed using the expand argument.

  - For example, `expand=account` would return a related customer account if one exists.

  When the field represents a collection, you can specify the query limit.

  - For example, `expand=variants:10` would return up to 10 records of the variants collection.

  See [expanding ](https://developers.swell.is/backend-api/querying/expanding)for more details.
- `fields` (string): Return only the specified fields in the result. For example `fields=name,slug` would return only the fields `name` and `slug` in the response. Supports nested object and array fields using dot-notation. For example, `items.product_id`. The gift card `id` is always returned.
- `include` (string): Include one or more arbitrary queries in the response, possibly related to the main query.

  See [including ](https://developers.swell.is/backend-api/querying/including)for more details.

### Example request

`GET /content/pages/:id`

**cURL**

```bash
$ curl https://api.swell.store/content/pages/60f199509111e70000000022 \
  -u store-id:secret-key
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.get('/content/pages/{id}', {
  id: '60f199509111e70000000022',
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->get('/content/pages/{id}', [
  'id' => '60f199509111e70000000022'
]);
```

### Example response

```json
{
  "id": "60f199509111e70000000022",
  "title": "Example page",
  "slug": "example-page",
  "content": "<p>Welcome to our store.</p>",
  "published": true,
  "date_published": "2021-07-16T14:36:00.142Z",
  "meta_title": "Example page",
  "meta_description": null,
  "date_created": "2021-07-16T14:36:00.142Z",
  "date_updated": "2021-07-16T14:36:00.142Z"
}
```


## Update a page

Update an existing page using the ID that was returned when created.

### Arguments

- `id` (objectId, required): Unique identifier for the page.
- `slug` (string, auto): Slug identifier of the page. Defaults to a slug-formatted version of the `title`.
- `title` (string, required): Title of the page.
- `content` (string): HTML or text content of the page.
- `published` (boolean): Indicates whether the page is published and should be displayed in the storefront.
- `date_published` (date): Date the page was published. May be used to indicate the publish date in the storefront, or to delay publishing until a future date.
- `meta_title` (string): Title used for SEO purposes, if different than the page `title`.
- `meta_description` (string): Description used for SEO purposes. Typically the storefront will use a number of characters from the page's `content` if this is not defined.
- `meta_keywords` (string): Keywords used for SEO purposes.
- `theme_template` (string): Template used to render this page in a storefront theme, if applicable.

### Example request

`PUT /content/pages/:id`

**cURL**

```sh
$ curl https://api.swell.store/content/pages/60f199509111e70000000022 \
  -u store-id:secret-key \
  -d title="Updated page" \
  -X PUT
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.put('/content/pages/{id}', {
  id: '60f199509111e70000000022',
  title: 'Updated page'
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->put('/content/pages/{id}', [
  'id' => '60f199509111e70000000022',
  'title' => 'Updated page'
]);
```

### Example response

```json
{
  "id": "60f199509111e70000000022",
  "title": "Updated page",
  "slug": "example-page",
  "content": "<p>Welcome to our store.</p>",
  "published": true,
  "date_published": "2021-07-16T14:36:00.142Z",
  "meta_title": "Example page",
  "meta_description": null,
  "date_created": "2021-07-16T14:36:00.142Z",
  "date_updated": "2021-07-18T09:12:04.481Z"
}
```


## List all pages

Return a list of content pages.

### Arguments

- `expand` (string): Expand link fields and child collections by using the expand argument.

  - For example, `expand=account` would return a related customer account if one exists.

  When the field represents a collection, you can specify the query limit.

  - For example, `expand=variants:10` would return up to 10 records of the variants collection.

  See [expanding](https://developers.swell.is/backend-api/querying/expanding) for more details.
- `fields` (string): Returns only the specified fields in the result.

  - For example `fields=name,slug` would return only the fields `name` and `slug` in the response.

  Supports nested object and array fields using dot-notation.

  - For example, `items.product_id`. The product `id` is always returned.
- `include` (object): Include one or more arbitrary queries in the response which are potentially related to the main query.

  See [including](https://developers.swell.is/backend-api/querying/including) for more details.
- `limit` (int): Limit the number of records returned, ranging between `1` and `1000`. Defaults to `15`. Default: `15`.
- `page` (int): The page number of results to return given the specified or default `limit`.
- `search` (string): A text search is performed using the search argument. Searchable fields are defined by the model.

  - For example, `search=red` would return records containing the word "red" anywhere in the defined text fields.

  See [searching](https://developers.swell.is/backend-api/querying/searching) for more details.
- `sort` (string): Expression to sort results by using a format similar to a SQL sort statement.

  - For example, `sort=name asc` would return records sorted by name ascending.

  See [sorting](https://developers.swell.is/backend-api/querying/sorting) for more details.
- `where` (object): An object with criteria to filter the result.

  - For example, `active=true` would return records containing a field `active` with the value `true`.

  It's also possible to use query operators, for example, `$eq`, `$ne`, `$gt`, and more.

  See [querying](https://developers.swell.is/backend-api/querying) for more details.

### Example request

`GET /content/pages`

**cURL**

```sh
$ curl https://api.swell.store/content/pages \
  -u store-id:secret-key \
  -G
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.get('/content/pages', {
  limit: 25,
  page: 1
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->get('/content/pages', [
  'limit' => 25,
  'page' => 1
]);
```

### Example response

```json
{
  "count": 51,
  "results": [
    {
      "id": "60f199509111e70000000022",
      "title": "Example page",
      "slug": "example-page",
      "content": "<p>Welcome to our store.</p>",
      "published": true,
      "date_published": "2021-07-16T14:36:00.142Z",
      "meta_title": "Example page",
      "meta_description": null,
      "date_created": "2021-07-16T14:36:00.142Z",
      "date_updated": "2021-07-16T14:36:00.142Z"
    },
    {...},
    {...}
  ],
  "page": 1,
  "page_count": 3,
  "limit": 25,
  "pages": {
    "1": {
      "start": 1,
      "end": 25
    },
    "2": {
      "start": 26,
      "end": 50
    },
    "3": {
      "start": 51,
      "end": 51
    }
  }
}
```


## Delete a page

Delete a content page permanently.

### Arguments

- `id` (objectId, required): The ID of the page to delete.

### Example request

`DELETE /content/pages/:id`

**cURL**

```sh
$ curl https://api.swell.store/content/pages/60f199509111e7000000002e \
  -u store-id:secret-key \
  -X DELETE
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.delete('/content/pages/{id}', {
  id: '60f199509111e7000000002e'
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->delete('/content/pages/{id}', [
  'id' => '60f199509111e7000000002e'
]);
```

### Example response

```json
{
  "id": "60f199509111e7000000002e",
  "title": "Retired page",
  "slug": "retired-page",
  "content": null,
  "published": false,
  "date_published": null,
  "meta_title": null,
  "meta_description": null,
  "date_created": "2021-07-16T14:36:00.142Z",
  "date_updated": "2021-07-16T14:36:00.142Z"
}
```

