blog

Using Gravwell Flows and the Best Buy API to help obtain a Sony Playstation 5

Apr 26, 2022 7:21:45 AM / By Fritz

Overview

I really want a Playstation 5. 

Unfortunately, scalpers have beaten us mere mortals to nearly every stock drop from every vendor, and the resale market for new Playstations has climbed to nearly a thousand dollars. It’s frustrating and it seems the only way to get one at retail price is to play the scalper’s game of automated stock checking (they probably automate the entire purchase process as well, but I’ll try to hold on to a little dignity in this post). 

If only I, a Gravwell Keyboard Biscuit Developer, had access to a tool that could periodically check on available stock…

Hey! Didn’t Gravwell just release some new version that has a flow-based automation framework in it? Maybe we can leverage that somehow! All we need to do is have Gravwell poll a website that sells the PS5, let’s use Best Buy as an example, and send me an email when it’s available. 

What’s even better is that Best Buy has an amazing developer API that’s free to use, simplifying the process even more. I can simply poll their REST API for the PS5, and I get a nice blob of JSON to key on. As an example:

curl "https://api.bestbuy.com/v1/products/6426149.json?show=onlineAvailability,inStorePickup,orderable&apiKey=<my api key>"

{"onlineAvailability":false,"inStorePickup":false,"orderable":"NotOrderable"}

With our API call in hand, let’s make a flow!

Screen Shot 2022-04-14 at 2.30.14 PMOur flow is really simple, let’s walk through it node by node:

HTTP

Our flow begins with an HTTP request to the Best Buy developer API shown above. It’s a simple GET. At the beginning of the flow it issues the request and sends the response down to the next node. 

Ingest

We ingest the response, which is a simple JSON blob, into the “bestbuy” tag, as shown below using Gravwell Data Explorer. Our flow is executed every 2 minutes, so we should see entries at the same interval.

Screen Shot 2022-04-14 at 2.31.33 PM

Run a Query / Get Table Results / Text Template

After ingesting the HTTP response, we immediately query the “bestbuy” tag, extracting the latest result, and just the “onlineAvailability” field:

tag=bestbuy limit 1 | json onlineAvailability | table onlineAvailability

The “Get Table Results” and “Text Template” nodes retrieve the results of the query and format the response into a simple “true/false” variable that we can use in the IF node.

IF

This is probably the simplest node available – if a condition is met, in this case if the extracted value from Step 3 is “true”, then continue executing. If not, just stop here until we run again.

Email

If we make it here, it’s because the IF node saw a true response on the extracted value from Step 3. That means the Playstation 5 is in stock! In this node I simply send an email to myself with a hardcoded URL to the Playstation on Best Buy’s website. 

Scheduling

The Best Buy API is rate limited, so we run this flow every 2 minutes. That should help my chances of getting a Playstation 5… stay tuned for part 2, where I play Elden Ring instead of working!

Screen Shot 2022-04-14 at 3.11.56 PMPictured: The backend team giving an update to the boss.

Conclusion

Gravwell Flows make it easy to automate your workflows, integrate remote APIs, and prepare alerts. 

With Gravwell Community Edition, you are able to unlock the power of Gravwell at your place of work or in your Homelab. A license is free and allows you to ingest up to 13.9 GB a day of ingestion. Request a license by clicking on the button below.

Request a CE License

 

 



 

 

Fritz
Written by Fritz
TOP