msgraph-sdk-java icon indicating copy to clipboard operation
msgraph-sdk-java copied to clipboard

InvalidRequest: Missing header Client-Request-Id. Header Client-Request-Id is not a guid

Open praducg opened this issue 1 year ago • 2 comments

Graph API End point: POST https://graph.microsoft.com/v1.0/drive/items/{item-id}/workbook/comments

Request Body:

{
  "content": "This is a sample text"
}

I am passing GUID in the Client-Request-Id but still the issue remains same.

When posting comments to a word document using graph Client getting Error message: {"code":"InvalidRequest","message":"Missing header Client-Request-Id. Header Client-Request-Id is not a guid.","innerError":{"request-id":"00000000-0000-0000-0000-000000000000","date":"2024-09-20T17:03:58.6112675-07:00"}}

I tried using GraphExplorer,JavaCode(Refer Below),JavaScriptClient and everywhere the issue remains same.


import java.util.UUID;

import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;

public class AddComment {
    public static void main(String[] args) {
        try {
            String url = "https://graph.microsoft.com/v1.0/sites/" + "my-site-id" + "/drives/" + "my-drive-id" + "/items/" + "item-id" + "/workbook/comments";

            String clientRequestId = UUID.randomUUID().toString(); // Generate a new GUID
 
            CloseableHttpClient client = HttpClients.createDefault();
            HttpPost post = new HttpPost(url);

            post.setHeader("Authorization", "Bearer access-token");
            post.setHeader("client-Request-Id", clientRequestId);
            post.setHeader("Content-Type", "application/json");
            String json = "{\"content\": \"MS Document Comment\"}";
            StringEntity entity = new StringEntity(json);
            post.setEntity(entity);

            CloseableHttpResponse response = client.execute(post);
            String responseBody = EntityUtils.toString(response.getEntity());
            System.out.println(response.getCode());
            System.out.println(responseBody);

            client.close();
            // Handle the response...

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

praducg avatar Sep 21 '24 00:09 praducg

Hi @praducg, this seems to be a casing issue being validated by the API, client-request-id works on Graph Explorer. It should also work with this SDK. Please let me know if this is not the case. You could also consider upgrading to the latest version of this SDK which provides HTTP/2 support ~ lowercases all headers + a bunch of other performance enhancements.

Ndiritu avatar Oct 07 '24 23:10 Ndiritu

hi @Ndiritu I tried with lower case as well same result . Do you have a sample client code which I give a tried ? I tried with latest library also but no luck?

Basically I wanted to add inline comments to a word document stored in sharepoint using graph api(Tried sharepoint API too but didn't work) .I tried file comments on list items ,that works but not the inline comments. I tried with javascript also but same response posted the same in feedback forum also Ref :https://learn.microsoft.com/en-us/answers/questions/2075053/microsoft-graph-api-while-posting-comments-gives-m?page=1&orderby=helpful&comment=answer-1835370

praducg avatar Oct 08 '24 03:10 praducg