Need help with Memembership 2 API

I’m trying to import users as members from another system. The users are coming from an old website so all the data has been reformatted and imported using WP All Import. I’ve been processing their subscriptions during the import process using the M2P API. But after the migration some users are having issues with access and are getting protected content messages.

The code runs on the equivalent of a save_post hook that fires after a user has been imported by WP All Import. In some respects it looks like it works, because all the start and expire dates are correct when looking in Membership 2 Pro > All Members. And users have the correct memberships. But it’s only that they then don’t have access to pages that they should have on the front end.

I’m using the M2P API to handle the M2P part, WP All Import is just creating the WP Users. What am I doing wrong?