---
title: create
slug: docs/TS2p-create
docTags: 
createdAt: 2021-08-04T18:23:39.000Z
---

This call creates a trigger. The arguments that must be included in the doc are described below:

# Basic parameters

| Name       | Type    | Required | Description                   |
| ---------- | ------- | -------- | ----------------------------- |
| `action`   | string  | true     | `create`                      |
| `group_id` | integer | true     | The project the product is in |
| `doc`      | array   | false    | See doc parameters below      |

# Doc Parameters

| Name              | Type              | Required | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ----------------- | ----------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `reverse_trigger` | boolean           | false    | If the user first meets a trigger condition and then later changes a value so the condition is not met, `True` will ensure the product is removed from the cart. This is generally the behavior you'd expect, and the default is `True`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `action`          | associative array | true     | Contains two variables `product_id` and `action_type`; see below for more. <br />*Ex.* <br />\{<br />"action": \{<br />product\_id: \[1, 2, etc...],<br />action\_type:<br />"show\_prod\_in\_list"<br />}<br />}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `product_id`      | array             | true     | A list of [product id's](https://api.regpack.com/docs/products) you'd like the trigger to be set for.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `action_type`     | string            | true     | One of four actions the product can take when the trigger condition is met:<br />`add_product_no_show`: This adds the product to the user's cart automatically when the conditions are met. Additionally it ensures that users who do *not* meet the condition can not select the product on the  product selection widget. When adding automatically to a user, this is the most common option. <br />`show_prod_in_list`: The product shows in the product selection widget where the user has the option can select it.<br />`remove_prod_from_list`: Ensures that the product doe&#x73;*&#x20;not* appear for users to select on the product selection widget.<br />`add_product`: This adds the product automatically if they meet the conditions, but also shows the product to users who do *not* meet the condition on the product selection widget. |
| `conditions`      | associative array | true     | Contains two variables `andor` and `condition_list`; see below for more.<br />*Ex.*<br />"conditions": \{<br />"andor": "and",<br />"condition\_list": \[<br />\{<br />"field\_id": "instrument",<br />"field\_value": "guitar"<br />},<br />\{<br />etc...<br />}<br />]<br />}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `andor`           | string            | true     | When setting a trigger you can include one or more conditions. If adding multiple, `"and"` means *all* of the conditions must me true while `"or"` means that only one of the conditions must be true. Default is `"and"`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `condition_list`  | array             | true     | This is an array of associative arrays, each of which describes the trigger condition which must be met. <br />To trigger on a field, you include `field_id` and `field_value`.<br />To trigger on a status being applied to a user, you include `status_id` and `action`. `action` only has one argument, `"set_status"`. This is met when a status is applied to a user. <br />To trigger on the addition of some other product, include product\_id and action. action only has one argument, `"product_added"`. This is met when a product is added to a users cart, either through the API, manually by an admin, or by the user. <br />Values are case sensitive.<br />                                                                                                                                                                                |



# Example

### Call

:::CodeblockTabs
```curl
curl -X POST "https://www.regpack.com/reg/api2/triggers/" \
     -H "Content-Type: application/json" \
     -H "Accept: application/json" \
     -H "Api-Id: 15263" \
     -H "Api-user: api_admin@regpacks.com" \
     -H "Api-Token: cd2e514f-7gab-3cde-62fg-51abcd4e7362" \
     -d '{
    "action": "create",
    "group_id": 1625251,
    "doc": {
        "reverse_trigger": true,
        "action": {
            "product_id": "2767021", 
            "action_type": "add_product_no_show"
        },
        "conditions": {
            "andor": "and",
            "condition_list": [
                {
                    "field_id": "f_349514_4451053", 
                    "field_value": "guitar"
                },
                {
                    "product_id": "2594110", 
                    "action": "product_added"
                },
                {
                    "status_id": "90809", 
                    "action": "set_status"
                }
            ]
        }
    }
}'

```

```python
import requests
import json
triggers_endpoint = https://www.regpack.com/reg/api2/triggers/
headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Api-Id": "15263",
    "Api-user": "api_admin@regpacks.com",
    "Api-Token": "cd2e514f-7gab-3cde-62fg-51abcd4e7362",
}
payload = {
    "action": "create",
    "group_id": 1625251,
    "doc": {
        "reverse_trigger": True,
        "action": {
            "product_id": "2767021", 
            "action_type": "add_product_no_show"
            },
        "conditions": {
            "andor": "and",
            "condition_list": [
                {
                "field_id": "f_349514_4451053", 
                "field_value": "guitar"
                },
                {
                "product_id": "2594110", 
                "action": "product_added"
                },
                {
                "status_id": "90809", 
                "action": "set_status"
                },
            ],
        },
    },
}

add_trigger_json = json.dumps(payload)
add_trigger_response = requests.post(url=triggers_endpoint, 
                                              data=add_trigger_json, 
                                              headers=headers, 
                                              timeout=10)
```
:::

### Response

```json
{
  "undo_trigger": true,
  "action": {
    "action_vars": {
      "product_id": "1654403"
    },
    "action_type": "add_product_no_show"
  },
  "log_conds": {
    "andor": "and",
    "conditions": [
      {
        "log_ex_id": "field_set_to",
        "vars": {
          "field_id": "f_349514_4451053",
          "field_value": "guitar"
        }
      },
      {
        "log_ex_id": "product_added",
        "vars": {
          "product_id": "745947"
        },
        "multi_id": "multi_product_added_745947"
      },
      {
        "log_ex_id": "set_status",
        "vars": {
          "status_id": "70418"
        },
        "multi_id": "multi_set_status_70418"
      }
    ]
  },
  "text_qv": " <span class=\"fs_wrap\">  <span class=\"filter_name\">Rate Type</span>  <em>is</em>  <span class=\"answer\"><span class=\"val\">Bucket Rate </span></span> <a href=\"javascript;\" class=\"fs_delete\" rel=\"f231\"></a> </span> <span class=\"fs_wrap\">  <span class=\"filter_name\">Administrator License - 12 month - Legacy Price - Business Package</span>  <em>is</em>  <span class=\"answer\"><span class=\"val\">added to user cart</span></span> <a href=\"javascript;\" class=\"fs_delete\" rel=\"multi_product_added_745947\"></a> </span> <span class=\"fs_wrap\">  <span class=\"filter_name\">Status is: Active</span>  <a href=\"javascript;\" class=\"fs_delete\" rel=\"multi_set_status_70418\"></a> </span>",
  "ui_obj": [
    {
      "trigger_id": "mongo_text_search",
      "vars": [
        {
          "rate_type": "guitar"
        }
      ]
    },
    {
      "trigger_id": "product_logs",
      "multi_id": "multi_product_added_745947",
      "vars": [
        {
          "log_ex_id": "product_added"
        },
        {
          "trigger_vars": "{\"product_id\":\"745947\"}"
        }
      ]
    },
    {
      "trigger_id": "set_status_log",
      "vars": [
        {
          "log_ex_id": "set_status"
        },
        {
          "trigger_vars": "{\"status_id\":\"70418\"}"
        }
      ]
    }
  ],
  "group_id": "1625251",
  "_id": "100906231_1656649",
  "creation_date": {
    "sec": 1729011822,
    "usec": 42000
  },
  "trig_action_cond_level": "parent_condition_child_condition_child_action",
  "success": true
}

```






