Recently I had the task to automate a few things regarding AppleIDs. One of things was to create, change and verify AppleIDs. Having no tools (apart from Apples inofficial buggy AppleScript screen-click-automation scripts) I had a look at the HTTP communication between iTunes/the web client and the iTunes Store and AppleID servers.

The login to AppleID is rather straightforward by posting username and password via a login form. However note, that input controls in form have often different names and ids. In addition the names in forms may differ depending on the web client you use to connect to the AppleID servers.

Login to AppleID

  1. You start off by GETting the login url which is something like
  2. There you get your first session specific cookie ‘mymgrap_mycpr’ and some locale specific stuff. The richer the browser the more cookies you get.
    The cookie looks like to concatenated GUIDs without any hyphens, eg bc214ee621c546d3a1869ced550480d66f91e475600c477f8c8c0012440f7f18
  3. Along with the cookie you get the login form that you should POST to the Uri denoted in the action attribute.
  4. Within the form you get another session specific variable ‘wosid’ that you have to send in your form and that you will find in all your subsequent requests to the AppleID servers. That variable is relatively short (eg R7ESZtr5DaEn3cI8rrIIXx).
  5. Another interesting point is that at this point you seem to be redirected to a specific AppleID server instance which is also encapsulated in action attribute of the form. It has the form of a number (2-3 digits, eg 283).
  6. In addition you are send to a page specific address that comes in a form of digit-dot-notation. you will find these declarations later on all over their web pages (eg for logging in).
  7. So a complete login UrL where you POST your data to could look like
  8. If everything works fine you are you are being forwarded to a url besides being awarded with a few cookies (actually the only cookie you really need is the ‘mymgrap_mypcr’ cookie that you already have).
    The location header looks something like this: /cgi-bin/WebObjects/MyAppleId.woa/283/wo/R7ESZtr5DaEn3cI8rrIIXx/2.0
  9. Now you are logged in and all future requests will be based at the above address.

Verify AppleID Email

  1. To verify the AppleID Email (the actual email address, not the recovery address) you have to look for a mail with the following subject: “Please verify the contact email address for your Apple ID.”
  2. Then extract the confirmation link with the following (.NET) regular expression: ‘\”(^\”]+)\”‘.

You could use the following code to get the latest confirmation email from an Office365 or Exchange mailbox:

#Connect to EWS first
Connect-OSCEXOWebService -Credential $cred
# Search for mail
$aMail = Search-OSCEXOEmailMessage -WellKnownFolderName Inbox -Subject "Please verify the contact email address for your Apple ID.";
$Mail = $aMail[0];
$Message = [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($exService, $Mail.UniqueId)
# Get mail and extract VerificationUrl
$fReturn = $Message.Body.Text -match '\"([^\"]+)\"';
$VerificationUrl = $Matches[1];

Change Email Address

Changing an email address is easy too, but looks a little bit noisy and redundant:

POST <a href=""></a> HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: ISTLocale=ZW5fVVM=; mymgrap_mycpr=bc214ee621c546d3a1869ced550480d66f91e475600c477f8c8c0012440f7f18
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 963

Maybe this information comes in helpful when you need it. At least for me it helped me to create a 850 AppleID accounts, assigned software and changed email addresses – certainly all done with PowerShell … And in case you are interested I used a mixture of Invoke-WebRequest, [System.Net.WebClient] and [System.Net.WebRequest] to make the calls. And without the help of Fiddler I could not have done this either.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.