# Backend Triggers

Use backend events to trigger surveys inside your mobile app and website. Additional properties can be passed with the backend events to add more context to users' responses.

### Setting up the Backend Trigger

* Navigate to Connections Tab > Backend Trigger on Blitzllama's dashboard
* Click on the Backend Trigger card and then click 'Enable'.&#x20;
* Copy the URL :link:(send backend trigger events on this URL) & the unique API Key 🔑 (add in the API header \[x-api-key]).

#### API call

```javascript
var request = require('request');

var options = {
  'method': 'POST',
  'url': 'https://events.blitzllama.com/api/v1/connections/backend/event', //copied url
  'headers': {
    'x-api-key': '<copied API Key>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
   "user_id":"user_123",
  "event_name":"item_added_to_cart",
  "properties": {
      "id": 1,
      "name": "War and Peace",
      "author": "Leo Tolstoy",
      "type": "hardcover",
      "category": "novel"
    }
  })
};

request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

```

{% hint style="info" %}
**event\_name** - this is the name of the backend trigger, which will show up in the Trigger tab on Blitzllama's dashboard after the first successful API.

**user\_id** - the unique user identifier.

**properties** -  JSON object that will be added to each survey responses.
{% endhint %}

**Sample payload**

```json
{
  "user_id":"user_123",
  "event_name":"item_added_to_cart",
  "properties": {
      "id": 1,
      "name": "War and Peace",
      "author": "Leo Tolstoy",
      "type": "hardcover",
      ...
      "category": "novel"
    }
  }  
```

###

### **How to trigger an in-app survey using Backend Trigger**

* In the survey editor navigate to "Configure & Launch" > "Select trigger" section&#x20;
* Click on "Activate with backend event" option
* Choose the backend triggers (all your backend triggers will be populated in the dropdown)
* Add event expiration time (max 100 hours). This allows you maintain relevancy of the survey questions.
* Lastly, choose where the surveys should show up on your app or website by selecting the frontend triggers from the "Select Trigger" dropdown.

<figure><img src="https://713176431-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MagfF5JPg-8vm99iTd9%2Fuploads%2FgYqCNQ5j8QxUJ7SjOYeR%2Fimage.png?alt=media&#x26;token=f8c36c2c-f57f-445a-8166-2c1dce675db3" alt=""><figcaption><p>In the above screenshot of a Sleep Tracking app, a sleep quality monitoring survey will be shown to the users within 2 hours of them ending their sleep ("ended sleep" event) on the app's homepage ("MainActivity" frontend trigger).</p></figcaption></figure>
