> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to delete a user-defined field using the web services API

> Describes how to delete a user-defined field using web services

This guide describes how to delete a user-defined field using the web services API.

## Steps

The following REST code snippets use plain http requests to demonstrate how to perform the operation. The WebApi code snippet demonstrates how to perform the same operation using our nuget package [SuperOffice.WebApi][1].

[1]: https://www.nuget.org/packages/SuperOffice.WebApi

<Tabs>
  <Tab title="RESTful REST API">
    Describes how-to delete a Contact user-defined field details by prog-id or label. This deletes the admin version of the field. The layout needs to be published before the change is visible.

    1. Delete the user-defined field:

       **Delete by ProgId**

       ```http theme={null}
       DELETE https://\{\{env\}\}.superoffice.com/\{\{tenant\}\}/api/v1/Contact/UdefLayout/SuperOffice:11
       Authorization: Bearer \{\{token\}\}
       Accept: application/json; charset=utf-8
       ```

       **Delete by FieldLabel**

       ```http theme={null}
       DELETE https://\{\{env\}\}.superoffice.com/\{\{tenant\}\}/api/v1/Contact/UdefLayout/My New Number
       Authorization: Bearer \{\{token\}\}
       Accept: application/json; charset=utf-8
       ```

    2. Make sure the Contact user-defined fields are not currently being updated.

       ```http theme={null}
       GET https://\{\{env\}\}.superoffice.com/\{\{tenant\}\}/api/v1/Contact/UdefLayout/Publish HTTP/1.1
       Authorization: Bearer \{\{token\}\}
       Accept: application/json; charset=utf-8
       ```

       Only if the response is False, proceed to publish and complete the delete operation.

    3. Publish to finalize the delete changes.

       ```http theme={null}
       POST https://\{\{env\}\}.superoffice.com/\{\{tenant\}\}/api/v1/Contact/UdefLayout/Publish HTTP/1.1
       Authorization: Bearer \{\{token\}\}
       Accept: application/json; charset=utf-8
       ```
  </Tab>

  <Tab title="HTTP RPC Agent API">
    Get the current UDefFieldId value for the user-defined field to delete, then pass that into the following request as a query string parameter.

    1. Deletes the user-defined field is 868.

       ```http theme={null}
       POST https://\{\{env\}\}.superoffice.com/\{\{tenant\}\}/api/v1/Agents/UserDefinedFieldInfo/DeleteUserDefinedFieldInfo?UserDefinedFieldInfoId=868 HTTP/1.1
       Authorization: Bearer \{\{token\}\}
       Accept: application/json; charset=utf-8
       ```

    2. Publish to complete the delete operation for this user-defined field.

           <Danger>
             A Publish request creates a new version of all user-defined fields for the entity. Therefore, all user-defined fields not deleted will have updated UdefFieldId values.
           </Danger>

       Before published fields, make sure there is no active publish event happening at the same time. As long as the `IsAnyPublishEventActive` call returns false, it is safe to proceed.

       ```http theme={null}
       POST https://\{\{env\}\}.superoffice.com/\{\{tenant\}\}/api/v1/Agents/UserDefinedFieldInfo/IsAnyPublishEventActive
       Authorization: Bearer \{\{token\}\}
       Accept: application/json; charset=utf-8
       ```

       To prevent anyone from overwriting your field changes, set the publish event flag for the entity.

       ```http theme={null}
       POST https://\{\{env\}\}.superoffice.com/\{\{tenant\}\}/api/v1/Agents/UserDefinedFieldInfo/SetPublishStartSystemEvent
       Authorization: Bearer \{\{token\}\}
       Accept: application/json; charset=utf-8
       Content-Type: application/json; charset=utf-8
       \{
           "OwnerType": "Contact"
       \}
       ```

       Finally issue the publish the request to activate the new field changes.

       ```http theme={null}
       POST https://\{\{env\}\}.superoffice.com/\{\{tenant\}\}/api/v1/Agents/UserDefinedFieldInfo/Publish
       Authorization: Bearer \{\{token\}\}
       Accept: application/json; charset=utf-8
       Content-Type: application/json; charset=utf-8
       \{
           "OwnerType": "Contact"
       \}
       ```

    <Note>
      Depending on the user-case it might be a good idea to [flush caches][4].
    </Note>
  </Tab>
</Tabs>

[4]: ../../../caching/flush-cache


## Related topics

- [How to create a user-defined field using the web services API](/en/api/web-services/howto/custom-objects/rest-create-udef-field.md)
- [How to update a user-defined field using the web services API](/en/api/web-services/howto/custom-objects/rest-update-udef-field.md)
- [How to get all user-defined fields using the web services API](/en/api/web-services/howto/custom-objects/rest-get-all-udef-fields.md)
- [How to set a user-defined list item on a Udef field (services)](/en/api/web-services/howto/custom-objects/set-udef-listitem-value.md)
- [SuperOffice.WebApi.Agents.UserDefinedFieldInfoAgent](/en/api/reference/webapi/SuperOffice.WebApi.Agents.UserDefinedFieldInfoAgent.md)
- [SuperOffice.WebApi.Agents.IUserDefinedFieldInfoAgent](/en/api/reference/webapi/SuperOffice.WebApi.Agents.IUserDefinedFieldInfoAgent.md)
