# Triggering campaigns

Depending on the type of your campaign, you must set up different campaign triggers: manual, scheduled, remote action, or via API.

## Triggering a campaign manually <a href="#triggeringcampaigns-triggeringacampaignmanually" id="triggeringcampaigns-triggeringacampaignmanually"></a>

To manually trigger a campaign, you must:

1. Grant *Trigger manually all campaigns* or share a campaign with trigger permission.
2. Configure the campaign for a Manual trigger.

Refer to the [Manage Campaigns](https://docs.nexthink.com/platform/~/changes/Sh4xqs4GDClkDKT9Hvux/user-guide/campaigns/managing-campaigns) documentation for more information.

To manually trigger a campaign from the list of results of an NQL query on users on the Investigations page:

* Select a user or a set of **Users** from the list on the Investigations page.
* Choose **Launch campaigns** from the action bar at the button of the page. A list of the available campaigns pops up.

<figure><img src="https://268444917-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxJSUDk9NTtCHYPG5EWs3%2Fuploads%2Fgit-blob-0ab07ad9646b7545222a06ce3f63dfcc2a19f3ab%2Ftriggeringcampaings-1700569503.png?alt=media" alt="" width="760"><figcaption></figcaption></figure>

* Select the campaign and click **Send**.
  * A warning message appears displaying the number of targeted employees selected and asking for confirmation. If the campaign has parameters, you must provide a value for each parameter on the **Send campaign** popup window. Click **Yes** to proceed.
  * If all employees have a valid user SID, a validation message confirms the system has triggered the campaign.
  * If there is a mix of employees with valid or invalid SIDs, a warning message confirms that the system can only trigger the campaign for those employees with valid SIDs.
  * If all employees have an invalid SID, an error message confirms that the system cannot trigger the campaign.

{% hint style="info" %}
Refer to [Types of campaigns](https://docs.nexthink.com/platform/~/changes/Sh4xqs4GDClkDKT9Hvux/user-guide/campaigns/creating-campaigns/types-of-campaigns) documentation for information on parameters for manual and API campaigns.
{% endhint %}

## Triggering a scheduled campaign <a href="#triggeringcampaigns-triggeringascheduledcampaign" id="triggeringcampaigns-triggeringascheduledcampaign"></a>

Once you publish a scheduled campaign, the evaluation of the NQL query defined in the **Schedule** tab of the *Edit campaign* page begins.

The query will be re-evaluated, relative to the time it was first published, **daily** or **hourly**, depending on the option **Only once** or **Again after** that was selected, according to the following rules:

* **Only once:** the campaign will only be sent once, and will never recur. Use this option, for example, for employee onboarding campaigns, one-time surveys or notifications, and other one-time communications. With this option, the system evaluates the NQL query **every 24 hours** from the time the campaign is published, to ensure only the employees who have not yet answered or declined the campaign receive it.
* **Again after**: the option to enable recurring campaigns. Use it, for example, for proactive fixes, a reminder to restart computers regularly or for surveys that need to be sent at specific intervals. To provide more immediate feedback, the system evaluates the campaign **every hour**. To protect employees from unnecessary interruption, they will not receive the campaign if they have already answered it or declined it within the selected timeframe. For example, if you choose the campaign to be resent again after one week, the system will resend it seven days after the employee has either answered or declined the campaign. If you choose one month, the system will resend it 30 days after the employee has either answered or declined the campaign.

To randomly select a different sample of employees to continuously collect the sentiment data, set up the query below. Replace `#dex_campaign_name` with the **NQL ID** of the campaign and adjust the limit below set as `50` to specify the number of new users the campaign targets every hour.

Note that you need to:

* Define the trigger **Schedule** and select **Only after** the (minimum) number of days you want to have in between responses for each employee
* First, save the campaign at least once before you can use the below NQL query, so that the system is aware that your campaign exists and does not generate a *Table does not exist* error when validating the NQL query.

{% code lineNumbers="true" %}

```
users
| include campaign.#dex_campaign_name.responses
| compute number_of_requests = count()
| sort number_of_requests asc
| limit 50
```

{% endcode %}

## Triggering a remote action campaign <a href="#triggeringcampaigns-triggeringaremoteactioncampaign" id="triggeringcampaigns-triggeringaremoteactioncampaign"></a>

Once you have published a remote action campaign, add its NQL ID to the remote action’s scripts to trigger the campaign.

### Retrieving campaign NQL ID <a href="#triggeringcampaigns-retrievingcampaignnqlid" id="triggeringcampaigns-retrievingcampaignnqlid"></a>

* Select **Campaigns** from the main menu.
* Click on **Manage campaigns** in the navigation panel.
* Click on the title of the campaign you wish to connect to.
* Copy the NQL ID value from the NQL ID field in the **General** tab of the configuration page.
* Paste the value into your remote action script. Refer to the following documentation for details:
  * [Writing scripts for remote actions on Windows](https://docs.nexthink.com/platform/~/changes/Sh4xqs4GDClkDKT9Hvux/user-guide/remote-actions/managing-remote-actions/writing-scripts-for-remote-actions-on-windows)
  * [Writing scripts for remote actions on Mac](https://docs.nexthink.com/platform/~/changes/Sh4xqs4GDClkDKT9Hvux/user-guide/remote-actions/managing-remote-actions/writing-scripts-for-remote-actions-on-mac)

Nexthink recommends using NQL ID as a campaign identifier if you use Collectors version 23.5 or higher. You can still use campaign UID for compatibility reasons.

### Retrieving campaign UID <a href="#triggeringcampaigns-retrievingcampaignuid" id="triggeringcampaigns-retrievingcampaignuid"></a>

* Select **Campaigns** from the main menu.
* Choose the campaign you wish to connect to from the navigation menu.
* Locate the UID of the campaign as part of the URL and copy it for the remote action.

<figure><img src="https://268444917-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxJSUDk9NTtCHYPG5EWs3%2Fuploads%2Fgit-blob-588ff68a13664c9ce5406cce01b0c51786853866%2Fcamp-1698302462.png?alt=media" alt="Finding UID in Campaigns" width="756"><figcaption></figcaption></figure>

## Triggering a campaign using the API <a href="#triggeringcampaigns-triggeringacampaignusingtheapi" id="triggeringcampaigns-triggeringacampaignusingtheapi"></a>

Trigger campaigns using the Nexthink Campaigns API, giving you the flexibility to create integrations with external applications. For parametric campaigns, specify the values of each parameter defined for the campaign. Visit the [developer.nexthink.com](https://developer.nexthink.com) website to learn more.

## Triggering a campaign using a workflow <a href="#triggeringcampaigns-triggeringacampaignusingtheapi" id="triggeringcampaigns-triggeringacampaignusingtheapi"></a>

Trigger campaigns using the Nexthink Workflow API to notify employees about remediations that are taking place, or to prompt for permission or additional information that a workflow needs to continue running an automated remediation.

To use a campaign in a workflow, ensure that:

* The workflow trigger is set.
* The campaign contains only single answer questions.
* The campaign is published.
