I won't post the full code, because all the features I incorporated make it quite long. But I can post some tips.
You have to use the Site Admin API. This can be registered, like the ALM Client. Go to the same page where you the HP ALM Client Registration process and you'll find a link for the Site Admin Client. It is a COM-based API like the OTA API. The product includes documentation for it.
The Site Admin API has a Login method. You have to provide valid Site Admin credentials to get connected.
The API provides has a few different CreateUser methods. You have to use the one that fits your needs.
The Create method doesn't update an existing record, so you should check if the user already exists. For that I use the GetAllUsers method and then search the output. The GetUser method to look for an individual user is case sensitive and requires that you have an exact match on the user name. In my environment, I can't ensure that I'm starting with a user name that will have the same case as the user account if it already exists in ALM.
You also, of course, need to build in error handling in case any of this fails.
I wrote code to generate a text based log file of the activities.
My program only creates the Site user account. I don't add the user to any projects or manage project specific permissions.
I created my program as a ASP.NET web page, and I host it on the ALM server. Everything in it runs server-side, so I only have to register the Site Admin API on the ALM server. I do have to remember to re-run that registration whenever I install an ALM patch.
I've written similar custom web apps for deleting user accounts, for display the connections (like you see in the Site Admin Connections tab) and for creating and copying Projects. I did this all to provide some self-service tools to my vast user community, so they don't have to wait on service from an actual Site Admin. All my programs use privatized Site Admin credentials behind the scenes to accomplish these tasks, while my log files make note of the actual user running the web app.