0

I am trying to update the plan details through Microsoft Graph API. My project is MVC .Net 4. GET and POST request are good but when I tried to update the details of the plan, IF-Match header was mandatory in the request so I am sending ETAG value in the if-match section but keep saying IF-Match Value is invalid and sometimes says quoted wrong. help me.

These are some responses once I build in the order out the requests below 1) Error in/Home/EditPlanAction: The format of value 'W/\"JzEtUGxhbiAgQEBAQEBAQEBAQEBAQEBATCc=\"' is invalid.

2 & 3) Error in/Home/EditPlanAction: { "error": { "code": "", "message": "The If-Match header contains an invalid value.", "innerError": { "request-id": "e7744797-f0ac-45c6-a1a6-73dcd3838759", "date": "2019-05-03T21:03:24" } } }

if (method != HttpMethod.Get && method != HttpMethod.Delete && method != 
    HttpMethod.Post && method != HttpMethod.Put)


{


string uri1 = uri.Replace("/details", "");
HttpResponseMessage foretag = await 
ServiceHelper.SendRequest(HttpMethod.Get, $"{graphV1Endpoint}{uri1}", 
accessToken);



 //EntityTagHeaderValue entityTagHeaderValue = new 
                     EntityTagHeaderValue((foretag.Headers.ETag.Tag));

     //JsonConvert.SerializeObject(entityTagHeaderValue, jsonSettings);

      string etag1 = foretag.Headers.ETag.Tag;

      string etag2 = etag1.Replace("\"", "");

      //string etag3 = "W/\\\"" + etag2 + "\\\"";


 `request.Headers.Add("If-Match", "W/\\\"" + etag2 + "\\\"");`
 `request.Headers.Add("If-Match", "W/\"" + etag2 + "\"");`
 `request.Headers.Add("If-Match", "\"" + etag2 + "\"");`
 `request.Headers.Add("If-Match", "\\\"" + etag2 + "\\\"");`
 `request.Headers.Add("If-Match",  etag2 );`
Ashok Subedi
  • 217
  • 2
  • 10
  • If you're getting different error messages, that suggests you're trying different code. Can you edit your question to include specific (but short!) examples of what you've tried and the corresponding result? – B. Shefter May 03 '19 at 20:41
  • Hi, Thanks for quick response i added some responses I got after I tried those request.Headers on the bottom in order – Ashok Subedi May 03 '19 at 21:06

1 Answers1

0

Fixed, so my problem was I kept using Plan's Etag to update Plan Details. Little did I know that even if we are working on the same plan, plan details for that plan would have different Etag. Instead of doing new get request to grab plans Etag from the response, i got the plan details Etag and sent it to request for the details and it worked. feel free to comment if anyone is going through the same problem and want more details on the problem. I wrote a new function called GetMyEtag that gets the etag of the plan details I am trying to update.

Ashok Subedi
  • 217
  • 2
  • 10