How to get Automated Alerts on Instacart Delivery availability using Postman & Python bot


For impatient folks here is a link to GitHub source to this project Notify Me Give a try and let me know how it goes.

Need for Weekend Project

Instacart is a unique platform where one can order their grocery needs from multiple local stores at once. Instacart shoppers then visit these shops in person to do all shopping as mentioned in the order and deliver to your home within an hour or so! For end-users, this is a really helpful service in the current situation (thank you COVID-19) where we all are restricted to stay home! Due to this, the site is currently experiencing tremendous demand and it’s almost getting difficult to place orders as Instacart Shoppers keep working on their backlog.

Since we are on Corona vacation aka House arrest, we’ve been trying to use online services as much as we can to get our essential needs addressed. Many local stores still don’t provide online shopping which makes using Instacart a necessity. But every time I’ve tried to place an order through their website to get items from stores such as Costco, Safeway or CVS, I’ve been presented with the message below. I was really annoyed and wanted to find out if there is anything I can do so that I will able to know right once delivery times are available on Instacart so that I can submit my order!

Sorry no times are available
Sorry, Try again later!

So I jotted down what I need to do that I can allow me to slack and jump to screen only when I have to place an order as per alert from my bot. Since then I’ve successfully created a small script that alerts me (via email or text) whenever Instacart has specific time windows available to submit order. And yes finally, I’ve been successful in placing an order on Instacart to get groceries from Costco and Foodmaxx. Below you will find how I came up with a solution and how you can use it for your own needs.

Instacart, Firefox and Postman

First I decided to find out which Instacart APIs being used to inform the user that delivery times are available or not. Earlier my friend from Nashville had mentioned to me that they were able to place orders from this website right away. So I set my delivery address to zip code 37067 (Franklin, Nashville, TN) to start with. It allowed me to see available times for Costco.

Costco Availability on Instacart

Firefox Developer Tools helped me to narrow down on two API calls which seem to be useful for my needs.

Then I switched to Postman to understand what are different inputs / outputs information provided by these APIs.

Instacart Retailer Delivery Info API on Postman
Instacart Quick Availability API on Postman

Out of this, I decided to use Instacart Retailer Delivery Information API for my cause as it not only indicates if delivery times are available for a given store or not, but it also provides exact day time details for each window (if available) which I may like to use in a future version of this bot!

Postman – My Delivery Guide

Before we dive further, one question that should come to mind is, how the heck I’m able to successfully run this API in Postman app though. Right? BTW if you don’t know Postman, it’s a Swiss army knife that every developer should have. It helps in understanding APIs real up close when you don’t have related documentation available!

Initially, I tried to use my Instacart credentials with BASIC AUTH in Postman but ran into a 401 (Unauthorized Access Error) message. I could able to locate session-id info in Firefox but setting up that info into Request Header didn’t help either. And that’s when I saw Cookies link in Postman as you can see in Retailer Info API Image. Manage Cookies section in Postman allows one to capture cookies from your Browser with help from Postman Chrome Inspector extension (available only on Chrome). With that, I’m able to access the above APIs through Postman, viola! We are ON to something great 🙂

Upon closer look at JSON output by Retailer Info API, I could see delivery related useful information in the modules section of this output. 1st dictionary from this section tells the browser if delivery times are available or not. If the types set as “icon_info”, then yes delivery windows are available for end-user to submit the order for that store. And if it has “error” as the value then it means Instacart Shoppers are super busy right now and we should try again later. Also when types set as “icon_info”, 2nd dictionary in this section provides all information on different time slot availability.

Core Information to implement our Bot

Postman – Delivery guy comes to rescue again

And with all this information I was confident that I can start writing Python script with Requests module to retrieve relevant details and display/email/text me as necessary. But later on, I couldn’t able to figure out how to use these cookies with my beloved Requests module. Stuck again, but not for a long time though!

Another look at Postman revealed me Code link which was right there staring at me all this time. Eureka! Postman already generated the necessary code for me. Very next moment, I ran code snippet from Python – Requests section within my Jupyter Notebook. But to my despair that didn’t work either 🙁

I decided to give a try with the cURL code snippet from the command line and it did work as expected. It was a good sign and I could see light at the end of the tunnel! I was able to spot another python code snippet using http.client module. And this code did live up to my expectations and for the very first time, I was able to see API in real action based on given commands!

Perfect Setup using Mailgun, Twilio & Cronjob

Now that I’d basic working code at my disposal, I wanted to add all the bells and whistles that can really help me to get notifications without gluing me to computer all the time.

First thing I did was to register myself with Mailgun and Twilio to allow me to send emails / texts through my program. As I’ve never used both these services before I was bit skeptical for quick turnaround. Mailgun setup was super easy and straight forward. Within few minutes I was able to send emails through program. (Free version allows upto 5000 emails per month I guess, which is more than sufficient for my needs). In case of Twilio, I’d to bit play around to figure out how to make it work. Couple of Issues that I need to find a fix are:

  • Error – The phone number you are using to send a message is not activated I need to use the phone number provided by Twilio instead of my own!
  • Adding a new line character to message content
  • Getting around with the pre-appended message “Sent from your Twilio trial account -“

And with that I started spamming myself with all text messages that no one sent me before! Next I integrated both these services into my main program. Also I enhanced script further to handle errors, read different credentials via dot-files and also made sure that one can use this script with different stores available in Instacart and user can change store list through configuration.

With all this working together, I setup cron job and went to sleep. At 2 am, I got a text and email mentioning Costco and Total Wine and More have delivery windows available to submit my orders. Since I’d already put everything in my cart, I was able to submit my order right away! Yay!!! Now I can continue to stay home and wait for Instacart Shopper (thank you buddy!) to deliver food/groceries right at our door step.

Notify-Me Bot text notification on my phone

Since then I’ve made more changes so that script is more generic and available for anyone to use with minimal setup efforts. Here is the link to the Notify Me project on Github. Give a try and let me know if it’s being useful to you. Thank you for staying with me so far.

References

16 Replies to “How to get Automated Alerts on Instacart Delivery availability using Postman & Python bot”

  1. Hey man, awesome post. I am very new to this API stuff but what do you put in the INSTACART_COOKIE_CONTENT parameter? I was able to get postman to work and intercept but I don’t know what to look for or put

    1. Guillerp, sorry your comment was in Spam folder. For INSTACART_COOKIE_CONTENT, we get it from your Instacart Browser session. I’ve explained in blog above. Let me know if you need help in capturing this cookie.

  2. Hey there-

    I was about to start building my own version of this. Good thing I googled as you’ve done most of the hard work already. Thank you for putting this together. I’m going to modify a bit with the ‘pickup’ option of the instacart API as I dont have delivery in my area.

    1. Sounds good Marty! I’m following strict orders and haven’t stepped out of house for more than month now, so for me Delivery was only way to get things home 🙂

      With that being said, will be more than happy to see extension for pick up too.

  3. How am I supposed to get the header for the instacart cookie content

    1. Rohan, you will need to use Postman REST API client (postman.com). It’s a bit tedious process but you will get there.

  4. Im also not able to get the environment set up

    1. If you give me more details may be I can help you out. Also will be great if you open a ticket on github to keep track of this issue to help others too.

  5. Hey, do you think a script can be made for instacart shoppers that need to auto accept orders.

    1. Santiago — that’s ultimate goal I’ve!. Got couple of ideas to get there, let’s see. Without any documentation things are very slow (and more interesting and fun too).

      Will update code as I’ve something more tangible to share with everyone.

  6. Hi
    To piggyback from Santiago… I am an Instacart shopper and people using bots are killing me. I don’t see any batches anymore.
    I know NOTHING about what you discussed in this post (literally nothing – I don’t code) but would love to see if you could assist me.
    Thx

    1. Karen — This program is written mainly from user prespective to help them find delivery window so that they can submit orders. I’m not very sure what are Instacart Shoppers needs are. Let me know what you need help and see if there is anything we can do here.

  7. Do you guys happen to know the Bots for the Shopper app for instacart Shoppers or can you develop one for me let me know please $$$$

  8. I’m in that Shopper situation as well. Up until 2 weeks ago I had no issues getting batches to shop and deliver. Been doing it part time for 2 years. Now there are bots that are grabbing the batches before you can see them and selling them to other shoppers thru an app of some sort. Haven’t found out the name of the app/bot but would love a way to combat this. Let me know what info you might need to explore. Thanks

    1. Daryl — Thanks for your comment. I’d never thought this can be issue. Since I’m not a Instacart Shopper, I really don’t have any way to look into this. Does Instacart knows about this problem. You should bring this to their attention. Also you should ask in your Shopper community like this https://www.reddit.com/r/InstacartShoppers/ I will try to see if I get any more details on this bot. But I’m afraid, I may not able to do much here.

      If possible please do share your findings with us. Good luck!

  9. I’m in that Shopper situation as well. Up until 2 weeks ago I had no issues getting batches to shop and deliver. Been doing it part time for 2 years. Now there are bots that are grabbing the batches before you can see them and selling them to other shoppers thru an app of some sort. Haven’t found out the name of the app/bot but would love a way to combat this. Let me know what info you might need to explore. Thanks

Comments are closed.