sharepoint-onlinepower-automatesharepoint-rest-api

Send a BATCH request to SharePoint with 2 POST and 1 PATCH. will ignore the PATCH


have this BATCH request to SharePoint Online. where i am doing the following:-

  1. Move the item to Closed folder

  2. Reset Item Permission

  3. Update the ActiveStatus column to closed, as follow:-

enter image description here

--batch_1234
Content-Type: multipart/mixed; boundary="changeset_1234"

--changeset_1234
Content-Type: application/http
Content-Transfer-Encoding: binary

POST  ****/sites/Seagulls-PPM-Test/_api/Web/getFileByServerRelativeURL('/sites/Seagulls-PPM-Test/Lists/PrintingOrdersDetails/100_.000')/moveTo(newurl='/sites/Seagulls-PPM-Test/Lists/PrintingOrdersDetails/Closed/100_.000',flags=1) HTTP/1.1

--changeset_1234
Content-Type: application/http
Content-Transfer-Encoding: binary

POST ****/sites/Seagulls-PPM-Test/_api/Web/lists('a55243c2-6865-4e5b-acfb-f7ca02c048f7')/items(100)/ResetRoleInheritance() HTTP/1.1

--changeset_1234
Content-Type: application/http
Content-Transfer-Encoding:binary

PATCH *****/sites/Seagulls-PPM-Test/_api/lists('a55243c2-6865-4e5b-acfb-f7ca02c048f7')/items(100) HTTP/1.1
Content-Type: application/json;type=entry

{
    "ActiveStstus":"Closed"
}

--changeset_1234--

--batch_1234--

where the item will get moved + has a reset permission, but its ActiveStatus will not get set to closed?? so seems the PATCH request will be ignored, any advice?

Here is the API call response:-

{
  "$content-type": "multipart/mixed; boundary=batchresponse_330d5f39-8eb9-4062-9a93-5118a09bc998",
  "$content": "LS1iYXRjaHJlc3BvbnNlXzMzMGQ1ZjM5LThlYjktNDA2Mi05YTkzLTUxMThhMDliYzk5OA0KQ29udGVudC1UeXBlOiBhcHBsaWNhdGlvbi9odHRwDQpDb250ZW50LVRyYW5zZmVyLUVuY29kaW5nOiBiaW5hcnkNCg0KSFRUUC8xLjEgMjAwIE9LDQpDT05URU5ULVRZUEU6IGFwcGxpY2F0aW9uL3htbDtjaGFyc2V0PXV0Zi04DQoNCjw/eG1sIHZlcnNpb249IjEuMCIgZW5j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LTUxMThhMDliYzk5OA0KQ29udGVudC1UeXBlOiBhcHBsaWNhdGlvbi9odHRwDQpDb250ZW50LVRyYW5zZmVyLUVuY29kaW5nOiBiaW5hcnkNCg0KSFRUUC8xLjEgNDEyIFByZWNvbmRpdGlvbiBGYWlsZWQNCkNPTlRFTlQtVFlQRTogYXBwbGljYXRpb24vanNvbjtvZGF0YT12ZXJib3NlO2NoYXJzZXQ9dXRmLTgNCg0KeyJlcnJvciI6eyJjb2RlIjoiLTEsIE1pY3Jvc29mdC5TaGFyZVBvaW50LkNsaWVudC5DbGllbnRTZXJ2aWNlRXhjZXB0aW9uIiwibWVzc2FnZSI6eyJsYW5nIjoiZW4tVVMiLCJ2YWx1ZSI6IlRoZSByZXF1ZXN0IEVUYWcgdmFsdWUgJycgZG9lcyBub3QgbWF0Y2ggdGhlIG9iamVjdCdzIEVUYWcgdmFsdWUgJ1wiZGIyOGRiMDgtZTBjYy00ZjM4LWE4ODgtMmQ4NjBiZTk0ZTM3LDJcIicuIn19fQ0KLS1iYXRjaHJlc3BvbnNlXzMzMGQ1ZjM5LThlYjktNDA2Mi05YTkzLTUxMThhMDliYzk5OC0tDQo=",
  "$multipart": [
    {
      "headers": {
        "Content-Type": "application/http; msgtype=response",
        "Content-Transfer-Encoding": "binary",
        "Content-Length": "348"
      },
      "body": {
        "$content-type": "application/http; msgtype=response",
        "$content": "SFRUUC8xLjEgMjAwIE9LDQpDT05URU5ULVRZUEU6IGFwcGxpY2F0aW9uL3htbDtjaGFyc2V0PXV0Zi04DQoNCjw/eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9InV0Zi04Ij8+PGQ6TW92ZVRvIHhtbG5zOmQ9Imh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vYWRvLzIwMDcvMDgvZGF0YXNlcnZpY2VzIiB4bWxuczptPSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL2Fkby8yMDA3LzA4L2RhdGFzZXJ2aWNlcy9tZXRhZGF0YSIgeG1sbnM6Z2VvcnNzPSJodHRwOi8vd3d3Lmdlb3Jzcy5vcmcvZ2VvcnNzIiB4bWxuczpnbWw9Imh0dHA6Ly93d3cub3Blbmdpcy5uZXQvZ21sIiBtOm51bGw9InRydWUiIC8+",
        "$applicationHttp": {
          "headers": {},
          "body": {
            "$content-type": "application/xml; charset=utf-8",
            "$content": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48ZDpNb3ZlVG8geG1sbnM6ZD0iaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS9hZG8vMjAwNy8wOC9kYXRhc2VydmljZXMiIHhtbG5zOm09Imh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vYWRvLzIwMDcvMDgvZGF0YXNlcnZpY2VzL21ldGFkYXRhIiB4bWxuczpnZW9yc3M9Imh0dHA6Ly93d3cuZ2VvcnNzLm9yZy9nZW9yc3MiIHhtbG5zOmdtbD0iaHR0cDovL3d3dy5vcGVuZ2lzLm5ldC9nbWwiIG06bnVsbD0idHJ1ZSIgLz4="
          },
          "statusCode": 200
        }
      }
    },
    {
      "headers": {
        "Content-Type": "application/http; msgtype=response",
        "Content-Transfer-Encoding": "binary",
        "Content-Length": "362"
      },
      "body": {
        "$content-type": "application/http; msgtype=response",
        "$content": "SFRUUC8xLjEgMjAwIE9LDQpDT05URU5ULVRZUEU6IGFwcGxpY2F0aW9uL3htbDtjaGFyc2V0PXV0Zi04DQoNCjw/eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9InV0Zi04Ij8+PGQ6UmVzZXRSb2xlSW5oZXJpdGFuY2UgeG1sbnM6ZD0iaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS9hZG8vMjAwNy8wOC9kYXRhc2VydmljZXMiIHhtbG5zOm09Imh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vYWRvLzIwMDcvMDgvZGF0YXNlcnZpY2VzL21ldGFkYXRhIiB4bWxuczpnZW9yc3M9Imh0dHA6Ly93d3cuZ2VvcnNzLm9yZy9nZW9yc3MiIHhtbG5zOmdtbD0iaHR0cDovL3d3dy5vcGVuZ2lzLm5ldC9nbWwiIG06bnVsbD0idHJ1ZSIgLz4=",
        "$applicationHttp": {
          "headers": {},
          "body": {
            "$content-type": "application/xml; charset=utf-8",
            "$content": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48ZDpSZXNldFJvbGVJbmhlcml0YW5jZSB4bWxuczpkPSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL2Fkby8yMDA3LzA4L2RhdGFzZXJ2aWNlcyIgeG1sbnM6bT0iaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS9hZG8vMjAwNy8wOC9kYXRhc2VydmljZXMvbWV0YWRhdGEiIHhtbG5zOmdlb3Jzcz0iaHR0cDovL3d3dy5nZW9yc3Mub3JnL2dlb3JzcyIgeG1sbnM6Z21sPSJodHRwOi8vd3d3Lm9wZW5naXMubmV0L2dtbCIgbTpudWxsPSJ0cnVlIiAvPg=="
          },
          "statusCode": 200
        }
      }
    },
    {
      "headers": {
        "Content-Type": "application/http; msgtype=response",
        "Content-Transfer-Encoding": "binary",
        "Content-Length": "319"
      },
      "body": {
        "$content-type": "application/http; msgtype=response",
        "$content": "SFRUUC8xLjEgNDEyIFByZWNvbmRpdGlvbiBGYWlsZWQNCkNPTlRFTlQtVFlQRTogYXBwbGljYXRpb24vanNvbjtvZGF0YT12ZXJib3NlO2NoYXJzZXQ9dXRmLTgNCg0KeyJlcnJvciI6eyJjb2RlIjoiLTEsIE1pY3Jvc29mdC5TaGFyZVBvaW50LkNsaWVudC5DbGllbnRTZXJ2aWNlRXhjZXB0aW9uIiwibWVzc2FnZSI6eyJsYW5nIjoiZW4tVVMiLCJ2YWx1ZSI6IlRoZSByZXF1ZXN0IEVUYWcgdmFsdWUgJycgZG9lcyBub3QgbWF0Y2ggdGhlIG9iamVjdCdzIEVUYWcgdmFsdWUgJ1wiZGIyOGRiMDgtZTBjYy00ZjM4LWE4ODgtMmQ4NjBiZTk0ZTM3LDJcIicuIn19fQ==",
        "$applicationHttp": {
          "headers": {},
          "body": {
            "error": {
              "code": "-1, Microsoft.SharePoint.Client.ClientServiceException",
              "message": {
                "lang": "en-US",
                "value": "The request ETag value '' does not match the object's ETag value '\"db28db08-e0cc-4f38-a888-2d860be94e37,2\"'."
              }
            }
          },
          "statusCode": 412
        }
      }
    }
  ]
}

Also if i add this to the request header Content-Type: application/json;odata=verbose Accept: application/json;odata=verbose If-Match: *

the error will be :-

 "error": {
              "code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
              "message": {
                "lang": "en-US",
                "value": "An entry without a type name was found, but no expected type was specified. To allow entries without type information, the expected type must also be specified when the model is specified."
              }

Solution

  • You have to add X-HTTP-Method: MERGE and If-Match: * to the PACTH request.

    --batch_1234
    Content-Type: multipart/mixed; boundary="changeset_1234"
    
    --changeset_1234
    Content-Type: application/http
    Content-Transfer-Encoding: binary
    
    POST  ****/sites/Seagulls-PPM-Test/_api/Web/getFileByServerRelativeURL('/sites/Seagulls-PPM-Test/Lists/PrintingOrdersDetails/100_.000')/moveTo(newurl='/sites/Seagulls-PPM-Test/Lists/PrintingOrdersDetails/Closed/100_.000',flags=1) HTTP/1.1
    
    --changeset_1234
    Content-Type: application/http
    Content-Transfer-Encoding: binary
    
    POST ****/sites/Seagulls-PPM-Test/_api/Web/lists('a55243c2-6865-4e5b-acfb-f7ca02c048f7')/items(100)/ResetRoleInheritance() HTTP/1.1
    
    --changeset_1234
    Content-Type: application/http
    Content-Transfer-Encoding:binary
    
    PATCH *****/sites/Seagulls-PPM-Test/_api/lists('a55243c2-6865-4e5b-acfb-f7ca02c048f7')/items(100) HTTP/1.1
    Accept: application/json
    Content-Type: application/json
    X-HTTP-Method: MERGE
    If-Match: *    
    
    {
        "ActiveStstus":"Closed"
    }
    
    --changeset_1234--
    --batch_1234--
    

    Source: How to do a Update/Merge/Patch to a SharePoint list with SharePoint_api

    When there is an error about type missing, it's usually when the __metadata node is missing, where NameOfYourList is the name of your list + ListItem (for example, for PrintingOrdersDetails the type is SP.Data.PrintingOrdersDetailsListItem:

    {
       __metadata: {
        "type": "SP.Data.NameOfYourListListItem"
       }, {
        "ActiveStstus":"Closed"
       }
    }
    

    Source: SharePoint REST API: How to find the List or Library “__metadata” “type”