Do either of these exist:
- API to get the Managed Packages of the user?
- API to set the Managed Packages of the user?
You can use the UserPackageLicense like a normal object. You can query the object to determine if a user has a given package assigned to them, insert new records to assign a package, and delete them to remove a package. This works both in Apex Code and the various API's (SOAP, REST, etc).
UserPackageLicense[] licenses = [SELECT PackageLicense.NamespacePrefix
FROM UserPackageLicense
WHERE UserId = :UserInfo.getUserId()];
PackageLicense license = [SELECT Id FROM PackageLicense WHERE NamespacePrefix = :aPrefix];
UserPackageLicense userLicense = new UserPackageLicense(UserId=UserInfo.getUserId(),
PackageLicenseId=license.Id);
insert userLicense;
delete [SELECT Id FROM UserPackageLicense
WHERE PackageLicense.NamespacePrefix = :aPrefix AND UserId = :UserInfo.getUserId()];