Unsubscribe Customer from an Alert Request
We provide a storefront API endpoint to unsubscribe a customer from an alert request. This can be useful if you wish to build a management portal in the customer account area. See also Fetching a customer's alert requests.
Unsubscribe Alert Request API
This API only supports logged-in customers
Endpoint
DELETE https://backinstockalerts.space48apps.com/api/store/{store_hash}/customers/{jwt}/alert-requests/{id}
Path Parameters
| Field | Description |
|---|---|
store_hash |
The store hash of the BigCommerce store |
jwt |
The JSON Web Token is provided by BigCommerce’s Current Customer API when requested using the Back in Stock Alerts Client ID. See example below. |
id |
The alert request ID. |
Headers
| Header | Value | Description |
|---|---|---|
Accept |
application/json |
Required header to receive a JSON response. |
Response
When successful, the response will be empty with the 204 HTTP status code.
Sample Code
Fetching a Current Customer JWT
The first step before making a request to the Back in Stock Alerts API for this endpoint is to request a JWT from BigCommerce to identify the currently logged-in customer using the Current Customer API.
const app_client_id = '9s57chpu0tik4pw7wz9d2p022qnff6n'; // Back in Stock Alerts Client ID
const fetchCustomerJWT = async (app_client_id) => {
const response = await fetch(
'/customer/current.jwt?app_client_id=' + app_client_id
);
if (!response.ok) {
if (response.status === 404) {
return new Error('Customer not logged in.');
}
return new Error('Unable to identify customer');
}
return await response.text();
}
const jwt = await fetchCustomerJWT(app_client_id);
Unsubscribing a customer from an alert request
Then, you can use this JWT to delete an alert request for this customer:
const deleteAlertRequest = async (store_hash, jwt, alert_request_id) => {
const url = "https://backinstockalerts.space48apps.com/api/store/" + store_hash + "/customers/" + jwt + "/alert-requests/" + alert_request_id;
const response = await fetch(url, {
method: "DELETE",
headers: { Accept: "application/json" },
});
if (!response.ok) {
if (response.status === 404) {
return new Error(response?.data?.error || "Alert request not found.");
} else if (response.status === 402) {
return new Error(response?.data?.error || "A subscription to Back in Stock Alerts is required to perform this action.");
}
return new Error("Unable to unsubsribe from alert request.");
}
// If 204 No Content, return a simple success message
if (response.status === 204) {
return { success: true };
}
}
// Example usage
const store_hash = "nqivp06qsb"; // Change for your store
const alert_request_id = 12345 // Obtain from fetch alert requests API
const unsubscribe = await deleteAlertRequest(store_hash, jwt, alert_request_id);
if (unsubscribe instanceof Error) {
console.error(unsubscribe.message);
} else {
console.log("Successfully unsubscribed from alert request:", unsubscribe);
}