microsoftgraph / msgraph-sdk-javascript

Microsoft Graph client library for JavaScript
https://graph.microsoft.com
MIT License
730 stars 220 forks source link

Plan Details update missing header If-Match #1647

Closed Eleirbag89 closed 3 months ago

Eleirbag89 commented 3 months ago

Bug Report

Prerequisites

For more information, see the CONTRIBUTING guide.

Description

Update Plan Details call fails

Console Errors:

GraphError: The If-Match header must be specified for this kind of request.
    at new GraphError (C:\Users\GabrieleGrillo\git\trello-migration-tool\node_modules\@microsoft\microsoft-graph-client\lib\src\GraphError.js:34:28)
    at GraphErrorHandler.constructErrorFromResponse (C:\Users\GabrieleGrillo\git\trello-migration-tool\node_modules\@microsoft\microsoft-graph-client\lib\src\GraphErrorHandler.js:63:22)
    at Function.<anonymous> (C:\Users\GabrieleGrillo\git\trello-migration-tool\node_modules\@microsoft\microsoft-graph-client\lib\src\GraphErrorHandler.js:91:48)
    at step (C:\Users\GabrieleGrillo\git\trello-migration-tool\node_modules\tslib\tslib.js:195:27)
    at Object.next (C:\Users\GabrieleGrillo\git\trello-migration-tool\node_modules\tslib\tslib.js:176:57)
    at C:\Users\GabrieleGrillo\git\trello-migration-tool\node_modules\tslib\tslib.js:169:75
    at new Promise (<anonymous>)
    at Object.__awaiter (C:\Users\GabrieleGrillo\git\trello-migration-tool\node_modules\tslib\tslib.js:165:16)
    at GraphErrorHandler.getError (C:\Users\GabrieleGrillo\git\trello-migration-tool\node_modules\@microsoft\microsoft-graph-client\lib\src\GraphErrorHandler.js:87:24)
    at GraphRequest.<anonymous> (C:\Users\GabrieleGrillo\git\trello-migration-tool\node_modules\@microsoft\microsoft-graph-client\lib\src\GraphRequest.js:315:84) {
  statusCode: 412,
  code: '',
  requestId: '3ef9c0b4-94c3-42cf-b492-fb46b07c7934',
  date: 2024-03-14T10:00:57.000Z,
  body: '{"code":"","message":"The If-Match header must be specified for this kind of request.","innerError":{"date":"2024-03-14T11:00:57","request-id":"3ef9c0b4-94c3-42cf-b492-fb46b07c7934","client-request-id":"***"}}',
  headers: _Headers [Headers] {
    [Symbol(headers list)]: _HeadersList {
      cookies: null,
      [Symbol(headers map)]: Map(13) {
        'cache-control' => { name: 'Cache-Control', value: 'no-cache' },
        'transfer-encoding' => { name: 'Transfer-Encoding', value: 'chunked' },
        'content-type' => { name: 'Content-Type', value: 'application/json' },
        'content-encoding' => { name: 'Content-Encoding', value: 'gzip' },
        'vary' => { name: 'Vary', value: 'Accept-Encoding' },
        'strict-transport-security' => {
          name: 'Strict-Transport-Security',
          value: 'max-age=31536000'
        },
        'request-id' => {
          name: 'request-id',
          value: '3ef9c0b4-94c3-42cf-b492-fb46b07c7934'
        },
        'client-request-id' => {
          name: 'client-request-id',
          value: '***'
        },
        'x-ms-ags-diagnostic' => {
          name: 'x-ms-ags-diagnostic',
          value: '{"ServerInfo":{"DataCenter":"Italy North","Slice":"E","Ring":"5","ScaleUnit":"001","RoleInstance":"MI2PEPF0000024B"}}'
        },
        'x-proxycluster' => {
          name: 'X-ProxyCluster',
          value: 'weu-001.tasks.osi.office.net'
        },
        'x-officecluster' => {
          name: 'X-OfficeCluster',
          value: 'weu-001.tasks.osi.office.net'
        },
        'x-tasks-correlationid' => {
          name: 'X-Tasks-CorrelationId',
          value: '***'
        },
        'date' => { name: 'Date', value: 'Thu, 14 Mar 2024 11:00:56 GMT' }
      },
      [Symbol(headers map sorted)]: null
    },
    [Symbol(guard)]: 'immutable',
    [Symbol(realm)]: null
  }
}

Steps to Reproduce

  1. Invoke the api
    const plannerPlanDetails = {
    categoryDescriptions: {
        category1: "Test"
    }
    };
    await client.api('/planner/plans/'+PLAN_ID+'/details').update(plannerPlanDetails);
  2. I also tried to manually add the header but with no luck, same error
    await client.api('/planner/plans/'+PLAN_ID+'/details').header("If-Match", PLAN_ID).update(plannerPlanDetails);

Usage Information

Request ID - 3ef9c0b4-94c3-42cf-b492-fb46b07c7934

SDK Version - [SDK version you are using]

Node Version - v20.9.0

sebastienlevert commented 3 months ago

Using the odata.etag property is required when updating the plan details. Please update your code without using the ID in your If-Match header!

Eleirbag89 commented 3 months ago

I had to put the 'odata.etag' in the entity, but also the header:

const remotePlanDetails = await client.api('/planner/plans/'+PLAN_ID+'/details').get();
plannerPlanDetails['@odata.etag'] = remotePlanDetails['@odata.etag'];

await client.api('/planner/plans/'+PLAN_ID+'/details').header("If-Match", plannerPlanDetails['@odata.etag']).update(plannerPlanDetails);

It works