# MESA Admin API

The MESA Admin API allows you to programmatically interact with MESA. All requests must include your API key which can be found in My Account > Connections.

## Key

### Value

{url}  
https://api.getmesa.com/v1

{uuid}  
Your store’s unique identifier: {{uuid}}.myshopify.com

## Workflows

### Get list of automations

`GET http://{{url}}/admin/{uuid}/automations.json`

Returns a list of automations for a store, sorted by most recently created first.

#### Path parameters

- `uuid` string Required

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Body

- `application/json`  
- object Optional Example:
```json
{"automations":[{"uuid":"my-store","created_by":"","key":"etsy_order_send_to_google_sheets","name":"Send Etsy orders to Google Sheets","version":"1.0.0","template":"etsy/order/send_to_google_sheets","description":"Consolidate your Etsy orders in Google Sheets for real-time tracking and improved order management. This template will automatically send Etsy order details to a Google Sheets spreadsheet when a customer completes an order on Etsy.","video":"","is_premium":false,"tags":[],"source":"","destination":"","enabled":false,"did_complete":false,"logging":true,"debug":false,"setup":"incomplete","seconds":135,"notifications":{"enabled":false,"emails":["example@theshoppad.com"]},"_id":"65f1fdbbb54ac273e806026b","created_at":"Mar 13 2020","updated_at":"Mar 13 2024"}]}
```

#### Responses

- `200` Successful response

```json
GET /admin/{uuid}/automations.json HTTP/1.1
Host: {{url}}
Content-Type: application/json
Accept: */*
Content-Length: 776

{
  "automations": [
    {
      "uuid": "my-store",
      "created_by": "",
      "key": "etsy_order_send_to_google_sheets",
      "name": "Send Etsy orders to Google Sheets",
      "version": "1.0.0",
      "template": "etsy/order/send_to_google_sheets",
      "description": "Consolidate your Etsy orders in Google Sheets for real-time tracking and improved order management. This template will automatically send Etsy order details to a Google Sheets spreadsheet when a customer completes an order on Etsy.",
      "video": "",
      "is_premium": false,
      "tags": [],
      "source": "",
      "destination": "",
      "enabled": false,
      "did_complete": false,
      "logging": true,
      "debug": false,
      "setup": "incomplete",
      "seconds": 135,
      "notifications": {
        "enabled": false,
        "emails": [
          "example@theshoppad.com"
        ]
      },
      "_id": "65f1fdbbb54ac273e806026b",
      "created_at": "Mar 13 2020",
      "updated_at": "Mar 13 2024"
    }
  ]
}
```

### Get the mesa.json file for an automation

`GET http://{{url}}/admin/{uuid}/automations/{automation_key}.json`

#### Path parameters

- `uuid` string Required
- `automation_key` string Required

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`
- `Content-Type` string Optional Example: `application/json`

#### Responses

- `200` Successful response

```json
GET /admin/{uuid}/automations/{automation_key}.json HTTP/1.1
Host: {{url}}
Accept: */*
```

### Create or update an Automation configuration

`POST http://{{url}}/admin/{uuid}/automations.json`

Updates the Inputs, Outputs, Credentials and Storage for an automation.

#### Path parameters

- `uuid` string Required

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Body

- `application/json`  
- object Optional Example:
```json
{"key":"","name":"","config":{"inputs":[],"outputs":[],"secrets":[],"storage":[],"files":[],"overwrite":false}}
```

#### Responses

- `200` Successful response

```json
POST /admin/{uuid}/automations.json HTTP/1.1
Host: {{url}}
Content-Type: application/json
Accept: */*
Content-Length: 111

{
  "key": "",
  "name": "",
  "config": {
    "inputs": [],
    "outputs": [],
    "secrets": [],
    "storage": [],
    "files": [],
    "overwrite": false
  }
}
```

### Uninstall an Automation

`DELETE http://{{url}}/admin/{uuid}/automations/{automation_key}.json`

#### Path parameters

- `uuid` string Required
- `automation_key` string Required Example: `new_workflow_1`

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Responses

- `200` Successful response

```json
DELETE /admin/{uuid}/automations/{automation_key}.json HTTP/1.1
Host: {{url}}
Accept: */*
```

## Connections

### Get a list of Credentials

`GET http://{{url}}/admin/{uuid}/{automation_key}/credentials.json`

Returns a list of all Credential names.

#### Path parameters

- `uuid` string Required
- `automation_key` string Required

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Responses

- `200` Successful response

```json
GET /admin/{uuid}/{automation_key}/credentials.json HTTP/1.1
Host: {{url}}
Accept: */*
```

### Create a new Credential

`POST http://{{url}}/admin/{uuid}/{automation_key}/credentials.json`

#### Path parameters

- `uuid` string Required
- `automation_key` string Required Example: `new_workflow_1`

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Body

- `application/json`  
- object Optional Example:
```json
{"secret":{"key":"mysecret","value":"myvalue"}}
```

#### Responses

- `200` Successful response

```json
POST /admin/{uuid}/{automation_key}/credentials.json HTTP/1.1
Host: {{url}}
Content-Type: application/json
Accept: */*
Content-Length: 47

{
  "secret": {
    "key": "mysecret",
    "value": "myvalue"
  }
}
```

### Update an existing Credential

`PUT http://{{url}}/admin/{uuid}/{automation_key}/credentials/{credential_key}.json`

#### Path parameters

- `uuid` string Required
- `automation_key` string Required Example: `new_workflow_1`
- `secret_key` string Required

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Body

- `application/json`  
- object Optional Example:
```json
{"secret":{"value":"myvalue"}}
```

#### Responses

- `200` Successful response

```json
PUT /admin/{uuid}/{automation_key}/credentials/{credential_key}.json HTTP/1.1
Host: {{url}}
Content-Type: application/json
Accept: */*
Content-Length: 30

{
  "secret": {
    "value": "myvalue"
  }
}
```

### Delete a Credential

`DELETE http://{{url}}/admin/{uuid}/{automation_key}/credentials/{credential_key}.json`

#### Path parameters

- `uuid` string Required
- `automation_key` string Required Example: `new_workflow_1`
- `secret_key` string Required Example: `googlesheets_1`

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Responses

- `200` Successful response

```json
DELETE /admin/{uuid}/{automation_key}/credentials/{credential_key}.json HTTP/1.1
Host: {{url}}
Accept: */*
```

## Storage

### Get a list of all Storage items

`GET http://{{url}}/admin/{uuid}/{automation_key}/storage.json`

Returns a list of all Storage item names.

#### Path parameters

- `uuid` string Required
- `automation_key` string Required Example: `new_workflow_1`

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Responses

- `200` Successful response

```json
GET /admin/{uuid}/{automation_key}/storage.json HTTP/1.1
Host: {{url}}
Accept: */*
```

### Create a new Storage item

`POST http://{{url}}/admin/{uuid}/{automation_key}/storage.json`

The value parameter can be a string, an object, an array, or a boolean value.

#### Path parameters

- `uuid` string Required
- `automation_key` string Required Example: `new_workflow_1`

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Body

- `application/json`  
- object Optional Example:
```json
{"storage":{"key":"{{storage_key}}","value":{"mykey":"myvalue"}}}
```

#### Responses

- `200` Successful response

```json
POST /admin/{uuid}/{automation_key}/storage.json HTTP/1.1
Host: {{url}}
Content-Type: application/json
Accept: */*
Content-Length: 65

{
  "storage": {
    "key": "{{storage_key}}",
    "value": {
      "mykey": "myvalue"
    }
  }
}
```

### Get the value of a Storage item

`GET http://{{url}}/admin/{uuid}/{automation_key}/storage/{storage_key}.json`

#### Path parameters

- `uuid` string Required
- `automation_key` string Required Example: `new_workflow_1`
- `storage_key` string Required Example: `storage_1`

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Responses

- `200` Successful response

```json
GET /admin/{uuid}/{automation_key}/storage/{storage_key}.json HTTP/1.1
Host: {{url}}
Accept: */*
```

### Update an existing Storage item

`PUT http://{{url}}/admin/{uuid}/{automation_key}/storage/{storage_key}.json`

#### Path parameters

- `uuid` string Required
- `automation_key` string Required Example: `new_workflow_1`
- `storage_key` string Required Example: `storage_1`

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Body

- `application/json`  
- object Optional Example:
```json
{"storage":{"value":"mynewstringvalue"}}
```

#### Responses

- `200` Successful response

```json
PUT /admin/{uuid}/{automation_key}/storage/{storage_key}.json HTTP/1.1
Host: {{url}}
Content-Type: application/json
Accept: */*
Content-Length: 40

{
  "storage": {
    "value": "mynewstringvalue"
  }
}
```

### Deletes a Storage item

`DELETE http://{{url}}/admin/{uuid}/{automation_key}/storage/{storage_key}.json`

#### Path parameters

- `uuid` string Required
- `automation_key` string Required Example: `new_workflow_1`
- `storage_key` string Required Example: `storage_1`

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Responses

- `200` Successful response

```json
DELETE /admin/{uuid}/{automation_key}/storage/{storage_key}.json HTTP/1.1
Host: {{url}}
Accept: */*
```

## Scripts

### Get a list of Scripts

`GET http://{{url}}/admin/{uuid}/{automation_key}/scripts.json`

Returns a list of all Scripts, including the Script code.

#### Path parameters

- `uuid` string Required

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Responses

- `200` Successful response

```json
GET /admin/{uuid}/{automation_key}/scripts.json HTTP/1.1
Host: {{url}}
Accept: */*
```

### Create or update a Script

`POST http://{{url}}/admin/{uuid}/{automation_key}/scripts.json`

#### Path parameters

- `uuid` string Required
- `automation_key` string Required Example: `new_workflow_1`

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Body

- `application/json`  
- object Optional Example:
```json
{"script":{"filename":"myscript.js","code":"// Javascript goes here"}}
```

#### Responses

- `200` Successful response

```json
POST /admin/{uuid}/{automation_key}/scripts.json HTTP/1.1
Host: {{url}}
Content-Type: application/json
Accept: */*
Content-Length: 70

{
  "script": {
    "filename": "myscript.js",
    "code": "// Javascript goes here"
  }
}
```

### Delete a Script

`DELETE http://{{url}}/admin/{uuid}/{automation_key}/scripts.json`

#### Path parameters

- `uuid` string Required

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Responses

- `200` Successful response

```json
DELETE /admin/{uuid}/{automation_key}/scripts.json HTTP/1.1
Host: {{url}}
Accept: */*
```

## Testing

### Run a test

`POST http://{{url}}/admin/{uuid}/{automation_key}/triggers/{trigger_key}/test.json`

Trigger a test with a specific payload.

#### Path parameters

- `uuid` string Required
- `automation_key` string Required Example: `new_workflow_1`
- `trigger_key` string Required Example: `shopify_1`

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Body

- `application/json`  
- object Optional Example:
```json
{"payload":{}}
```

#### Responses

- `200` Successful response

```json
POST /admin/{uuid}/{automation_key}/triggers/{trigger_key}/test.json HTTP/1.1
Host: {{url}}
Content-Type: application/json
Accept: */*
Content-Length: 14

{
  "payload": {}
}
```

## Tasks

### Replay a task

`POST http://{{url}}/admin/{uuid}/tasks/{task_id}/replay.json`

Restart the execution of the workflow from a specific task.

#### Path parameters

- `uuid` string Required
- `task_id` string Required

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Responses

- `200` Successful response

```json
POST /admin/{uuid}/tasks/{task_id}/replay.json HTTP/1.1
Host: {{url}}
Accept: */*
```

## Templates

### Install a template from the Mesa Template library

`POST http://{{url}}/admin/{uuid}/templates/install.json`

#### Path parameters

- `uuid` string Required

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Body

- `application/json`  
- object Optional Example:
```json
{"template":"shoppad/mesa-templates/tests/kitchen-sink","force":true}
```

#### Responses

- `200` Successful response

```json
POST /admin/{uuid}/templates/install.json HTTP/1.1
Host: {{url}}
Content-Type: application/json
Accept: */*
Content-Length: 69

{
  "template": "shoppad/mesa-templates/tests/kitchen-sink",
  "force": true
}
```

## Logs

### Get the 50 most recent log entries

`GET http://{{url}}/admin/{uuid}/logs.json`

Returns a list of the most recent 50 log entries.

#### Path parameters

- `uuid` string Required

#### Header parameters

- `x-api-key` string Optional Example: `{{api_key}}`

#### Responses

- `200` Successful response

```json
GET /admin/{uuid}/logs.json HTTP/1.1
Host: {{url}}
Accept: */*
```
