Deleting a custom field

Let's say you've got a custom Person field named "Relationship status" and you've realized there's no need to fill this field in anymore, so now you want to delete it.

🚧

We don't recommend deleting a custom field, because it might permanently remove all data. In case you do delete by mistake, there's a chance that you can get it back by contacting our awesome support people.

If you still want to delete a custom field, follow the steps below.

📘

You can adjust and apply this tutorial for deleting the custom field of a Deal, Organization, or a Product item.



Step 1: GET the ID of the custom Person field


First, create a file getPersonFields.php and follow our tutorials on how to find the API token and how to get the company domain.

To make a GET request, you'll need the correct URL meant for getting Person fields, an example would look like this https://{COMPANYDOMAIN}.pipedrive.com/api/v1/personFields?api_token=659c9fddb16335e48cc67114694b52074e812e03. All available endpoints and their URLs are described in our API Reference.

Here's an example of what the request itself should look like in PHP. Don't forget to replace the data in the example code with yours (the $company_domain and the $api_token).

<?php
// Content of getPersonFields.php
  
// Pipedrive API token
$api_token = '659c9fddb16335e48cc67114694b52074e812e03';
  
// Pipedrive company domain
$company_domain = 'theunicorntail';
 
// URL for getting Person fields
$url = 'https://' . $company_domain . '.pipedrive.com/api/v1/personFields?start=0&api_token=' . $api_token;
 
// GET request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   
echo 'Sending request...' . PHP_EOL;
   
$output = curl_exec($ch);
curl_close($ch);
 
// Create an array from the data that is sent back from the API
// As the original content from server is in JSON format, you need to convert it to a PHP array
$result = json_decode($output, true);
 
// Check if data returned in the result is empty
if (empty($result['data'])) {
    exit('Error: ' . $result['error'] . PHP_EOL);
}
 
// Print out full data if the result is not empty
print_r($result['data']);

Execute the code by using the php getPersonFields.php command in the command line.



Step 2: Check the payload of the GET request you just made


If the request was successful, you can now find the id of the custom Person field named "Relationship status" from the payload.

The original payload could be quite bulky, so here's the section from what you'll learn that the id of the custom Person field named "Relationship status" is 9068:

Array
(
    [0] => Array
        (
            [id] => 9068
            [key] => 199fda744ce708da51ac2500dcfc2811c0032365
            [name] => Relationship status
            [order_nr] => 1
            [field_type] => enum
            [add_time] => 2018-09-17 12:15:45
            [update_time] => 2018-09-17 12:16:53
        )


Step 3: Delete the custom Person field by making a DELETE request


Next, create a file deleteCustomPersonField.php

To make a DELETE request, you'll need the correct URL meant for deleting a Person field, an example would look like this https://{COMPANYDOMAIN}.pipedrive.com/api/v1/personFields/9068?api_token=659c9fddb16335e48cc67114694b52074e812e03. If you want to use this tutorial for deleting other types of custom fields, you can find the needed URLs for that below:

Method

URL

Useful for

DELETE

/dealFields/{id}

Deleting a custom Deal field

DELETE

/organizationFields/{id}

Deleting a custom Organization field

DELETE

/personFields/{id}

Deleting a custom Person field

DELETE

/productFields/{id}

Deleting a custom Product field

And as you can see from the example URL, you need to pass along the custom field's $id in the request URL.

Here's an example of what the request should look like in PHP. Don't forget to replace the data in the code example for your actual $id of the custom Person field you want to delete, and again the $company_domain, and the $api_token.

<?php
// Content of deleteCustomPersonField.php
   
// Pipedrive API token
$api_token = '659c9fddb16335e48cc67114694b52074e812e03';
  
// Pipedrive company domain
$company_domain = 'theunicorntail';
  
// The ID of the custom Person field you want to delete
$id = 9068;
  
// URL for deleting a custom Person field
$url = 'https://' . $company_domain . '.pipedrive.com/api/v1/personFields/' . $id . '?api_token=' . $api_token;
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    
echo 'Sending request...' . PHP_EOL;
    
$output = curl_exec($ch);
curl_close($ch);
   
// Create an array from the data that is sent back from the API
// As the original content from server is in JSON format, you need to convert it to a PHP array
$result = json_decode($output, true);
 
// Check if data returned in the result is empty
if (empty($result['data'])) {
    exit('Error: ' . $result['error'] . PHP_EOL);
}
 
// If the custom Person field was deleted successfully, print the ID of the deleted field
if ($result['data']) {
    echo 'Success! The ID of the deleted custom Person field: ' . $result['data']['id'] . PHP_EOL;
}
const pipedrive = require('pipedrive');
const defaultClient = pipedrive.ApiClient.instance;

// Configure authorization by settings api key
// PIPEDRIVE_API_KEY is an environment variable that holds real api key
defaultClient.authentications.api_key.apiKey = process.env.PIPEDRIVE_API_KEY;

async function deletePersonCustomField() {
    try {
        console.log('Sending request...');

        const api = new pipedrive.PersonFieldsApi();
        const FIELD_ID = 9073; // id of the field you want to delete
        const response = await api.deletePersonField(FIELD_ID);

        console.log('Custom field deleted from a person successfully!', response);
    } catch (err) {
        const errorToLog = err.context?.body || err;

        console.log('Deleting custom field failed', errorToLog);
    }
}


deletePersonCustomField();

And now execute the code by using the deleteCustomPersonField.php command in the command line.



Step 4: Check the output of the DELETE request you just made


In case of a successful request, this is the output you'll receive:

Sending request...
Success! The ID of the deleted custom Person field: 9068

You have now successfully deleted the custom Person field called "Relationship status". You can also check the change from the web app.


Read next
Did this page help you?