Skip to content

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

Closed as not planned

Description

@tuesdayMike

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")
`

Activity

  1. tuesdayMike commented on Feb 20, 2025

    @tuesdayMike
    Author

    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)

  2. office365-maintainer commented on Oct 3, 2026

    @office365-maintainer

    Not a library defect — this is a documented SharePoint REST limitation. FieldLinkCollection.add() already sends the payload Microsoft documents for this endpoint: an SP.FieldLink object carrying FieldInternalName (see the "REST resource endpoint" section of SP.FieldLinkCollection.add). The server accepts it and then fails to resolve the column, which is the documented behavior:

    • Site Columns cannot be added to a content type using the REST service.
    • You can add a field to a site content type only if the field already exists on the parent content type.
    • You can add a field to a content type associated with a list only if the field already exists on the list. To add a completely new field to a list content type, you have to first add it to the list and then add it to the content type in a separate call to the REST service.

    The failing URL is /_api/Web/ContentTypes('0x...')/FieldLinks, i.e. a site content type, so REST cannot link a site column to it. The same limitation is still present in SharePoint Online (SharePoint/sp-dev-docs#10489).

    Workarounds:

    • List content type: add the column to the list first (e.g. via the UI's "Add from existing site columns" or list.fields.add_field_as_xml(...)), then link it with list.content_types.get_by_name(...).field_links.add(...).
    • Site content type: REST cannot do it — use CSOM/PnP (Add-PnPFieldToContentType) or PowerShell.

    Since this is a server-side limit rather than something the REST client can change, closing as not planned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsharepointSharePoint REST v1 API, ClientContext

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions