Hack 25 Create Several Birthday Reminders at Once


You probably have dozens of birthdays to track. You can speed up the process of adding Amazon event reminders with a script.

If you have an entire address book of people's birthdays that you'd like to receive reminders about, it could be a long process to enter them one by one into Amazon's event reminder form. Instead, you can speed up the process considerably with some scripting.

This ASP page accepts a text list of names and birth dates and enters them all as Amazon events. This script runs on Windows servers running IIS.

25.1 The Code

As with other services that require you to be logged in, the event reminder service requires an Amazon session ID that is tied to your account. This script first logs in as you via SSL and sets the session ID. Then it loops through the birthdays, calling the AddEvent subroutine, which sends a form post to Amazon with the event information.

' add_reminders.asp
' Turns a supplied list of names and birthdates into Amazon events
' Usage: An ASP page called from any web browser

Const YOUR_EMAIL = "insert email address"
Const AMZN_PASSWORD = "insert Amazon password"
Const WinHttpRequestOption_EnableRedirects = 6

Sub AddEvent(sid,name,e_month,e_day)
    strURL = "https://www.amazon.com/exec/obidos/reminder-edit-done/" 
    strURL = strURL & strSessionID
    strPostData = "reminder-id=" & _
                  "&reminder-frequency=on" & _
                  "&sort-by=reminder-date" & _
                  "&customer-email=" & YOUR_EMAIL & _
                  "&occasion-id=3" & _
                  "&smart-send-options-enabled=yes" & _
                  "&time-zone-name=US/Pacific" & _
                  "&7-days-before=no" & _
                  "&recipient-customer-id=" & _
                  "&recipient-name=" & name & _
                  "&recipient-lower-email=" & _
                  "&gift-recipient-customer-id=" & _
                  "&gift-recipient-age-range=00-00" & _
                  "&gift-recipient-gender=" & _
                  "&month=" & e_month & _
                  "&day-of-month=" & e_day & _
                  "&14-days-before=on" & _
                  "&0-days-before=no" & _
                  "&1-days-before=no" & _
                  "&interest1=" & _
                  "&30-days-before=no" & _
                  "&x=63" & _
    Set httppost = Server.CreateObject("Msxml2.SERVERXMLHTTP")
    httppost.Open "POST", strURL, false
    httppost.setRequestHeader "Content-Type",[RETURN]
    If Err.Number <> 0 Then
        'WScript.Echo httppost.Error
    End If    
    strText = httppost.ResponseText
    strHeaders = httppost.GetAllResponseHeaders
    strStatus = httppost.status
    Set httppost = Nothing
End Sub

If Request("txaBirthdays") <> "" Then
    'Start an Amazon Session
    strURL = "https://www.amazon.com/exec/obidos/flex-sign-in-done/"
    strPostData = "email=" & YOUR_EMAIL & _
                  "&password=" & AMZN_PASSWORD & _
                  "&method=get" & _
                  "&opt=an" & _
                  "&cont-page=cm/reminders-signed-in-continue" & _
                  "&cont-type=add-reminder" & _
                  "&response=reminder-add" & _
                  "&response=" & _
                  "stores/gifts/gifts-sign-in-secure.html" & _
                  "&action=sign-in" & _
                  "&next-page=" & _
    Set httppost = Server.CreateObject("WinHttp.WinHttpRequest.5")
    httppost.Open "POST", strURL, false
    'Turn off redirects
    httppost.Option(WinHttpRequestOption_EnableRedirects) = False
    httppost.setRequestHeader "Content-Type", [RETURN]
    httppost.setRequestHeader "User-Agent", [RETURN]
"(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)"
    httppost.setRequestHeader "Accept", [RETURN]
"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"
    httppost.Send strPostData
    If Err.Number <> 0 Then
        response.write httppost.Error
    End If    
    strHeaders = httppost.GetAllResponseHeaders
    strStatus = httppost.status
    'response.write "<xmp>" & strStatus & Chr(13) & strHeaders & "</xmp>"
    Set objRegExpr = New regexp
    objRegExpr.Pattern = "session-id=(.*?);"
    objRegExpr.Global = True
    objRegExpr.IgnoreCase = True
    Set objMatches = objRegExpr.Execute(strHeaders)
    If objMatches.Count = 0 Then
        response.write "Amazon session couldn't be started."
        For Each objMatch In objMatches
            strSessionID = objMatch.SubMatches(0)
    End If
    Set objMatches = Nothing
    Set objRegExpr = Nothing
    Set httppost = Nothing
    'Loop through the Birthdays
    cntEvent = 0
    arBDays = Split(Request("txaBirthdays"),Chr(13))
    For x = 0 To UBound(arBDays)
        arNameDate = Split(arBDays(x),",")
        strName = arNameDate(0)
        strDate = arNameDate(1)
        arMonthDay = Split(strDate,"/")
        strMonth = arMonthDay(0)
        strDay = arMonthDay(1)
        AddEvent strSessionID, strName, strMonth, strDay
        cntEvent = cntEvent + 1
    response.write cntEvent & [RETURN]
" events added! Check your email for confirmation."
    <title>Add Event Reminders</title>

Add a list of birthdays below, one on each line:<br>
Format: [Name], [Birthday mm/dd]
<form action="add_reminders.asp" method="post">
    <textarea cols="35" rows="6" name="txaBirthdays"></textarea>
<br><input type="submit" value="Add Items">
<% End If %>

25.2 Running the Hack

Add the code to an ASP file, add_reminders.asp. Upload the file to your server and point your browser at it:


Because your Amazon password is stored in the file, make sure that you're the only one with access to the source code.

You'll see the simple HTML form waiting for birthdays. Add a list of names and dates separated by carriage returns. If you happen to store your birthdays in a spreadsheet or other electronic format, it should be fairly easy to export them in this format. Click "Add Items," and the script should let you know how many events were added at Amazon. Log in and check your events list [Hack #24] to verify that the script worked.

25.3 Hacking the Hack

To understand the form variables that are sent in the AddEvent subroutine, view the source HTML of Amazon's event reminder [Hack #24] form and take a look at the form fields and their values. By playing with values set in strPostData, you could easily turn this script into an anniversary reminder, or change the notification time of the reminders from the default 14 days to any other available value.