Miscrosoft Graph API 'UnableToDeserializePostBody' error after sending a post request to update a contact

Frédéric Van Overmeire 0 Reputation points
2023-08-09T10:07:22.2066667+00:00

I'm trying to update a new contact with a schema extension by calling the Microsoft Graph API using the MS Graph sdk in Java.

So far, every call for this specific action returns an UnableToDeserializePostBody error.

My code to check for a shema extension:

SchemaExtensionCollectionPage response = graphClient.schemaExtensions().buildRequest().get();
List<SchemaExtension> extensions = fetchAll(response);
contactExtension = extensions.stream()
    .filter(e-> (contactExtensionId).equals(e.id)) //contactExtensionId fetched from internal DB
    .findAny().orElse(null);
if(contactExtension == null)
{
	contactExtension = new SchemaExtension();
	contactExtension.id = contactExtensionId;
	contactExtension.description = "Contact extension";
	LinkedList<String> targetTypesList = new LinkedList<>();
	targetTypesList.add("contact");
	contactExtension.targetTypes = targetTypesList;
	
	LinkedList<ExtensionSchemaProperty> propertiesList = new LinkedList<>();
	ExtensionSchemaProperty tenantProperty = new ExtensionSchemaProperty();
	tenantProperty.name = EXTENSION_PROPERTY_TENANT;
	tenantProperty.type = "String";
	propertiesList.add(tenantProperty);
	ExtensionSchemaProperty idProperty = new ExtensionSchemaProperty();
	idProperty.name = EXTENSION_PROPERTY_ID;
	idProperty.type = "String";
	propertiesList.add(idProperty);
	contactExtension.properties = propertiesList;
	
	contactExtension = graphClient.schemaExtensions()
			.buildRequest()
			.post(contactExtension);
			
	logger.info("Contact Extension created : " + contactExtension.id);
}

Here's the extension for the contact:

public static class ContactExtension extends Extension
{
	@SerializedName(value = "tenant", alternate = {"Tenant"})
	@Expose
	@Nullable
	public String tenant;
	
	@SerializedName(value = "entityId", alternate = {"EntityId"})
	@Expose
	@Nullable
	public String entityId;
}

And here is how I try to update the contact following the official documentation as much as I can :

Extension ext = graphClient.users(targetUser.id)
	.contacts(contact.id)
	.extensions(this.contactExtension.id)
	.buildRequest()
	.post(contactExt);

The stack trace i get:

Jul 12, 2023 1:53:03 PM com.microsoft.graph.logger.DefaultLogger logError
	SEVERE: CoreHttpProvider[sendRequestInternal] - 408Graph service exception
	Jul 12, 2023 1:53:03 PM com.microsoft.graph.logger.DefaultLogger logError
	SEVERE: Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: UnableToDeserializePostBody
	Error message: were unable to deserialize
	POST https://graph.microsoft.com/v1.0/users/{user}/contacts/{contacts}/extensions/extdtlnlmgg_contactMetaData
	SdkVersion : graph-java/v5.49.0
		[...]
		400 : Bad Request
[...]
		[Some information was truncated for brevity, enable debug logging for more details]
	Jul 12, 2023 1:53:03 PM com.microsoft.graph.logger.DefaultLogger logError
	SEVERE: CoreHttpProvider[sendRequestInternal] - 408Graph service exception
	Jul 12, 2023 1:53:03 PM com.microsoft.graph.logger.DefaultLogger logError
	SEVERE: Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: UnableToDeserializePostBody
	Error message: were unable to deserialize
	POST https://graph.microsoft.com/v1.0/users/{user}/contacts/{contacts}/extensions/extdtlnlmgg_contactMetaData
	SdkVersion : graph-java/v5.49.0
		[...]
		400 : Bad Request
[...]
		[Some information was truncated for brevity, enable debug logging for more details]
		13:53:03,442  ERROR [cerebro.manager.MsGraphHelper] Mails TES error
	com.microsoft.graph.http.GraphServiceException: Error code: UnableToDeserializePostBody
	Error message: were unable to deserialize
	POST https://graph.microsoft.com/v1.0/users/{user}/contacts/{contacts}/extensions/extdtlnlmgg_contactMetaData
	SdkVersion : graph-java/v5.49.0
		[...]
		400 : Bad Request
[...]
		[Some information was truncated for brevity, enable debug logging for more details]
	at com.microsoft.graph.http.GraphServiceException.createFromResponse(GraphServiceException.java:419)
	at com.microsoft.graph.http.GraphServiceException.createFromResponse(GraphServiceException.java:378)
	at com.microsoft.graph.http.CoreHttpProvider.handleErrorResponse(CoreHttpProvider.java:512)
	at com.microsoft.graph.http.CoreHttpProvider.processResponse(CoreHttpProvider.java:442)
	at com.microsoft.graph.http.CoreHttpProvider.sendRequestInternal(CoreHttpProvider.java:408)
	at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:225)
	at com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:202)
	at com.microsoft.graph.http.BaseRequest.send(BaseRequest.java:335)

Is there anyone who might have a clue about what steps I should take or the source of the issue?

The official documentation regarding Java in this matter is quite limited.

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. TH-4749-MSFT 3,315 Reputation points
    2023-08-14T20:33:00.4433333+00:00

    Hello Frédéric Van Overmeire,

    Thanks for reaching out. For Graph SDK related questions please post your questions and issues on Graph SDK Github in the respective SDK forum.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    Thanks.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.