SharePoint / sp-dev-docs

SharePoint & Viva Connections Developer Documentation
https://docs.microsoft.com/en-us/sharepoint/dev/
Creative Commons Attribution 4.0 International
1.25k stars 1.01k forks source link

SharePoint REST API: Issue updating CanvasContent1 #3526

Open DroopyTersen opened 5 years ago

DroopyTersen commented 5 years ago

Category

Expected or Desired Behavior

I would expect to able to update a Modern Page's CanvasContent1 property via the REST API.

Observed Behavior

Is there tenant, site or library level property that might prevent the REST API from persisting the CanvasContent1 property update?

Steps to Reproduce

I am performing the following SharePoint REST API HTTP Request from inside a SPFx webpart (currently from /_layouts/workbench.aspx of the target site.

fetch(
    "https://TENANT.sharepoint.com/sites/THE_SITE/_api/Web/Lists(guid'a1ba5ef3-2c67-4b42-9cc9-4af7b95d9372')/Items(5)",
    {
        credentials: "include",
        headers: {
            accept: "application/json;odata=verbose",
            "accept-language": "en-US,en;q=0.9",
            "cache-control": "no-cache",
            "content-type": "application/json;odata=verbose",
            "if-match": "*",
            pragma: "no-cache",
            "x-http-method": "MERGE",
            "x-requestdigest": "DIGEST IS HERE,01 Mar 2019 15:15:06 -0000",
        },
        referrer: "https://TENANT.sharepoint.com/sites/THE_SITE/_layouts/15/workbench.aspx",
        referrerPolicy: "no-referrer-when-downgrade",
        body: JSON.stringify({ __metadata: {"type":"SP.Data.SitePagesItem"}, CanvasContent1: `<div>I took the CanvasContent1 from a different page and set it here</div>` }),
                method: "POST",
    }
);

As stated above:

msft-github-bot commented 5 years ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

jansenbe commented 5 years ago

Did you try setting both in the same request?

DroopyTersen commented 5 years ago

@jansenbe yes, I did try updating both properties at once. The LayoutWebPartsContent updates as expected. The CanvasContent1 property acts as if nothing happened.

I also tried purposefully using an invalid property ID, CanvasContentXXX to make sure it wasn't it wasn't an issue of errors being silently swallowed. When doing this though, I received the invalid Field error as expected.

Kind of at a loss at how to proceed. Ultimately I am trying to clone pages while running the page content through some replacer functions. Is there another way to achieve this that doesn't require an update of CanvasContent1?

juliemturner commented 5 years ago

I'm also having this exact issue. For me this is with a solution that has been working for 4 months and just stopped working about 2-3 weeks ago. I have the exact same request running in 3 different tenants. 2 of the 3 tenants fails but only in site collections that were created since the issue started. In site collections that were created before the issue started the call still works properly. In the 3rd site collection the call works regardless if the site collection was recently created or has existed for some time.

I've replicated the issue with an OOB webpart instead of the custom webpart the solution uses, just to take that out of the equation.

GUIDs altered for privacy...

RESPONSE: 204 POST: https://shirepharmadev.sharepoint.com/sites/MLTest2/_api/Web/Lists(guid'05c919c8-1902-44ec-b636-18134cf26632')/Items(24) PAYLOAD: {"__metadata":{"type":"SP.Data.SitePagesItem"},"CanvasContent1":"

<div data-sp-canvascontrol=\"\" data-sp-canvasdataversion=\"1.0\" data-sp-controldata=\"{"controlType":3,"id":"cdb5c8ec-df14-4b23-8296-401ebee3451e","position":{"controlIndex":1,"sectionFactor":12,"sectionIndex":1,"zoneIndex":1},"webPartId":"daf0b71c-6de8-4ef7-b511-faae7c388708"}\"><div data-sp-webpart=\"\" data-sp-webpartdataversion=\"1.0\" data-sp-webpartdata=\"{"dataVersion":"1.0","description":"Dynamically display content based on location, type, and filtering","id":"daf0b71c-6de8-4ef7-b511-faae7c388708","instanceId":"cdb5c8ec-df14-4b23-8296-401ebee3451e","properties":{},"serverProcessedContent":null,"title":"Highlighted content"}\">
daf0b71c-6de8-4ef7-b511-faae7c388708
<div data-sp-htmlproperties=\"\">
"}

rohit404404 commented 3 years ago

Was this ever resolved or any alternative?

achimismaili commented 1 year ago

From Power Automate, I am able to successfully update the CANVASCONTENT1 property formatted as JSON in the following way for a modern SPO page: POST Body: { "CanvasContent1": "[{\"webPartId\":\"d1d91...[some more content]...on\":4},\"isEmailReady\":false}}]" } POST Headers: { "Accept": "application/json; odata=nometadata", "Content-Type": "application/json;odata=verbose" } POST URL: https://[tenant].sharepoint.com/sites/[sitename] POST URI: /_api/sitepages/pages(@{triggerOutputs()?['body/ID']})/SavePageAsDraft

hope that helps.

Before I was able to do that, I had to checkout the page /_api/sitepages/pages(@{triggerOutputs()?['body/ID']})/checkoutpage. The ID used is just the SharePoint integer list-item-ID of the page.

frevds commented 3 months ago

The issue seems to be that the fields CanvasContent1 and LayoutWebpartsContent in the SitePages library cannot have more than 255 characters, which can silently fail (a field error being returned in the request instead, e.g. when using ValidateUpdateListItem). It's obviously not limited to 255 characters, but the validation insists it is. After cutting it down to this length, which is all but easy, it saves.