Skip to content

Instantly share code, notes, and snippets.

@raxityo
Last active March 27, 2024 13:59
Show Gist options
  • Save raxityo/c82abe49b77d5feaeb5cf6b69f0e0d9d to your computer and use it in GitHub Desktop.
Save raxityo/c82abe49b77d5feaeb5cf6b69f0e0d9d to your computer and use it in GitHub Desktop.
Clip all available BJ's coupons
// ==UserScript==
// @name BJ's Coupon Clipper
// @namespace Violentmonkey Scripts
// @match https://www.bjs.com/
// @grant none
// @version 1.0
// @author @raxityo
// @description 3/24/2024, 11:01:30 PM
// ==/UserScript==
/**
* Clip all available BJ's coupons
* - Login to BJ's website
* - Open dev console and paste this function
* - Run it! Example `await clipAllOffers()`
* @return {Promise<T>}
*/
(async function clipAllOffers() {
const membershipNumber = localStorage.getItem("x_MembershipNumber");
const zipcode = JSON.parse(
localStorage.getItem("clubDetailsForClubId")
).postalCode;
await fetch(
"https://api.bjs.com/digital/live/api/v1.0/member/available/offers",
{
method: "post",
credentials: "include",
body: JSON.stringify({
membershipNumber,
zipcode,
category: "",
isPrev: false,
isNext: true,
pagesize: 500,
searchString: "",
indexForPagination: 0,
brand: ""
})
}
)
.then((r) => r.json())
.then(([{ availableOffers }]) => {
// Intentionally doing sequential requests to avoid hammering the backend
availableOffers.forEach(async ({ offerId, storeId }) => {
await fetch(
`https://api.bjs.com/digital/live/api/v1.0/store/${storeId}/coupons/activate?zip=07302&offerId=${offerId}`,
{
credentials: "include"
}
);
});
});
})().then();
@TheMarf
Copy link

TheMarf commented Mar 27, 2024

@raxityo Great idea. Thanks for the tip and the code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment