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

Unable to add existing site column to content typ (ct.field_links.add())

Open tuesdayMike opened this issue 10 months ago • 1 comments

Hi,

I'm struggling to add existing site columns to content type.

Code: ` field_target = ctx_dest.web.fields.get_by_internal_name_or_title(field.title).execute_query() print(f" - Mapping Field: {field_target.internal_name} Target-ID: {field_target.id}")

field_links = ct_target.field_links.add(field_target).execute_query() ` The field_target is found and of type 'office365.sharepoint.fields.field.Field'.

The error is:

`Traceback (most recent call last): File "/home/joe/.local/lib/python3.10/site-packages/office365/runtime/client_request.py", line 37, in execute_query response = self.execute_request_direct(request) File "/home/joe/.local/lib/python3.10/site-packages/office365/runtime/client_request.py", line 101, in execute_request_direct response.raise_for_status() File "/usr/lib/python3/dist-packages/requests/models.py", line 943, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://joe.sharepoint.com/sites/Joe_PROD/_api/Web/ContentTypes('0x0100DBB1EA60214E52428BCC389XXXSSSAAA')/FieldLinks

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/joe/reporting/sharepoint_list_mgmt/sp_site_config_reproduce.py", line 189, in field_link = ct_target.field_links.add(field_target).execute_query() File "/home/joe/.local/lib/python3.10/site-packages/office365/runtime/client_object.py", line 55, in execute_query self.context.execute_query() File "/home/joe/.local/lib/python3.10/site-packages/office365/runtime/client_runtime_context.py", line 173, in execute_query self.pending_request().execute_query(qry) File "/home/joe/.local/lib/python3.10/site-packages/office365/runtime/client_request.py", line 41, in execute_query raise ClientRequestException(*e.args, response=e.response) office365.runtime.client_request_exception.ClientRequestException: ('-2147024809, System.ArgumentException', "Die Spalte 'Absender' ist nicht vorhanden. Möglicherweise wurde sie von einem anderen Benutzer gelöscht. https://joe.sharepoint.com/sites/Joe_PROD ", "400 Client Error: Bad Request for url: https://joe.sharepoint.com/sites/Joe_PROD/_api/Web/ContentTypes('0x0100DBB1EA60214E52428BCC389XXXSSSAAA')/FieldLinks") `

tuesdayMike avatar Feb 19 '25 14:02 tuesdayMike

I tried switching to plain vanilla http requests (SP Rest API) but âlways get to the 404 point. This limitations seems to be the problem:

Site Columns cannot be added to a content type using the REST service.

Source: https://learn.microsoft.com/en-us/previous-versions/office/sharepoint-visio/jj245869(v=office.15)

tuesdayMike avatar Feb 20 '25 19:02 tuesdayMike