Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
praducg opened this issue Sep 21, 2024 · 2 comments
Labels
Needs: Attention 👋 type:legacy-version Old version of the SDK type:question An issue that's a question

Comments

@praducg
Copy link

praducg commented Sep 21, 2024

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 praducg added the status:waiting-for-triage An issue that is yet to be reviewed or assigned label Sep 21, 2024
@Ndiritu
Copy link
Contributor

Ndiritu commented Oct 7, 2024

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 Ndiritu added type:question An issue that's a question type:legacy-version Old version of the SDK status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Oct 7, 2024
@praducg
Copy link
Author

praducg commented Oct 8, 2024

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

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Attention 👋 type:legacy-version Old version of the SDK type:question An issue that's a question
Projects
None yet
Development

No branches or pull requests

2 participants