API Action

The API Action in Penbox Automations enables you to send HTTP requests to external systems, providing a powerful way to integrate with third-party tools and services. This action can be configured with an endpoint, method, JSON body, and headers.

Components of an API Action

An API action is composed of the following elements:

1. URL

The endpoint to which the HTTP request will be sent. This is a required field.

2. Method

The HTTP method to use for the request. While POST is the most commonly used method, other methods (e.g., GET, PUT, DELETE) may also be supported depending on your requirements.

3. JSON Body

The payload of the request, provided as a JSON object. This must be a valid JSON structure and can include dynamic mappings using Pen-Script.

Example of dynamic mapping using Pen-Script:

{"full_name": "{user.given_name} {user.family_name}"}

Pen-Script methods allow you to dynamically populate the JSON payload with values from the request or user data. Refer to the Pen-Script Documentation for a complete list of available methods.

4. Headers

Custom headers can be added to the request for authorization or other purposes. While the headers are configured directly in the script, Penbox supports the use of secrets for secure token storage.

Example of adding headers:

"headers": {  
  "Authorization": "Bearer abc"  
}

Using secrets for secure tokens:

"headers": {  
  "Authorization": "Bearer {$secrets.my_secret_1}"  
}

Refer to the Secrets Documentation for instructions on adding and managing secrets in your workspace.

Full JSON Example of an API Action

Below is an example of a fully configured API action in JSON format:

{  
  "type": "http",  
  "options": {  
    "url": "",  
    "headers": {  
      "Authorization": "Bearer abc"  
    },  
    "method": "POST",  
    "json": {  
      "full_name": "{user.given_name} {user.family_name}"  
    }  
  }  
}

Explanation of the JSON Example:

  • type: Specifies the type of action as an HTTP request.
  • options:
    • url: The endpoint for the HTTP request.
    • headers: Custom headers for the request, such as an Authorization token.
    • method: The HTTP method, in this case, POST.
    • json: The payload of the request, which can include dynamic fields populated with Pen-Script.

👀

Ensure that the JSON body and headers are correctly formatted to avoid errors when the automation runs. Use PenScript for dynamic values and refer to the Secrets Documentation for secure token handling.