“Batch request to Microsoft Graph returns ‘message’: ‘Url specified is invalid.'”

huangapple go评论96阅读模式
英文:

Batch request to Microsoft Graph returns "message": "Url specified is invalid."

问题

以下是您提供的代码部分的翻译:

  1. {
  2. "requests": [
  3. {
  4. "id": "01GNYB5KKIKZVLU4SXJZAI6PD76QD3PUVQ",
  5. "method": "GET",
  6. "url": "https://graph.microsoft.com/v1.0/sites/bpmgroup.sharepoint.com,23e7ef7a-a529-4dde-81ba-67afb4f44401,0fa8e0f7-1c76-4ad0-9b6e-a485f9bfd63c/drive/items/01GNYB5KKIKZVLU4SXJZAI6PD76QD3PUVQ/thumbnails?select=large"
  7. },
  8. {
  9. "id": "01GNYB5KNZCQTFLFPNQNCJZXQVQWIBQWLG",
  10. "method": "GET",
  11. "url": "https://graph.microsoft.com/v1.0/sites/bpmgroup.sharepoint.com,23e7ef7a-a529-4dde-81ba-67afb4f44401,0fa8e0f7-1c76-4ad0-9b6e-a485f9bfd63c/drive/items/01GNYB5KNZCQTFLFPNQNCJZXQVQWIBQWLG/thumbnails?select=large"
  12. }
  13. ]
  14. }

以下是您提供的响应部分的翻译:

  1. {
  2. "responses": [
  3. {
  4. "id": "01GNYB5KNZCQTFLFPNQNCJZXQVQWIBQWLG",
  5. "status": 400,
  6. "headers": {
  7. "Content-Type": "application/json"
  8. },
  9. "body": {
  10. "error": {
  11. "code": "BadRequest",
  12. "message": "Url specified is invalid.",
  13. "innerError": {
  14. "date": "2023-05-17T18:17:39",
  15. "request-id": "7bb48670-f436-4c16-8137-9d70abe92dab",
  16. "client-request-id": "7bb48670-f436-4c16-8137-9d70abe92dab"
  17. }
  18. }
  19. }
  20. },
  21. {
  22. "id": "01GNYB5KKIKZVLU4SXJZAI6PD76QD3PUVQ",
  23. "status": 400,
  24. "headers": {
  25. "Content-Type": "application/json"
  26. },
  27. "body": {
  28. "error": {
  29. "code": "BadRequest",
  30. "message": "Url specified is invalid.",
  31. "innerError": {
  32. "date": "2023-05-17T18:17:39",
  33. "request-id": "7bb48670-f436-4c16-8137-9d70abe92dab",
  34. "client-request-id": "7bb48670-f436-4c16-8137-9d70abe92dab"
  35. }
  36. }
  37. }
  38. }
  39. ]
  40. }

请注意,这些翻译是您提供的代码和响应的直译翻译,不包含其他信息。如果您需要进一步的帮助或解释,请随时提问。

英文:
  1. {
  2. requests: [
  3. {
  4. id: '01GNYB5KKIKZVLU4SXJZAI6PD76QD3PUVQ',
  5. method: 'GET',
  6. url: 'https://graph.microsoft.com/v1.0/sites/bpmgroup.sharepoint.com,23e7ef7a-a529-4dde-81ba-67afb4f44401,0fa8e0f7-1c76-4ad0-9b6e-a485f9bfd63c/drive/items/01GNYB5KKIKZVLU4SXJZAI6PD76QD3PUVQ/thumbnails?select=large'
  7. },
  8. {
  9. id: '01GNYB5KNZCQTFLFPNQNCJZXQVQWIBQWLG',
  10. method: 'GET',
  11. url: 'https://graph.microsoft.com/v1.0/sites/bpmgroup.sharepoint.com,23e7ef7a-a529-4dde-81ba-67afb4f44401,0fa8e0f7-1c76-4ad0-9b6e-a485f9bfd63c/drive/items/01GNYB5KNZCQTFLFPNQNCJZXQVQWIBQWLG/thumbnails?select=large'
  12. }
  13. ]
  14. }

Above is the batchPayload (testing with only 2 items) passed to my callMsGraph(token, batchUrl, batchPayload) function. And below is the received batchResponse:

  1. {
  2. "responses": [
  3. {
  4. "id": "01GNYB5KNZCQTFLFPNQNCJZXQVQWIBQWLG",
  5. "status": 400,
  6. "headers": {
  7. "Content-Type": "application/json"
  8. },
  9. "body": {
  10. "error": {
  11. "code": "BadRequest",
  12. "message": "Url specified is invalid.",
  13. "innerError": {
  14. "date": "2023-05-17T18:17:39",
  15. "request-id": "7bb48670-f436-4c16-8137-9d70abe92dab",
  16. "client-request-id": "7bb48670-f436-4c16-8137-9d70abe92dab"
  17. }
  18. }
  19. }
  20. },
  21. {
  22. "id": "01GNYB5KKIKZVLU4SXJZAI6PD76QD3PUVQ",
  23. "status": 400,
  24. "headers": {
  25. "Content-Type": "application/json"
  26. },
  27. "body": {
  28. "error": {
  29. "code": "BadRequest",
  30. "message": "Url specified is invalid.",
  31. "innerError": {
  32. "date": "2023-05-17T18:17:39",
  33. "request-id": "7bb48670-f436-4c16-8137-9d70abe92dab",
  34. "client-request-id": "7bb48670-f436-4c16-8137-9d70abe92dab"
  35. }
  36. }
  37. }
  38. }
  39. ]
  40. }

I have tested the urls as individual GET requests in postman, and they are indeed valid. But the POST response to batchUrl https://graph.microsoft.com/v1.0/$batch is returning that they are invalid?

I don't see how the URL could be malformed in anyway. I initially called each URL separately (without batching) with callMsGraph(accessToken, graphEndpoint) and the responses were fine -- the URLs are unchanged. I ofcourse want to utilize batching to reduce individual network requests.

My callMsGraph:

  1. function callMsGraph(accessToken, graphEndpoint, payload) {
  2. const headers = new Headers();
  3. const bearer = `Bearer ${accessToken}`;
  4. headers.append("Authorization", bearer);
  5. headers.append("Content-Type", "application/json");
  6. const options = {
  7. method: "POST",
  8. headers: headers,
  9. body: JSON.stringify(payload)
  10. };
  11. return fetch(graphEndpoint, options)
  12. .then(response => response.json())
  13. ....
  14. ...

答案1

得分: 1

在批量请求中,您的URL应该是相对的 https://learn.microsoft.com/en-us/graph/json-batching

> 必需的。这是个相对资源URL,通常用于发送单个请求。因此,虽然绝对URL是 https://graph.microsoft.com/v1.0/users,但这个URL是 /users。

所以类似于

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

{
requests: [
{
id: '01GNYB5KKIKZVLU4SXJZAI6PD76QD3PUVQ',
method: 'GET',
url: '/sites/bpmgroup.sharepoint.com,23e7ef7a-a529-4dde-81ba-67afb4f44401,0fa8e0f7-1c76-4ad0-9b6e-a485f9bfd63c/drive/items/01GNYB5KKIKZVLU4SXJZAI6PD76QD3PUVQ/thumbnails?select=large'
},
{
id: '01GNYB5KNZCQTFLFPNQNCJZXQVQWIBQWLG',
method: 'GET',
url: '/sites/bpmgroup.sharepoint.com,23e7ef7a-a529-4dde-81ba-67afb4f44401,0fa8e0f7-1c76-4ad0-9b6e-a485f9bfd63c/drive/items/01GNYB5KNZCQTFLFPNQNCJZXQVQWIBQWLG/thumbnails?select=large'
}
]
}

<!-- end snippet -->

英文:

In a batch request you URL's should be relative https://learn.microsoft.com/en-us/graph/json-batching

> Required. The relative resource URL the individual request would typically be sent to. Therefore, while the absolute URL is https://graph.microsoft.com/v1.0/users, this url is /users.

so something like

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

  1. {
  2. requests: [
  3. {
  4. id: &#39;01GNYB5KKIKZVLU4SXJZAI6PD76QD3PUVQ&#39;,
  5. method: &#39;GET&#39;,
  6. url: &#39;/sites/bpmgroup.sharepoint.com,23e7ef7a-a529-4dde-81ba-67afb4f44401,0fa8e0f7-1c76-4ad0-9b6e-a485f9bfd63c/drive/items/01GNYB5KKIKZVLU4SXJZAI6PD76QD3PUVQ/thumbnails?select=large&#39;
  7. },
  8. {
  9. id: &#39;01GNYB5KNZCQTFLFPNQNCJZXQVQWIBQWLG&#39;,
  10. method: &#39;GET&#39;,
  11. url: &#39;/sites/bpmgroup.sharepoint.com,23e7ef7a-a529-4dde-81ba-67afb4f44401,0fa8e0f7-1c76-4ad0-9b6e-a485f9bfd63c/drive/items/01GNYB5KNZCQTFLFPNQNCJZXQVQWIBQWLG/thumbnails?select=large&#39;
  12. }
  13. ]
  14. }

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月18日 03:05:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76275434.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定