1

I am attempting to change the values of some existing JSON data with a PATCH request, but when sending the request, only some of the requested values are updated, not all.

PATCH Request:

function updateRequest(){
    let updateOptionValuesUrl = 
    'https://something.something.com/v1.0/dealers/Options/289?apiKey=1234abcdefghjiklmnop';
    const updateOptionValuesRequest = new XMLHttpRequest();
    updateOptionValuesRequest.open('PATCH', updateOptionValuesUrl);
    updateOptionValuesRequest.setRequestHeader("Accept", "text/json");
    updateOptionValuesRequest.setRequestHeader("Content-Type", "text/json");
    updateOptionValuesRequest.onreadystatechange = function () {
        const response = updateOptionValuesRequest.response;
        if (!response.response) {
            console.log("updateValueStatus" + " " + updateOptionValuesRequest.status);
            console.log(updateOptionValuesRequest.responseText);
        }
    }
    updateOptionValuesRequest.send('{"platformName":"new-name","optionName": "new-name","dotDigitalId":4,"optionValue":"new-name"}');
}

Existing Data BEFORE REQUEST

{
  "data": [
    {
      "rooftopGoogleOptionId": 289,
      "googleId": 112,
      "dotDigitalId": 2,
      "optionName": "test-name",
      "optionValue": "test-name",
      "platformName": "test-name",
      "googleAccount": {
        "googleId": 112,
        "active": false,
        "viewId": 51008847,
        "viewName": "www.something.com",
        "credentials": "",
        "vdpUrlPatterns": null,
        "updatedBy": null,
        "updatedAt": null,
      },
}

Existing DATA AFTER Request

{
  "data": [
    {
      "rooftopGoogleOptionId": 289,
      "googleId": 112,
      "dotDigitalId": 2,
      "optionName": "test-name",
      "optionValue": "new-name",
      "platformName": "new-name",
      "googleAccount": {
        "googleId": 112,
        "active": false,
        "viewId": 51008847,
        "viewName": "www.something.com",
        "credentials": "",
        "vdpUrlPatterns": null,
        "updatedBy": null,
        "updatedAt": null,
      },
}

As you can see above, optionName & dotDigitalId did NOT update even though they were both in the request.

  • We need to see the controller code. – Barmar Sep 01 '21 at 20:22
  • @Bamar, I don't have access to it, I am using Swagger to access the JSON data, & I don't know the developer who wrote the code. It's so unfortunate, I am attempting to resolve the issue with what I have. – slowstarder Sep 01 '21 at 20:25
  • This isn't an issue in the client, it depends on what the controller does with the JSON you send it. – Barmar Sep 01 '21 at 20:26

0 Answers0