Triggers API

This API enables you to execute Pinkfish automations that you’ve created and published. With these “trigger” endpoints, you can integrate automated workflows into your applications and systems. You can also trigger one automation from another automation - thereby chaining automations together.

There is no API for other services that you might be looking for, such as retrieving monitor logs, billing data, or automation CRUD operations.

Key Concepts

  • Automation: A series of steps that perform a specific task or workflow.

  • Trigger: A mechanism to initiate an automation via API call. You must set up a trigger in order to call your automation by API.

  • Run: An instance of an automation being executed.

Execution Models

Our API supports two execution models:

Asynchronous (Fire and Forget)

  • When you call an automation trigger with x-api-wait: false, the API immediately returns (with a runId in the response header)

  • The automation runs asynchronously in the background

  • Results are not directly returned via the API call

  • Best for long-running automations or when immediate response isn’t required

Synchronous (Wait for Result)

  • When you call an automation trigger with x-api-wait: true, the API waits for up to 60 seconds for completion

  • If the automation completes within this window, the response body contains the results

  • If the automation takes longer than 60 seconds, the call returns with a timeout and a runId

  • Best for quick automations where you need immediate results

To view the outcome of an automation run (especially for async calls or timeouts), you have several options:

  1. Check the effects of the automation (e.g., a created Google Doc or message to Slack). This is entirely up to you to devise.

  2. Load the automation in the platform UI (you will see results from the last run). Warning: if you have edited your automation since your last publish, you won’t see results here.

  3. Use the Runs Monitor in the platform to view execution status and results. This is the most reliable and simple method.

Authentication

All API endpoints are authenticated using API keys. Include your API key in the X-API-KEY header of each request:

X-API-KEY: YOUR_API_KEY_HERE

You can generate API keys in two ways:

  1. In the Library section of the platform interface.

  2. While setting up a trigger for an automation.

Triggering Automations

Automations are executed by calling their associated triggers. Each trigger has a unique endpoint and may accept parameters either as query parameters (for GET requests), as form-encoded data, or as a json payload. Set up your trigger(s) in the Automation editor (requires first publishing a version of your automation)

Example Requests

Asynchronous Request (Form-encoded)

curl --location 'https://triggers.app.pinkfish.ai/ext/triggers/YOUR_AUTOMATION_ID' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'X-API-KEY: YOUR_API_KEY' \
--header 'x-api-wait: false' \
--data-urlencode 'Hello=World'

Synchronous Request (JSON)

curl --location 'https://triggers.app.pinkfish.ai/ext/triggers/YOUR_AUTOMATION_ID' \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: YOUR_API_KEY' \
--header 'x-api-wait: true' \
--data '{
    "user_request": "what is the capital of France"
}'

Example Responses

Asynchronous Response

The response body will be null. You can find your runId in the header as X-Pf-Run-Id.

Response Headers
Date: Wed, 18 Sep 2024 02:12:39 GMT
Content-Type: application/json
Content-Length: 0
Connection: keep-alive
x-amzn-RequestId: eea7315a-f8c2-4c55-88df-50f8332bf25e
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type, Authorization
X-Pf-Automation-Id: crkbpb5b9nas7163a4kg
x-amz-apigw-id: eR2LpEkBPHcEK9w=
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
X-Amzn-Trace-Id: Root=1-66ea3717-03397efa60d2632525a8fe5f
X-Pf-Run-Id: 1726625559774364090
Response Body
null

Synchronous Response (Successful)

If the automation completes within 60 seconds, you’ll receive the results in the response body:

{
    "automationId": "csrtvshm36rc711dhoqg",
    "automationVersion": 1,
    "automationName": "Hello Triggers",
    "id": "1731715310692281375",
    "type": "TRIGGER",
    "stepMap": {
        "1": 2,
        "2": 2
    },
    "inputs": "",
    "triggerId": "csru0bg3tgfs71020ssg",
    "results": [
        {
            "stepIndex": 1,
            "stepVersion": 2,
            "result": {
                "stepIndex": 1,
                "resultType": "markdown",
                "result": "# Hello from step 1! 👋"
            },
            "exitCode": 0,
            "duration": 790
        },
        {
            "stepIndex": 2,
            "stepVersion": 2,
            "result": {
                "stepIndex": 2,
                "resultType": "plaintext",
                "result": "Hello from step 2!"
            },
            "exitCode": 0,
            "duration": 707
        }
    ],
    "started": "2024-11-16T00:01:50Z",
    "startedBy": "588233679836"
}

Synchronous Response (Timeout)

If the automation doesn’t complete within 60 seconds:

Response Headers
[same as async response]

Response Body
{
    "status": "timeout",
    "message": "Automation execution exceeded 60 second timeout. Use runId to check results in Run Monitor."
}

Getting Started

To begin using the AI Automation API, you’ll need to:

  1. Create and publish an automation using our platform.

  2. Set up a trigger for your automation.

  3. Generate an API key from either the Library section or during trigger setup.

  4. Choose your execution model (sync or async) based on your automation’s expected runtime and your application’s needs.

  5. Use the provided trigger endpoint to execute your automation, including your API key and preferred wait setting in the request headers.