# Setka Content Cloud API

Setka Cloud API allows you to download HTML code and auxiliary data of posts saved in your [Setka account](https://editor.setka.io/).

{% hint style="warning" %}
To enable Cloud API, please contact [support](https://editor.setka.io/support).
{% endhint %}

## Working with posts when Cloud API is enabled

If Cloud API is active on your Setka account, you will see some new buttons that will help you operate with the posts.

### Publishing the post

If Cloud API is enabled, you will see the **Publish / Unpublish** button on the post badge in your [Setka account](https://editor.setka.io/). It determines the status of the post: *published* or *draft*, respectively:

![](https://1843290185-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MLOEPbfEK4119w2ROYc%2F-M_aMssLC-JtS39EMmsm%2F-M_aNLbuNELrL98oP7AJ%2FScreenshot%20of%20Setka%20Editor%20Interface%20Post%20Thumbnail%20with%20Publish%20button%20and%20Setka%20API%20sign.png?alt=media\&token=3e3b8fc7-7670-4b3f-8c24-53cde113ec06)

The same buttons will appear in the post editor:

![Screenshot of the Setka Editor interface: publishing the post via Cloud API](https://1843290185-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MLOEPbfEK4119w2ROYc%2F-MYuVbxxcIoGswfW2Wnm%2F-MYuXS5WMCw1hViXZ1c2%2FScreenshot-Setka-Editor-Publish-Post.png?alt=media\&token=d9e581d4-5352-402d-b58f-0d1326fb7d61)

![Screenshot of the Setka Editor interface: unpublishing the post via Cloud API](https://1843290185-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MLOEPbfEK4119w2ROYc%2F-M_aMssLC-JtS39EMmsm%2F-M_aQV4haSm4lfptsLEl%2FScreenshot-Setka-Editor-Unpublish-Post.png?alt=media\&token=538aeb5a-c628-49a2-90f6-779efae93a84)

### Updating the post

After the post is published, it can also be updated. Until then, its' status will stay as `draft` . To update the post and make the new revision available as `published` :

1. Make some changes in the published post and click **Save draft**.
2. Click **Republish**:

![Screenshot of the Setka Editor interface: updaring the post via Cloud API](https://1843290185-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MLOEPbfEK4119w2ROYc%2F-M_VuNTHptQKA_1bJ9qx%2F-M_aKR-Wf4yYXv2Dkho-%2FScreenshot-Setka-Editor-Update-Post.png?alt=media\&token=3645283e-0007-4589-a3bf-05816f02a62d)

## Making API requests with the Setka Cloud API <a href="#h_01enncg7mxdxs0cm62xe0esnam" id="h_01enncg7mxdxs0cm62xe0esnam"></a>

To fetch a complete list of posts from your Setka account, run the following request by adding a license key:

```http
GET https://editor.setka.io/api/v2/posts
```

To get a specific post from your Setka account, you need to specify its ID:

```http
GET https://editor.setka.io/api/v2/posts/POST_ID
```

Where `POST_ID` is the post’s ID.

{% hint style="warning" %}
By default, API will only return published posts with no images or HubSpot data. To get draft posts, use the `state:draft` or `state:all` filters. To include HubSpot data and/or images in the results, add additional fields to the request.
{% endhint %}

## Authorization <a href="#h_01ennch6xwpdtar6ra93bjm42n" id="h_01ennch6xwpdtar6ra93bjm42n"></a>

Authorizing your identity in the Setka Cloud API is possible in two ways:

### 1. In the request header <a href="#h_01ennchk3cq3tphwvhyyqrq23w" id="h_01ennchk3cq3tphwvhyyqrq23w"></a>

Add the authorization header to the request:

```http
{
  "Authorization": "Bearer YOUR_LICENSE_KEY"
}
```

where `YOUR_LICENSE_KEY` is your license key.

### 2. In the request parameters <a href="#h_01ekfytkypgcwhqxkys39r71ev" id="h_01ekfytkypgcwhqxkys39r71ev"></a>

Add the *token* parameter to the request:

```
GET https://editor.setka.io/api/v2/posts?token=YOUR_LICENSE_KEY
```

where `YOUR_LICENSE_KEY` is your license key.

## Example API request response <a href="#h_01eqdc5kj0mpez7rztkpgq0zrm" id="h_01eqdc5kj0mpez7rztkpgq0zrm"></a>

If the request is successful, you will receive a response consisting of an array of posts. The response will be paginated if the number of posts is large. Below is an example API request response:

```javascript
HTTP/1.1 200 OK
{
  posts: [
    {
      "id": 2587,
      "title": "Stylist",
      "style_name": "General",
      "layout_name": "6col_19774",
      "reading_time": 240,
      "preview_link": "https://editor.setka.io/posts/80a44hd5924792",
      "state": "published"
      "author": {
        "id": 44,
        "name": "John Smith"
      },
      "body_html": "Hello!",
      "assets": {
        "plugins": [
          "https://ceditor.setka.io/clients/js_plugins/5ca41dc7f0df3e3d6170901b627d32fc/public.js"
        ],
        "styles": [
          "https://ceditor.setka.io/common_css/common_css_1565603693.css",
          "https://ceditor.setka.io/clients/GP1TwUnF9mFFVzgqnAplHSQs51xdl4WT/css/loM7yyO-6xsVawmBxqej8A.css",
          "https://ceditor.setka.io/clients/GP1TwUnF9mFFVzgqnAplHSQs51xdl4WT/layout_option_builds/19774/gazQpY7j6Cgq9gFsEKYF5A.css"
        ],
        "images": [
          {
            "id": 3310,
            "url": "https://ceditor.setka.io/clients/U8Cr2B1ZnJjyHr6e6xn_Qa7N1oqyj7cB/post_images/-tltJS8D79MI5Yltt37MCA.jpg",
            "alt": "Alt text"
            "sizes": [
              {
                "width": 3654,
                "height": 5473,
                "url": "https://ceditor.setka.io/clients/U8Cr2B1ZnJjyHr6e6xn_Qa7N1oqyj7cB/post_images/-tltJS8D79MI5Yltt37MCA.jpg"
              },
              {
                "width": 500,
                "height": 5473,
                "url": "https://ceditor.setka.io/6xAHRUiLM1NBnWZ9JupZNdugX1UyoQkg9kzIGk9--vk/w:500/q:88/plain/clients/U8Cr2B1ZnJjyHr6e6xn_Qa7N1oqyj7cB/post_images/-tltJS8D79MI5Yltt37MCA.jpg"
              },
              {
                "width": 1000,
                "height": 5473,
                "url": "https://ceditor.setka.io/Ioa24dDnWZ9JupZNdugX1UyoQkg9kzIGk9--vk/w:1000/q:88/plain/clients/U8Cr2B1ZnJjyHr6e6xn_Qa7N1oqyj7cB/post_images/-tltJS8D79MI5Yltt37MCA.jpg"
              }
            ]
          }
        ]
      },
      "hubspot_post": {
        "id": 141,
        "url": "https://hubspotblog.com/1-blog-page/-temporary-slug-bbd6cb8e-afed-4291-8937-c779c9ac2d25?hs_preview=ludkAblF-28956926215",
        "blog_id": 1315
      },
      "created_at": "2019-07-19T10:25:27Z",
      "updated_at": "2019-07-19T10:27:40Z",
      "published_at": "2019-07-22T13:34:11Z"
    }
  ],
  pagination: {
    "page": 1,
    "limit": 20,
    "page_count": 1,
    "total_count": 1
  }
}
```

### Description of a received set of fields <a href="#h_01eqdc5wkh1vtm6x69trsdtamj" id="h_01eqdc5wkh1vtm6x69trsdtamj"></a>

| **Field**  | **Description**                                                                                                                                              |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| posts      | Posts array. Contains all the posts from your Setka account. The selection can be limited using additional parameters.                                       |
| pagination | Pagination of search results. Contains information about the current page, the number of pages, the total number of posts, and the number of posts per page. |

#### Posts array elements <a href="#h_01eqdc6crv4dzdjd2w56ekjh4j" id="h_01eqdc6crv4dzdjd2w56ekjh4j"></a>

| **Element**      | **Description**                                                                                                                                                                                                                                                                                                                                                                                          |
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| id               | The post’s unique ID.                                                                                                                                                                                                                                                                                                                                                                                    |
| <p>title<br></p> | The post’s title.                                                                                                                                                                                                                                                                                                                                                                                        |
| style\_name      | The name of the style used in the post.                                                                                                                                                                                                                                                                                                                                                                  |
| layout\_name     | The name of the grid in which the post is laid out.                                                                                                                                                                                                                                                                                                                                                      |
| reading\_time    | The estimated time to read the post (in seconds).                                                                                                                                                                                                                                                                                                                                                        |
| preview\_link    | A link to the post’s preview in your Setka account.                                                                                                                                                                                                                                                                                                                                                      |
| state            | The post’s state (either `draft` or `published`).                                                                                                                                                                                                                                                                                                                                                        |
| created\_at      | The date and time of the post’s creation.                                                                                                                                                                                                                                                                                                                                                                |
| updated\_at      | The date and time when the post was last updated.                                                                                                                                                                                                                                                                                                                                                        |
| published\_at    | The date and time of the post’s publication.                                                                                                                                                                                                                                                                                                                                                             |
| author           | <p>The post’s author, where</p><p><em>—</em> <code>id</code> — the author’s unique ID.</p><p><em>—</em> <code>name</code> — the author’s name specified in your Setka account.</p>                                                                                                                                                                                                                       |
| body\_html       | The post’s full HTML code.                                                                                                                                                                                                                                                                                                                                                                               |
| assets           | Any additional files in the posts (e.g., CSS, JavaScript, or images).                                                                                                                                                                                                                                                                                                                                    |
| hubspot\_post    | <p>The post data exported to HubSpot, where:</p><p><em>—</em> <code>id</code> — the post’s unique ID.</p><p><em>—</em> <code>url</code> — the link to the post in HubSpot.</p><p><em>—</em> <code>blog\_id</code> — the post’s ID in HubSpot.</p><p><em><strong>Note:</strong> Getting the <code>hubspot\_post</code> field in your API response will require the use of additional parameters.</em></p> |

**Assets element files**

As mentioned above, the *assets* element contains links to other files and assets. The possible types of *assets* are:

| File    | URL                                                                                                                          | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ------- | ---------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| plugins | <p><https://ceditor.setka.io/clients></p><p>/js\_plugins/5ca41dc7f0df3e3d6170901b627d32fc/public.js</p>                      | The scripts to run interactive post elements (e.g., animations, galleries, or notes).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| styles  | <p><https://ceditor.setka.io/common_css></p><p>/common\_css\_1565603693.css</p>                                              | <p><br>The <a href="https://editor-help.setka.io/hc/en-us/articles/115002594605-Integration-with-Content-Design-System-Manager#h_86d458de-3dcd-4dac-b1c1-43742dda74a7">CSS files</a> of post styles, including the common style file, the standalone style, and the layout grid file.</p>                                                                                                                                                                                                                                                                                                                                     |
| images  | <p><https://ceditor.setka.io/clients></p><p>/U8Cr2B1ZnJjyHr6e6xn\_Qa7N1oqyj7cB/post\_images/-tltJS8D79MI5Yltt37MCA.jpg  </p> | <p>The images used in the post, where:</p><p>— <code>id</code> — the image’s unique ID.</p><p>— <code>url</code> — the link to the file.</p><p>— <code>alt</code> — the alternative text.</p><p>— <code>sizes</code> — several options for the image size, depending on the device’s screen size. <br><strong>Note:</strong> <em>Getting the <code>images</code> field in your response will require using</em> <a href="https://editor-help.setka.io/hc/en-us/articles/360056312453-Getting-Posts-from-the-Setka-Account-with-Setka-Cloud-API#h_01EKFYY9S0YYMM744FF52HPA16"><em>additional parameters</em></a><em>.</em></p> |

#### Pagination object elements <a href="#h_01ekfyxhkqvfmr3c5sntkxheqr" id="h_01ekfyxhkqvfmr3c5sntkxheqr"></a>

| **Element**      | **Description**                       |
| ---------------- | ------------------------------------- |
| page             | The current page number.              |
| <p>limit<br></p> | The maximum number of posts per page. |
| page\_count      | The total number of pages.            |
| total\_count     | The total number of posts.            |

## Making API requests with additional parameters <a href="#h_01ekfyy9s0yymm744ff52hpa16" id="h_01ekfyy9s0yymm744ff52hpa16"></a>

Using additional request parameters with the Setka Cloud API is necessary to filter posts by features or to include or exclude certain data in the response.

### Filters <a href="#h_01ekfyykq3y2r3rhwcs25h47m3" id="h_01ekfyykq3y2r3rhwcs25h47m3"></a>

You can filter posts by status and author, e.g.:

```
GET https://editor.setka.io/api/v2/posts?filter=state:draft,author.id:1111&token=YOUR_LICENSE_KEY
```

The available filters are:

* `author` — the post’s author. The filter works both by ID (i.e., `author.id`) and by author name (`author.name`).
* `state` — the post’s status, i.e., one of the following: `draft`, `published`, or `all` (both `draft` and `published`).

### Additional fields <a href="#h_01ekfyyxxz36dysnbek6w2ed21" id="h_01ekfyyxxz36dysnbek6w2ed21"></a>

You can also include additional fields in the API response with the *include* parameter and listing the fields separated by commas, e.g.:

```
GET https://editor.setka.io/api/v2/posts?include=hubspot_post,images&token=YOUR_LICENSE_KEY
```

The available fields are:

* `hubspot_post` — the data of a post exported to HubSpot.
* `images` — all images used in a post.

### Selecting post data <a href="#h_01ekfyz3x4mj7rqh8r84fpe70h" id="h_01ekfyz3x4mj7rqh8r84fpe70h"></a>

If you need to obtain individual fields from your Setka account (e.g., only identifiers and post names), use the `select` parameter:

```
GET https://editor.setka.io/api/v2/posts?select=id,title&token=YOUR_LICENSE_KEY
```

The available fields are:

* `id` — the post’s unique ID.
* `title` — the post’s title.
* `style_name` — the name of the style used in the post.
* `layout_name` — the name of the grid in which the post is laid out.
* `reading_time` — the estimated time to read the post (in seconds).
* `preview_link` — a link to the post’s preview in your Setka account.
* `state` — the post’s state (either `draft` or `published`).
* `created_at` — the date and time of the post’s creation.
* `updated_at` — the date and time when the post was last updated.
* `published_at` — the date and time of the post’s publication.
* `author` — the post’s author, where *id* is the author’s unique ID, and the *name* is the author’s name specified in your Setka account.
* `body_html` — the post’s full HTML code.
* `assets` — any additional files in the posts (e.g., CSS, JavaScript, or images).
* `hubspot_post` — the post data exported to HubSpot, where `id` is the post’s unique ID; `url` is the link to the post in HubSpot; `blog_id` is the post’s ID in HubSpot.

## Possible errors when using the Setka Cloud API <a href="#h_01ekfyzd2vqnegz0y409bh6pm2" id="h_01ekfyzd2vqnegz0y409bh6pm2"></a>

When using the Setka Cloud API, you might encounter the following errors:

`HTTP/1.1 401 Unauthorized`

```javascript
{
   "error": "Not authorized!"
}
```

This error occurs when using an incorrect license key (token).

&#x20;`HTTP/1.1 404 Unauthorized`

```javascript
{
   "error": "Not found"
}
```

This error occurs when requesting a specific post if a post with this ID is not found.

{% hint style="info" %}
If you need assistance with the Setka Cloud API, [please contact support](https://editor.setka.io/support).
{% endhint %}

## Preserve your Setka Editor content after the service shutdown

If you use Post API to fetch content from Setka Cloud, you will need to migrate all assets to your own infrastructure. Post API response contains links to all necessary assets (CSS, Fonts, Images etc).

{% hint style="info" %}
Advice – store CSS files with the same path, that will simplify the update script.
{% endhint %}

For example: If CSS URL looks like: [`https://ceditor.setka.io/clients/123/example.css`](https://ceditor.setka.io/clients/123/example.css) you should store it in your infrastructure and make it accessible via the URL on your domain, for example like this: [`https://you-domain.com/clients/123/example.css`](https://you-domain.com/clients/123/example.css).

When all assets are downloaded and stored in your infrastructure, you need to replace all links used in the Post body and include CSS files in the Post Page. You will need a custom script tailored to your case.&#x20;

Inside the Post body there might be images. If you created Posts inside Setka Cloud you’ll find `srcset` generated for multiple image sizes. It’s a feature provided by Setka Cloud. Links to image variations are not provided. We suggest that you remove everything inside the `srcset`HTML attribute for in `<img tag>` and store the original image in your infrastructure.

Example:

You have the following piece of code:

{% code overflow="wrap" %}

```html
<img src="https://img.setka.io/clients/AutWJxVDaz_R9_xWagHPL9nT4WVLIRNp/post_images/mufasa_headshot-2023012401152726.png" data-image-id="248663" data-image-name="Mufasa_headshot.png" class="stk-image stk-reset" srcset="https://img.setka.io/clients/AutWJxVDaz_R9_xWagHPL9nT4WVLIRNp/post_images/mufasa_headshot-2023012401152726.png 1044w, https://img.setka.io/rk1GAk6jbdIj4L5shxsSoWdU8vdWLXBx3AcTkiOmKec/w:500/q:88/plain/clients/AutWJxVDaz_R9_xWagHPL9nT4WVLIRNp/post_images/mufasa_headshot-2023012401152726.png 500w, https://img.setka.io/2g0DHW1QRePXqTjfSSAAuLYU4TPFisvQlQZF_jEez_8/w:750/q:88/plain/clients/AutWJxVDaz_R9_xWagHPL9nT4WVLIRNp/post_images/mufasa_headshot-2023012401152726.png 750w, https://img.setka.io/2G2xzHJHv4XawjrRFaa6V76e7G3ZltwPorAYSmLH0zU/w:1000/q:88/plain/clients/AutWJxVDaz_R9_xWagHPL9nT4WVLIRNp/post_images/mufasa_headshot-2023012401152726.png 1000w" width="1044" height="1302" loading="lazy">
```

{% endcode %}

You should pick the original size – [`https://img.setka.io/clients/AutWJxVDaz_R9_xWagHPL9nT4WVLIRNp/post_images/mufasa_headshot-2023012401152726.png`](https://img.setka.io/clients/AutWJxVDaz_R9_xWagHPL9nT4WVLIRNp/post_images/mufasa_headshot-2023012401152726.png) in `src` attribute (you can find the same link inside Post API response) and make it accessible on the URL like [`https://your-domain.com/clients/AutWJxVDaz_R9_xWagHPL9nT4WVLIRNp/post_images/mufasa_headshot-2023012401152726.png`](https://your-domain.com/clients/AutWJxVDaz_R9_xWagHPL9nT4WVLIRNp/post_images/mufasa_headshot-2023012401152726.png)

Then change the link inside Setka Post body and remove the srcset. The result will look like this:

{% code overflow="wrap" %}

```html
<img src="https://your-domain.com/clients/AutWJxVDaz_R9_xWagHPL9nT4WVLIRNp/post_images/mufasa_headshot-2023012401152726.png" data-image-id="248663" data-image-name="Mufasa_headshot.png" class="stk-image stk-reset" width="1044" height="1302" loading="lazy">
```

{% endcode %}
