Office365-REST-Python-Client icon indicating copy to clipboard operation
Office365-REST-Python-Client copied to clipboard

Wrong method used when updating regional settings in SharePoint?

Open killstrelok opened this issue 4 years ago • 0 comments

It appears any attempts to update regional_settings result in ClientRequestException being thrown caused by wrong method being used to update properties. Code below:

    url = 'https://my_tenant.sharepoint.com/sites/test'
    credentials = ClientCredential(client_id, client_secret)
    client = ClientContext(url).with_credentials(credentials)
    regional = client.web.regional_settings.get().execute_query()
    regional.set_property('Time24', True)
    regional.update()
    client.web.execute_query()

Results in: office365.runtime.client_request_exception.ClientRequestException: ('-1, Microsoft.SharePoint.Client.InvalidClientQueryException', 'The type SP.RegionalSettings does not support HTTP PATCH method.', '400 Client Error: Bad Request for url: https://my_tenant.sharepoint.com/sites/test/_api/Web/RegionalSettings')

There is a chance I am doing something silly but I couldn't find a working example so I tried to re-implement the logic used in a powershell script that uses PnP.Powershell module:

$web = Get-PnPWeb -Includes RegionalSettings.TimeZones
$web.RegionalSettings.Time24 = $True
$web.Update()
Invoke-PnPQuery

Any advice will be appreciated.

//EDIT It appears the SP.RegionalSettings property is read-only when accessed using the REST API hence why it's not accepting any updates. I wish I stumbled upon this sooner.

killstrelok avatar Nov 04 '21 09:11 killstrelok