How can I add O365 contacts using batch API? (Java)

Yoppi 0 Reputation points
2023-08-25T11:30:54.9733333+00:00
Hello.
In the Microsoft Graph SDK for Java,
I'm trying to write an application that uses the batch API to add contacts.

I referred to the URL below, but I don't know how to implement it when replacing it with the contact API.

Is there a java source code sample for adding contacts using batch api?

https://learn.microsoft.com/en-us/graph/sdks/batch-requests?tabs=java

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,446 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. TH-4749-MSFT 3,295 Reputation points
    2023-09-01T20:15:12.07+00:00

    Hello Yoppi,

    Thanks for reaching out. You can find an example of creating a contact using Graph Java SDK below.

    https://learn.microsoft.com/en-us/graph/api/user-post-contacts?view=graph-rest-1.0&tabs=java

    For queries related to Graph SDK please refer to the respective Graph SDK Github 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.


  2. Yoppi 0 Reputation points
    2023-09-04T08:24:09.3633333+00:00

    With reference to batch sample code

    I wrote a batch code that registers the name in the contact form.

    The status after execution is 200, but it is not added to correspondence.

    Please let me know if anyone knows what is wrong.
    Thank you.

    GraphServiceClient oGraphClient = oClientCredPrv.getGraphClient();
    BatchRequestContent oBatchRequestContent = new BatchRequestContent();
    List<QueryOption> oContactList = Arrays.asList(new QueryOption("givenName", "John "),
    new QueryOption("surname", "Smith"));
    IHttpRequest oHttpRequest = oGraphClient.users(p_Upn).contacts().buildRequest(oContactList);
    String oRequestStepId = oBatchRequestContent.addBatchRequestStep(oHttpRequest);
    BatchResponseContent batchResponseContent = Objects
    .requireNonNull(oGraphClient.batch().buildRequest().post(oBatchRequestContent));
    BatchResponseStep<JsonElement> oContactsResponse = Objects
    .requireNonNull(batchResponseContent.getResponseById(oRequestStepId));
    System.out.println("result:" + oContactsResponse.status);
    
    0 comments No comments