Understanding Triggers

Triggers are events that automatically send API requests when something happens on your WordPress site. Instead of manually making API calls, triggers allow you to automatically notify external systems when users register, posts are published, orders are created, or other events occur. This article explains what triggers are, how they work, and how to configure them.

What is a Trigger?

A trigger is an automated action that sends an API request in response to a specific event on your WordPress site. When the event occurs, API Press automatically makes the API call you have configured, passing relevant data about the event.

Example Scenario

Imagine you have an external CRM system that needs to know whenever a new user registers on your WordPress site. Instead of manually logging in to the CRM each time, you can:

  1. Create an API connection to your CRM’s user creation endpoint
  2. Select the “User Registers” trigger
  3. Configure variables to pass the new user’s information

Now, every time someone registers, API Press automatically sends their information to your CRM.

How Triggers Work

When a trigger event occurs:

  1. WordPress fires the event (e.g., user registration)
  2. API Press detects the event and checks if a trigger is configured for it
  3. If a matching trigger is found, API Press gathers event data (user ID, email, etc.)
  4. The API request is sent to your configured endpoint with this data
  5. The external system receives the information and responds
  6. API Press logs the request for your records

Important: Triggers only work when the event actually occurs on your site. They do not retroactively send data for past events.

Available Triggers

API Press supports the following events as triggers:

User Registers

Fires when a new user creates an account on your WordPress site.

Available data: User ID, login, email, display name, registration date, user roles, first name, last name

Common use: Sync new users to a CRM, mailing list, or customer database

User Login

Fires when an existing user logs into your WordPress site.

Available data: User ID, login, email, display name, user roles

Common use: Track user activity, log logins to an external system, trigger welcome sequences

Post Published

Fires when a post is published on your site (both new posts and previously drafted posts).

Available data: Post ID, post type, status, title, permalink

Common use: Notify social media schedulers, send to publishing platforms, update content feeds

Post Created (PRO)

Fires when a new post is created (regardless of status: draft, published, scheduled, etc.).

Available data: Post ID, post type, title, permalink

Common use: Log new content creation, notify editorial systems

Post Updated (PRO)

Fires when an existing post is modified.

Available data: Post ID, post status, title, last modified date

Common use: Sync content changes to external sites, update search indexes

Post Deleted (PRO)

Fires when a post is permanently deleted from your site.

Available data: Post ID, post type, title

Common use: Remove content from external systems, clean up linked records

Contact Form 7 – Any Form (PRO)

Fires when a Contact Form 7 form is submitted on your site.

Available data: Form ID, form title, entry ID, all form field values

Common use: Send form submissions to CRM, create support tickets, add leads to email lists

WPForms – Any Form (PRO)

Fires when a WPForms form is submitted on your site.

Available data: Form ID, form title, all form field values

Common use: Sync form data to external services, create records in business systems

WooCommerce Order Created (PRO)

Fires when a new order is created in WooCommerce.

Available data: Order ID, order status, order total

Common use: Send orders to fulfillment systems, sync to accounting software

WooCommerce Order Updated (PRO)

Fires when an existing WooCommerce order is modified.

Available data: Order ID, order status, last updated time

Common use: Track order status changes, update external fulfillment systems

Free vs. Pro: Free version includes basic triggers (User Registers, User Login, Post events). Pro version adds form submissions (Contact Form 7, WPForms) and e-commerce (WooCommerce).

Configuring a Trigger

Step 1: Select Your Trigger

In the API Press admin, navigate to your API and find the Triggers tab. Click the trigger dropdown and select which event should trigger your API call. You can select multiple triggers for a single API.

Step 2: Set Up Your API Configuration

Make sure your API endpoint and method are configured correctly:

  • Set the URL to your external API endpoint that will receive the data
  • Choose the HTTP method (usually POST for sending data)
  • Configure authentication if required
  • Add any headers needed by the external API

Step 3: Use Variables to Pass Event Data

Use dynamic variables to include event data in your API request. Variables are enclosed in double brackets and are replaced with real values when the trigger fires.

Example: In your URL or body, you can include [[user.id]] and when a user registers, it will be replaced with the actual user’s ID number.

Step 4: Set Cooldown (Optional)

To prevent duplicate API calls for the same event, set a cooldown period. This prevents the same user, post, or form from triggering multiple API requests within a short time frame.

Example: Set cooldown to 5 minutes. If the same user logs in twice within 5 minutes, only the first login triggers an API call.

Using Variables

Variables are dynamic placeholders that get replaced with real data when a trigger fires. They allow you to pass event-specific information to your API.

Variable Format

Variables are enclosed in double brackets: [[variable.name]]

Common Variables (Available for All Triggers)

Variable Description Example Value
[[site.url]] Your WordPress site URL https://example.com
[[site.name]] Your WordPress site name My Business Site
[[site.admin]] Admin email address admin@example.com
[[request.uuid]] Unique ID for this request a1b2c3d4-e5f6-g7h8
[[request.timestamp]] Unix timestamp when request is sent 1719122400
[[date:Y-m-d H:i:s]] Current date/time in format you specify 2024-06-23 10:30:45
[[current_user.id]] ID of user making the API call 1
[[current_user.login]] Login of current user admin
[[current_user.email]] Email of current user admin@example.com

Event-Specific Variables

Each trigger has additional variables specific to that event. For example, the User Registers trigger includes user information:

Trigger Available Variables
User Registers / User Login [[user.id]][[user.login]][[user.email]][[user.display_name]][[user.first_name]][[user.last_name]][[user.roles]]
Post Published/Created/Updated/Deleted [[post.id]][[post.type]][[post.status]][[post.title]][[post.permalink]]
Contact Form 7 [[form.id]][[form.title]][[form.entry_id]][[form.fields.FIELD_NAME]]
WPForms [[form.id]][[form.title]][[form.fields.FIELD_ID]]
WooCommerce Orders [[wc.order.id]][[wc.order.status]][[wc.order.total]]

Finding Available Variables: When you select a trigger in the API Press admin, a list of available variables is displayed below the trigger selector. This list shows all variables available for the selected trigger(s).

How to Use Variables in Your API

In the URL (Query Parameters)

Add variables to your endpoint URL to pass data as query parameters:

https://api.example.com/users/register?user_id=[[user.id]]&email=[[user.email]]&site=[[site.url]]

In Headers

Include variables in custom headers:

Header name: X-User-Email Header value: [[user.email]]

In Request Body (POST Data)

Include variables in the request body JSON or form data:

{ “user_id”: [[user.id]], “email”: “[[user.email]]”, “display_name”: “[[user.display_name]]”, “registered”: “[[user.registered]]”, “site”: “[[site.url]]” }

Using Date Formatting Variables

The date variable allows you to format the current date and time:

[[date:Y-m-d]] Result: 2024-06-23 [[date:m/d/Y]] Result: 06/23/2024 [[date:Y-m-d H:i:s]] Result: 2024-06-23 10:30:45 [[date:Y-m-d H:i]] Result: 2024-06-23 10:30

Use standard PHP date formatting codes. Learn more about date formats in PHP documentation.

Trigger Examples

Example 1: Send New User to CRM

Trigger: User Registers

API Endpoint: https://crm.example.com/api/contacts/create

Method: POST

Request Body:

{ “first_name”: “[[user.first_name]]”, “last_name”: “[[user.last_name]]”, “email”: “[[user.email]]”, “source”: “wordpress”, “created”: “[[date:Y-m-d H:i:s]]” }

Every time someone registers on your WordPress site, their information is automatically added to your CRM.

Example 2: Notify Slack on New Post

Trigger: Post Published

API Endpoint: https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK

Method: POST

Request Body:

{ “text”: “New post published”, “blocks”: [ { “type”: “section”, “text”: { “type”: “mrkdwn”, “text”: “*[[post.title]]*\n<[[post.permalink]]|View Post>” } } ] }

When you publish a post, Slack receives a notification with the post title and link.

Example 3: Send Form Submission to Zapier

Trigger: Contact Form 7

API Endpoint: https://hooks.zapier.com/hooks/catch/YOUR/WEBHOOK/

Method: POST

Request Body:

{ “name”: “[[form.fields.your-name]]”, “email”: “[[form.fields.your-email]]”, “message”: “[[form.fields.your-message]]”, “submitted”: “[[date:Y-m-d H:i:s]]”, “source”: “[[site.url]]” }

Form submissions are sent to Zapier, which can then send data to thousands of other services.

Cooldown Period

The cooldown feature prevents the same trigger from firing multiple API requests in a short time frame. This is useful when:

  • You want to avoid duplicate API calls for the same event
  • The same user might trigger an event multiple times accidentally
  • You want to reduce load on external APIs
  • Your API charges per request

How Cooldown Works

If you set a 5-minute cooldown on the “User Login” trigger:

  1. User logs in at 10:00 AM – API request sent, cooldown activated
  2. Same user logs in at 10:02 AM – API request blocked (still in cooldown)
  3. Same user logs in at 10:05 AM – API request blocked (still in cooldown)
  4. Same user logs in at 10:06 AM – API request sent (cooldown expired)

Setting Cooldown

In the API Press admin, find the Cooldown field under your trigger selection. Enter the number of minutes:

  • 0 = No cooldown (default) – send API call every time event occurs
  • 5 = Wait 5 minutes before allowing another API call for same event
  • 60 = Wait 1 hour before allowing another API call

Note: Cooldown is per user/item. Different users can trigger API calls independently even within the cooldown period.

Troubleshooting Triggers

Trigger is not firing

Check:

  • Trigger is selected in the API configuration
  • API is published (draft APIs do not fire triggers)
  • Event actually occurred (e.g., user actually registered, not just a test)
  • Check API Press logs to confirm the request was sent

API request failed with error

Check:

  • External API endpoint URL is correct
  • Authentication credentials are valid
  • External API is online and responding
  • Request body format matches what external API expects
  • Headers are correct (Content-Type, Authorization, etc.)

Variables not being replaced with values

Check:

  • Variable names are spelled exactly as shown in the available variables list
  • Variables are enclosed in double brackets: [[variable.name]]
  • Variable is supported by the selected trigger
  • Data actually exists for that variable (e.g., user first name might be empty)

Too many duplicate requests

Solution:

  • Increase the cooldown period
  • Check if the event is being triggered multiple times (e.g., multiple post save hooks)
  • Review external system logs to confirm duplicates are actually occurring

Requests slow down site performance

Solution:

  • Increase API timeout setting if requests are taking time
  • Reduce frequency using cooldown period
  • Check if external API is slow to respond
  • Consider if trigger is truly needed for every event