Skip to main content

JSON Patch

The PATCH methods such as for updating PEA instances are JSON patch methods. Thus, one or more attributes can be specifically overwritten with a single request.

Example

The following scenario shows the change of the name of a PEA instance. Let's assume that the PEA instance with ID 25j7616c-ac12-3a7b-51f3-87b2ce8bf20e has the following values at the moment.

{
"name": "PEA Instance 01",
"version": "1.0.0",
"description": "",
// ...
}

We now want to change the name of the PEA instance to PEA Instance 02. The required request from the client would look like this:

var peaInstanceID = "25j7616c-ac12-3a7b-51f3-87b2ce8bf20e";
var apiKey = ">>>>>---YOUR-API-KEY---<<<<<<"

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Patch, $"https://api.mtp.semodia.com/v1/pea/instance/{peaInstanceId}");
request.Headers.Add("x-api-key", apiKey);

var content = new StringContent(
"[{ " +
" 'operationType': 'Add', " +
" 'path': '/name'," +
" 'op': 'add'," +
" 'value': 'PEA Instance 02'" +
"}]",
null, "application/json");

request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

Multiple JSON patch operations can be performed at the same time.