# Netsuite Webhook Setup

\**Note: Functionality is currently limited to Purchase Orders\**

1. **Create a Netsuite Integration in Violet**
   * Navigate to Violet and [set up a new Netsuite integration](https://docs.violetlabs.com/apps/n/netsuite).
2. **Create a Webhook in Violet**

   * Click your user profile picture in the bottom-left corner.
   * Go to the **Webhooks** page.

   <div align="left"><figure><img src="https://2091741164-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvrraExym8pNEUvBDoima%2Fuploads%2F9tIV8KtBq9iSWNIpWTAB%2Fimage.png?alt=media&#x26;token=9f05f85f-5600-4c1c-bc1d-278cad305597" alt=""><figcaption></figcaption></figure></div>

   * Click on <mark style="color:purple;">**+ CREATE WEBHOOK URL**</mark>
   * Select the Netsuite integration you created.
3. **Copy the Webhook URL**
   * Save the generated URL — **this will only display once**.
4. **Download and Update the Script**
   * Download the [Violet Netsuite Webhook Script](https://drive.google.com/file/d/1FHY3y0zU8uFZiu2VGhc6TxKGBiOZgSlg/view?usp=sharing).
   * Replace `[PASTE WEBHOOK URL GENERATED IN THE VIOLET WEBHOOKS TAB HERE]` with your Webhook URL.
5. **Upload Script to Netsuite**
   * Navigate in Netsuite to: `Customization → Scripting → Scripts → New`.
   * Upload the script and give it a name.
6. **Deploy the Script**
   * Under the **Deployments** tab:
     * Set **Applies To** → `Purchase Order`.
     * Set the deployment **Status** → `Released`.
   * Save the script.
7. **Set Audience**
   * Open the script deployment page.
   * Under **Audience**, select `All Employees`. This will ensure that the script runs on the appropriate create or edit actions regardless of which user takes the action.
8. **Verify Webhook Functionality**
   * The webhook should now fire events to Violet whenever a PO or PO line is created or edited.
   * **Note:** Deletes are not supported by Webhooks - they will be reflect on the next scheduled fetch from Netsuite.
9. **Test Webhook Functionality**
   * Edit a Purchase Order within Netsuite, and change the location of the Purchase Order.
   * Within Violet, go into the integration timeline on your Netsuite integration (under `Apps → [Your Netsuite Integration Name] → Click the Timeline icon labeled "View Integration Timeline”`)
   * Check and see if you see a `webhook event` within the timeline, near the top.
   * Check and see if the changed location updates within the corresponding entity in Violet. This may take a few minutes to process.
   * If any of these steps do not work, contact Violet.

### Possible Errors

* **Error on saving edited PO:**

  ```
  Error
  An unexpected error has occurred. Please click here to notify support and provide your contact information.
  ```

  * Cause: Script deployment in Netsuite is not working correctly.
  * Solution: Delete the deployment and script, then start over from step 5. If the issue persists, contact Violet.
* **Changes not showing in Violet (no error on save):**
  * Check the Netsuite script execution log for errors sending the webhook.
  * Check the integration timeline (under `Apps → [Your Netsuite Integration Name] → Click the Timeline icon labeled "View Integration Timeline”`) in Violet for processing errors.
  * Contact Violet with the collected information.
