Bug report: add webpart with properties not working
See original GitHub issueDescription
Hi Team, i am trying to add webpart on modern page with pre-configured properties, but not working. i have used below lines from https://pnp.github.io/
m365 --% spo page clientsidewebpart add --webUrl https://contoso.sharepoint.com/sites/a-team --pageName page.aspx --standardWebPart BingMap --webPartProperties
“{”“Title”“:”“Foo location”“}”``
m365 spo page clientsidewebpart add --webUrl https://contoso.sharepoint.com/sites/a-team --pageName page.aspx --standardWebPart Image --webPartData '
{ “dataVersion”: “1.8”, “serverProcessedContent”: {“htmlStrings”:{},“searchablePlainTexts”:{“captionText”:“”},“imageSources”:{“imageSource”:“/sites/team-a/SiteAssets/work-life-balance.png”},“links”:{}}, “properties”: {“imageSourceType”:2,“altText”:“a group of people on a beach”,“overlayText”:“Work life balance”,“fileName”:“48146-OFF12_Justice_01.png”,“siteId”:“27664b85-067d-4be9-a7d7-89b2e804d09f”,“webId”:“a7664b85-067d-4be9-a7d7-89b2e804d09f”,“listId”:“37664b85-067d-4be9-a7d7-89b2e804d09f”,“uniqueId”:“67664b85-067d-4be9-a7d7-89b2e804d09f”,“imgWidth”:650,“imgHeight”:433,“fixAspectRatio”:false,“isOverlayTextEnabled”:true}}'
using these lines not able to add standard webpart on the page.
Steps to reproduce
$webPartPropsJson = '{"id":"c70391ea-0b10-4ee9-b2b4-006d3fcad0cd","instanceId":"0683c254-92c4-4a96-adad-dd9fab9a61e0","title":"Quick links","description":"Show a collection of links to content such as documents, images, videos, and more in a variety of layouts with options for icons, images, and audience targeting.","audiences":[],"serverProcessedContent":{"htmlStrings":{},"searchablePlainTexts":{"items[0].title":"Google"},"imageSources":{},"links":{"baseUrl":"https://ajayguptavf.sharepoint.com/sites/mdrndev-comm","items[0].sourceItem.url":"https://google.com"},"componentDependencies":{"layoutComponentId":"706e33c8-af37-4e7b-9d22-6e5694d92a6f"}}}'
Write-Host $webPartPropsJson
# Make sure to add the backticks, double the JSON double-quotes and escape double quotes in properties'values
$webPartPropsJson = '`"{0}"`' -f $webPartPropsJson.Replace('\','\\').Replace('"', '""')
m365 spo page clientsidewebpart add --webUrl $siteUrl --pageName $pageName --standardWebPart QuickLinks --webPartData $webPartPropsJson --debug
Expected results
page created with webpart added in it.
Actual results
Error: Specified webPartData is not a valid JSON string. Input: {"id":"c70391ea-0b10-4ee9-b2b4-006d3fcad0cd","instanceId":"0683c254-92c4-4a96-adad-dd9fab9a61e0","title":"Quick links","description":"Show a collection of links to content such as documents, images, videos, and more in a variety of layouts with options for icons, images, and audience targeting.","audiences":[],"serverProcessedContent":{"htmlStrings":{},"searchablePlainTexts":{"items[0].title":"Google"},"imageSources":{},"links":{"baseUrl":"https://ajayguptavf.sharepoint.com/sites/mdrndev-comm","items[0].sourceItem.url":"https://google.com"},"componentDependencies":{"layoutComponentId":"706e33c8-af37-4e7b-9d22-6e5694d92a6f"}}}
. Error: SyntaxError: Unexpected token ` in JSON at position 0
Diagnostics
No response
CLI for Microsoft 365 version
v4.3.0
nodejs version
v12.16.1
Operating system (environment)
Windows
Shell
PowerShell
cli doctor
No response
Additional Info
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
@arjunumenon will post an update once I have tested in windows. Anyway thanks for quick responses @waldekmastykarz @arjunumenon
Hello @ag0059985 - I had tried recreating the issue in Windows 10 with PowerShell Version
5.1.18362
. If you modify your script based on @waldekmastykarz 's suggestion by removing the outer backticks, it is working as expected.Please let us know if you are still facing the issue.