Tuesday, November 19, 2019

Using Global Entry API to Get Better Appointment

Overview

I bit the bullet and decided to apply for TSA PreCheck for my traveling. Since it was only $15 US more for Global Entry (GE), I actually went that route. It gives me everything PreCheck does along with quicker customs processing when I return to the States. Since it has more intrusive background checks, you have to do an interview for final approval. With all the political drama going on right now, staffing these locations has been a challenge for US Customs and Border Protection. If I knew then what I know now, I would have just gotten TSA PreCheck.

I applied around February 2019 and after about a month was moved to the 'Conditionally Approved' phase so I was able to set an appointment for the interview. My brother applied a week after me and just now was made 'Conditionally Approved' this week. In my case, I set an appointment at Denver (DIA) and the soonest was May 2019. Two days before my appointment it was canceled on me and the soonest they had was July so I signed for that. That was canceled on me and Jan 2021 was the next avail. That put me at nearly a year from application. Ugh. 


Solution

As both my brother and I are in IT we started talking about getting an earlier appointment. People have to cancel their appointments for example so what happens to them? Did some research and found that the Global Entry website has an API available to talk to its database.

Sure enough, we found a blog post about it by Jeremy Stretch. ‘stretch' covers a GitHub repository he found that looks for appointments via the GE API. As the GE site changed, he had to start over and documented what he did but never finished it out as he got an appointment via the website. So my brother and I decided we could get something going based on what stretch started. My brother volunteered to write it in Python and I offered to run it on my main Ubuntu server.

As stretch documented, you can go into your browser's developer mode while looking at appointments on the website to pull out the site code.
  • Denver          6940
  • Miami           5181
  • Fort Lauderdale 5443
We looked up a few others for testing and apparently, Guam has free slots almost daily. I should go there! After identifying the office codes, we went to work within our requirements:
       Since there were no rules of engagement around the API we decided to run it every 5 minutes via cron.
       It will email us when it finds an opening. Nothing special, it just uses the MTA on the system such as PostFix.
       It will also stop once it finds one, and we have to reset it, also done around the API concerns. This drops /tmp/checkGE.disable and the script will exit out if that dropper is found.
       It should also track its history when it finds openings, and this is kept in /tmp/checkGE.history.
       Support multiple locations.
After writing it and doing some initial bug hunting it was returning results – too many, as it would show what was freshly available six to nine months out. Since I had an appointment a few months out, I was only interested in an earlier appointment so it supports regex to parse specific ranges. Initially, it was the remainder of 2019, but we then wanted the first couple months of 2020.

if re.match('^(2019-(10|11|12)|2020-(01|02))-',result):

This was done for readability more than optimized performance. Additionally, it follows ISO 8601, which is in the format of YYYY-MM-DDThh:mm:ss. In the above example, it is looking for the following months:

       October 2019
       November 2019
       December 2019
       January 2020
       February 2020

So this could have its regex streamlined as the following, but it would be much harder to read and modify if we had to go further into 2020 versus above.

if re.match(^20(19-1[0-2]|20-(0[12]))-',result):

Once it was set up, we just had to be near a PC when the email showed up to go to the website to snag the earlier appointment when we were notified one was available. I cannot prove it, but I believe the website polls the database on an interval as well. We had a few matches but they were not on the website. Initially, I thought I was too late, but a couple of appointments showed up on the website a few minutes after I got the email notification.

I really lucked out as it found an appointment two days out for me, which I snagged. I am all set up with Global Entry now. Wahoo! I might have to dust this off in 5 years if I get elected to go through another interview during the renewal process.


Download


This script is provided as-is; no warranty is provided or implied. The author is NOT responsible for any damages or data loss that may occur through the use of this script.  Always test, test, test before rolling anything into a production environment.

Since it was not originally written to share, you will have to work on it a little. Using what stretch covered, get your locations to code on line 14. Adjust the regex on line 26. Enter your email address on line 11. You can find the script here.



No comments:

Post a Comment