patching a FHIR resource requires the content type to be: application/json-patch+json

Raj
Raj
606 Points
25 Posts

I'm try to do patch http request update resource on GCP Fhir but getting following error:

"issue": [
    {
      "code": "structure",
      "details": {
        "text": "invalid_headers"
      },
      "diagnostics": "patching a FHIR resource requires the content type to be: application/json-patch+json",
      "severity": "error"
    }
  ],
  "resourceType": "OperationOutcome"
}

I'm trying following code:

var client = await CreateHttpClient().ConfigureAwait(false);
var url = uriBuilder.ToString();
var httpContent = new StringContent(patientData, Encoding.UTF8, "application/json-patch+json");
var result = await client.PatchAsync(url, httpContent).ConfigureAwait(false);
var content = await result.Content.ReadAsStringAsync().ConfigureAwait(false);
if (!(result.StatusCode == System.Net.HttpStatusCode.OK || result.StatusCode == System.Net.HttpStatusCode.Created))
{
    _logger.LogCritical($"Issue in update bundle error is {content}");
    throw new AggregateException(content);
}

var fjp = new FhirJsonParser();
return fjp.Parse<Hl7.Fhir.Model.DomainResource>(content);
Views: 432
Total Answered: 2
Total Marked As Answer: 2
Posted On: 09-Jun-2023 01:00

Share:   fb twitter linkedin
Answers
Rashmi
Rashmi
1008 Points
19 Posts
         

You are missing to add content-type "application/json-patch+json" in header.

Posted On: 12-Jun-2023 01:58
Raj
Raj
606 Points
25 Posts
         

Thanks. Resolved my issue by adding content-type header as:

 var httpContent = new StringContent(patientData, Encoding.UTF8);
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json-patch+json");    
Posted On: 12-Jun-2023 02:11
Thanks for sharing solution 👍
 - Brian  12-Jun-2023 02:16
 Log In to Chat