Attempting to write prototype initialisation code I want to rename a ContactType using the API action "create". I tried to set:

  • array ('parent_id' => 0)
  • array ('parent_id' => '')

But both error out with "Mandatory key(s) missing from params array: parent_id". I cannot set array('parent_id' => NULL), because it would be like unsetting 'parent_id' which according to the error message cannot be missing. So the question is how do you set it NULL or how do you rename the label of a ContactType using the API?

Edited: Then I discovered that apparently you need the ID of the ContactType when you want to update with 'create', following the instruction that the API explorer gives me when I choose 'update':

The "update" action is deprecated. Use "create" with an id instead.

So I added id as parameter and kept trying ways to set 'parent_id' correctly to NULL. I discovered that array('parent_id' => '0') is the likely way to do that, because it returned a different error message: "already exists". Well yes, I knew that. My intention was to update the label with 'create" according apparently a wrong instruction. Or is this a bug?

1 Answer 1


Rename ContactType label

$result = civicrm_api3('ContactType', 'create', array(
  'sequential' => 1,
  'id' => 1,
  'label' => "test",

This example will rename ContactType Label

I guess this helps !!!!

  • Yes, I can confirm that this is the right approach. So to update existing ContactType you need to first query the id with 'get' and then use the returned 'id' and only the data that needs changing, in this case the label. Still don't understand how you would do that "chained", for instance when you only know 'name'
    – ñull
    Jun 22, 2016 at 11:02
  • @ñull You can chain it like this, for a given contact_id for example you would do $result = civicrm_api3('Contact', 'getsingle', array( 'sequential' => 1, 'id' => 2, 'api.ContactType.get' => array( 'name' => '$value.contact_type' ), )); Does that help?
    – Andrei
    Jun 22, 2016 at 11:39
  • No, not really @Andrei, but thank you any way! I will experiment with this and when necessary post a more specific question separately.
    – ñull
    Jun 23, 2016 at 9:41
  • See my other question: civicrm.stackexchange.com/questions/12578/…
    – ñull
    Jun 23, 2016 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.