Azure GraphServiceClient exception "Delta patch payload must contain @context : #$delta" when updating user
As per the title, I'm trying to update an Azure B2C user with my API using the Microsoft.Graph
NuGet package. I've recently deleted and recreated my app registration on Azure and in my infinite wisdom didn't write down which scopes it had been permitted.
Users access my API with an access token issued by B2C from a separate web client, so I'm presuming the scopes my API needs would come under application permissions (no signed in user) rather than delegated permissions (with a signed in user), and I think the User.ReadWrite.All
permission should cover it?
I'm questioning this because the requests have stopped working yet there have been no changes to the code. The code is below:
IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(configuration[$"{Constants.AzureAdB2C}:ClientId"])
.WithTenantId(configuration[$"{Constants.AzureAdB2C}:Domain"])
.WithClientSecret(configuration[$"{Constants.AzureAdB2C}:ClientSecret"])
.Build();
IAuthenticationProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
User azureUser = await graphClient.Users[azureId]
.Request()
.Select(e => new
{
e.OtherMails
})
.GetAsync();
azureUser.OtherMails = userEmails;
await graphClient.Users[azureId]
.Request()
.UpdateAsync(azureUser);
Retrieving the details is fine but on the last line to update the user I get the exception Delta patch payload must contain @context : #$delta
. I can't find any reference to this anywhere and can't find or remember where I got the original code above from. Can anybody advise where I'm going wrong?