# Welcome to Mattermix

## Getting Started

### API: Automate image creation

Learn how to use the Mattermix API to automate and scale your image creation:

{% content-ref url="/pages/2A8SyEH2UmO2yJOlrt4r" %}
[Create API key](/api/create-api-key)
{% endcontent-ref %}

{% content-ref url="/pages/Q3lvlTQ5s4F4loc5DQP1" %}
[Authentication](/api/authentication)
{% endcontent-ref %}

{% content-ref url="/pages/24res4VzvKCNMB0YwByA" %}
[Create image](/api/create-image)
{% endcontent-ref %}

{% content-ref url="/pages/HbxRj58hNPCrnXGtCPSy" %}
[Delete image](/api/delete-image)
{% endcontent-ref %}

{% content-ref url="/pages/nCC1hD9hO9fGgugnNGpX" %}
[Template syntax](/api/template-syntax)
{% endcontent-ref %}

{% content-ref url="/pages/OjIASyEcrWXAnSkNestP" %}
[Set API limit](/api/set-api-limit)
{% endcontent-ref %}

### Integrations: Connect Mattermix with your apps

Learn how to connect Mattermix with the tools you already use:

{% content-ref url="/pages/ItqZVvyIxw3rhWSQDfG0" %}
[Zapier](/integrations/zapier)
{% endcontent-ref %}

### Subscription: Manage your subscription

Learn how to create and cancel your Mattermix subscription:

{% content-ref url="/pages/ezsgNTXRbXExSGHTVWAp" %}
[Manage subscription](/subscription/manage-subscription)
{% endcontent-ref %}


# Create API key

Creating an API key is necessary for using the Mattermix API. To create one, head to the *API* tab in your *Account* and click on the *Create key* button to create a new API key.

![Create a new API key for Mattermix](/files/DkZKDwzrUzMxb6RsuAxl)

Once the new API key is created, a modal will open with the new key. For added security, this is the only time you can view the key, so copy the value and keep it in a secure place. **Treat your API key like a password and do not expose or share it with anyone**.

{% hint style="warning" %}
**Warning:** Delete your API key and create a new one if it is accidentally shared or exposed to the public.
{% endhint %}

![Copy your new API key for Mattermix](/files/8DN6FvzAZva51cGln8lA)

You can now use your API key to [authenticate API requests](/api/authentication).


# Authentication

The Mattermix API is expecting an [Authorization](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization) header using the Bearer authentication scheme followed by your API key as the authorization parameter. For example, an authorization header would look like the following (replacing `Your-API-Key` with your actual API key): `Authorization: 'Bearer Your-API-Key'`.

Below is an example using the Fetch API from JavaScript:

```javascript
const body = {
  html: "<html><body><p>Hello World!</p></body></html>"
}

const res = await fetch("mattermix.com/api/v1/image", {
  method: "POST",
  headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${process.env.MATTERMIX_API_KEY}`
    },
  body: JSON.stringify(body)
});
```

In the above example, the Mattermix API key is stored in an [environment variable](https://www.freecodecamp.org/news/what-are-environment-variables-and-how-can-i-use-them-with-gatsby-and-netlify/) named `MATTERMIX_API_KEY` to prevent the API key being exposed in committed code.&#x20;


# Create image

{% hint style="info" %}
**Before getting started:** You will need to [create your API key](/api/create-api-key).
{% endhint %}

## Create and return a new image URL

<mark style="color:green;">`POST`</mark> `https://mtmx.io/v1/image`

#### Headers

| Name                                            | Type   | Description           |
| ----------------------------------------------- | ------ | --------------------- |
| Authorization<mark style="color:red;">\*</mark> | String | `Bearer YOUR-API-KEY` |

#### Request Body

| Name                                   | Type    | Description                                                                                                  |
| -------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------ |
| html<mark style="color:red;">\*</mark> | String  | The HTML you want to render for creating an image.                                                           |
| content                                | Object  | Updates values when using Handlebars templating syntax. [Learn more](/api/template-syntax).                  |
| type                                   | String  | Defines whether to render JPEG or PNG image. Accepted values are `png` and `jpeg`. Default value is `png`.   |
| quality                                | Number  | Defines the quality of JPG images. Not applicable to PNG images. Default value `80`.                         |
| selector                               | String  | Target a specific HTML element to perform the screenshot. Default value is `body`.                           |
| transparent                            | Boolean | Hides default white background and allows capturing screenshots with transparency. Default value is `false`. |

{% tabs %}
{% tab title="200: OK Export created successfully" %}

```javascript
{
    "success": true,
    "url": "https://cdn.mattermix.com/v1/image/62029ad452390ccfd9abcc4f-1644951564719.png"
    "id": "620bfdd2501f2b5c901e2800"
}
```

{% endtab %}

{% tab title="401: Unauthorized Unauthorized request" %}

```javascript
{
    "success": false,
    "statusCode": 401,
    "message": "Please provide a valid API key."
}
```

{% endtab %}

{% tab title="402: Payment Required Inactive or cancelled subscription" %}

```javascript
{
    "success": false,
    "statusCode": 402,
    "message": "Active subscription not found."
}
```

{% endtab %}

{% tab title="500: Internal Server Error Internal server error" %}

```javascript
{
    "success": false,
    "statusCode": 500,
    "message": "Server error."
}
```

{% endtab %}

{% tab title="429: Too Many Requests API limit reached" %}

```javascript
{
    "success": false,
    "statusCode": 429,
    "message": "You have reached your monthly export limit set in your account."
}
```

{% endtab %}
{% endtabs %}


# Delete image

{% hint style="info" %}
**Before getting started:** You will need to [create your API key](/api/create-api-key).
{% endhint %}

## Delete image from Mattermix and Google CDN

<mark style="color:red;">`DELETE`</mark> `https://mtmx.io/v1/image/:uid`

The `uid` for the image can be found in the image URL. For example, if the image URL is `https://cdn.mattermix.com/images/620d5489e8b565e74ce552c1/484ec22d-bfc9-4fc8-b764-6cf8d9b91f55.png` the `uid` is `484ec22d-bfc9-4fc8-b764-6cf8d9b91f55`.

#### Headers

| Name                                            | Type   | Description           |
| ----------------------------------------------- | ------ | --------------------- |
| Authorization<mark style="color:red;">\*</mark> | String | `Bearer YOUR-API-KEY` |

{% tabs %}
{% tab title="202: Accepted Export created successfully" %}

```javascript
{
    "success": true,
}
```

{% endtab %}

{% tab title="401: Unauthorized Unauthorized request" %}

```javascript
{
    "success": false,
    "statusCode": 401,
    "message": "Please provide a valid API key."
}
```

{% endtab %}

{% tab title="500: Internal Server Error Internal server error" %}

```javascript
{
    "success": false,
    "statusCode": 500,
    "message": "Server error."
}
```

{% endtab %}

{% tab title="404: Not Found Image not found" %}

```javascript
{
    "success": false,
    "statusCode": 404,
    "message": "Image with URL not found."
}
```

{% endtab %}
{% endtabs %}


# Template syntax

The Mattermix API uses the [Handlebars](https://handlebarsjs.com/guide/) templating syntax to dynamically update values in HTML or CSS. For example, you could have the following in your HTML: `<p>{{title}}</p>`. The title value could be updated with the API by passing a title value in the `content` object of the request body.&#x20;

Below is an example using the Fetch API from JavaScript:

```javascript
const body = {
  html: "<html><body><p>{{title}}</p></body></html>",
  content: {
    title: "Hello World!"
  }
}

const res = await fetch("mattermix.com/api/v1/image", {
  method: "POST",
  headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${process.env.MATTERMIX_API_KEY}`
    },
  body: JSON.stringify(body)
});
```


# Set API limit

The API limit helps you control costs by defining a max number of exports per month for your account. This limit can be adjusted at any time from the [API Dashboard](https://www.mattermix.com/account/api).

![Set API limit from the API Dashboard](/files/Cn3S6m5zJfRoiySNBZhz)

By default your API will be limited to 50 exports per month when you first create your account. In order to increase this limit you will need to include a payment method on your subscription, which you can do from the [Subscription Dashboard](https://www.mattermix.com/account/subscription).


# Zapier

### Introduction

[Zapier](https://zapier.com/) makes it simple to connect the apps you already use so they can work together and automate tasks. For example, you can connect [Google Sheets](https://www.google.com/sheets/about/) or [Airtable](https://www.airtable.com/) to Mattermix and create new images when a record is created or updated. Zapier supports over 3,000 apps, so the possibilities to automate your workflows are endless!

If it's your first time using Zapier be sure to check out the [Zapier Help Center](https://zapier.com/help).

### Connect Mattermix with Zapier

* Head to your [App integrations](https://zapier.com/app/connections)
* Click **Add connection**
* Search for **Mattermix** and select
* Fill out the form with your [API key](/api/create-api-key) and email
* Click **Yes, Continue**

### Getting started: Create a Zapier Trigger

Every Zap starts with a Trigger: something that tells Zapier it's time to start an automation. For example, a Trigger could be when a new field is added in a Google Sheet, a new contact is added to an email list, or when a new deal closes in your CRM.&#x20;

Not only does this start the Zapier automation, but you can also use data captured from Triggers and previous steps and pass those values down. In this example, we'll be passing values from Airtable into the Mattermix API to dynamically update values in the HTML.

![Test data from an Airtable Trigger in Zapier](/files/YjnrhDwS1YpW2Zw2smJf)

### Action: Create Image

The Create Image Action will create a new image from HTML with the Mattermix API.

#### Set HTML

Copy and paste your HTML template in the HTML field, replacing any values you want to dynamically update from the Trigger or previous steps.

![Map values from Zapier Trigger to the Mattermix HTML field in the Zapier Action](/files/xaQ6hkrjZTH1cFkSAIyr)

#### Test action

Once you've mapped values to the fields you want to update, click **Continue**. You will now be prompted to test the Action. If the request is successful you will see a response similar to the following:

```javascript
{
    "success": true,
    "url": "https://cdn.mattermix.com/images/620d5489e8b565e74ce552c1/484ec22d-bfc9-4fc8-b764-6cf8d9b91f55.png"
}
```

These values will be available in the following steps to further complete your workflow. For example, you can use the URL returned from the Mattermix API in an Action to update a record in Airtable.

![Image URL returned from Mattermix API is used to update record in Airtable](/files/iSQoY9N8wWwLPcm0u5YK)

The last step is to turn on your new Zap by clicking the *Turn on zap* button.

![Turn on your new Zap and enjoy! ](/files/658V52FWXR2aUeFllbFm)


# Manage subscription

Mattermix uses [Stripe](https://stripe.com/) for subscription management and payment processing.

### Create subscription&#x20;

When your Mattermix account is created you will automatically be signed up for a Mattermix Subscription without needing to provide any credit card information. The only time you would need to include your credit card information is when you increase your [API limit](/api/set-api-limit) beyond 50 monthly exports.

If your subscription is canceled you'll need to create a new subscription from the [Subscription Dashboard](https://www.mattermix.com/account/subscription) by clicking on the *Subscribe* button. This will redirect you to Stripe Checkout where you can enter your information and subscribe.

![Create subscription from the Subscription Dashboard](/files/l6OCSwtsGZH8QcBmdSRs)

### View subscription&#x20;

You can view your current and previous subscription from the [Subscription Dashboard](https://www.mattermix.com/account/subscription) by clicking on the *Manage* button. This will redirect you to the Stripe Customer Portal where you can view and update your payment method, billing information, and invoice history.

![Manage subscription from the Subscription Dashboard](/files/Dgmu4tOWoU4uuyFFcItK)

### Cancel subscription&#x20;

You can cancel your subscription from the [Subscription Dashboard](https://www.mattermix.com/account/subscription) by clicking on the *Manage* button. This will redirect you to the Stripe Customer Portal where you can click the *Cancel plan* button.&#x20;

![Cancel subscription from the Stripe Customer Portal](/files/16bQPEQP9hmbsLN9Z6qv)

Last, confirm your cancelation by clicking the next *Cancel plan* button.

![Confirm cancelation from the Stripe Customer Portal](/files/CElK0c1suADMafzFThoP)

Your plan will be canceled immediately and you will be invoiced for any outstanding balances on your account.


