Warm tip: This article is reproduced from serverfault.com, please click

Add weather WebPart using Add-PnPClientSideWebPart is not setting location

发布于 2020-12-14 04:32:42

I'm trying to add a weather WebPart on a modern page in SharePoint Online.

This is the PowerShell I'm executing:

$jsonProperties = '
{
    "serverProcessedContent": {
        "searchablePlainTexts": {
            "webPartTitle": "Weather"
        }
    },
    "properties": {
        "temperatureUnit": "C",
        "locations": [
            {
                "countryName": "Australia",
                "name": "Manjimup, Australia",
                "latitude": -34.24055862426758,
                "longitude": 116.14610290527344,
                "showCustomizedDisplayName": false
            },
            {
                "countryName": "Australia",
                "name": "Bega, Australia",
                "latitude": -36.673919677734378,
                "longitude": 149.84178161621095,
                "showCustomizedDisplayName": false
            }
        ]
    }
}'

Add-PnPClientSideWebPart -Page https://mysharepointsite.sharepoint.com/Sites/MyPage -DefaultWebPartType Weather -WebPartProperties $jsonProperties

The WebPart is being added but there are no weather locations, as shown below.

Weather WebPart

What am I missing for the locations to be added to the WebPart?

Questioner
Høgsdal
Viewed
0
Høgsdal 2020-12-15 07:18:47

I was missing the property "dataVersion": "1.2". The full JSON looks like this:

$jsonProperties = '
{
    "dataVersion": "1.2",
    "serverProcessedContent": {
        "searchablePlainTexts": {
            "webPartTitle": "Weather"
        }
    },
    "properties": {
        "temperatureUnit": "C",
        "locations": [
            {
                "countryName": "Australia",
                "name": "Manjimup, Australia",
                "latitude": -34.24055862426758,
                "longitude": 116.14610290527344,
                "showCustomizedDisplayName": false
            },
            {
                "countryName": "Australia",
                "name": "Bega, Australia",
                "latitude": -36.673919677734378,
                "longitude": 149.84178161621095,
                "showCustomizedDisplayName": false
            }
        ]
    }
}'