---
updatedAt: 2025-09-17T22:29:09.000Z
agentTools:
  projectIndex: https://docs.vizionapi.com/llms.txt
---

# Receive notification when reference has been unsubscribed

```node Node
import axios from 'axios';

// Define reference IDs
const referenceIds = [
  "60af720c-4f4a-46ac-ad07-2630f3ce8fb4",
  // Add more reference IDs as needed
];

// Object to store polling intervals for each reference ID
const pollingIntervals = {};

// Function to send notification
const sendNotification = (referenceId, autoUnsubscribed) => {
  if (autoUnsubscribed) {
    console.log(`Reference ID ${referenceId} has been auto-unsubscribed!`);
   } else {

    console.log(`Reference ID ${referenceId} has been manually unsubscribed!`);
   }

  // Stop polling for this reference ID
  clearInterval(pollingIntervals[referenceId]);
};

// Function to poll the endpoint
const pollEndpoint = (referenceId) => {
  const apiUrl = `https://prod.vizionapi.com/references/${referenceId}`;
  const apiKey = 'YOUR_API_KEY_HERE'; // Replace 'YOUR_API_KEY_HERE' with your actual API key

  const options = {
    method: 'GET',
    url: apiUrl,
    headers: {
      accept: 'application/json',
      'X-API-Key': apiKey,
    }
  };

  axios.request(options)
    .then(response => {
      const reference = response.data;
      if (!reference.active) {
        sendNotification(referenceId, reference.auto_unsubscribed);
      }
    })
    .catch(error => {
      console.error(error);
    });
};

// Start polling for each reference ID
referenceIds.forEach((id) => {
  pollingIntervals[id] = setInterval(() => pollEndpoint(id), 60 * 60 * 1000);
});

```

```json Response Example
{"success":true}
```

# Define reference IDs array and polling object

<!-- node@4-10 -->

Create an array to store multiple reference IDs. Set up an object to track polling intervals for each reference ID.

# Send notification function

<!-- node@13-19 -->

Develop a function to handle a notification when reference has been deactivated/unsubscribed. Stop polling once a given reference has confirmed to be unsubscribed (active = false).

# Create polling function to access 'Get reference' endpoint

<!-- node@22-45 -->

Access the 'Get reference' endpoint and check whether reference has been deactivated.

# Start polling for each reference ID

<!-- node@47-51 -->

Iterate over array of reference IDs to begin polling.