3

Using the contact - getoptions method you can read the list of options for a custom field with select type.

/civicrm/civicrm/extern/rest.php?entity=Contact&action=getoptions&api_key=userkey&key=sitekey&json={"sequential":1,"field":"custom_5"}

But how can I create new options using the API?

1
  • Oh, I think it's OptionValue. Let me check ....
    – James
    Commented Feb 8, 2016 at 14:13

2 Answers 2

1

Use CustomField - get method to get data for the select custom field who's options you want to edit. Note down the "option_group_id" value.

Then use the OptionGroup and OptionValue API methods with the Option Group you just noted. With this you can add new options.

1
  • You can also use a chained API to do this in one call if necessary! In Civi 4.7, I believe you can also use a joined API call here as well. Commented May 10, 2016 at 4:47
0

As james mentioned, it's entity=optionvalue and action=create

However, as opposed as what you shared for the getoption, it isn't possible to have the values you want to create as a get parameter, they have to be in post (for security reasons).

So the easiest is to use post for everything, it works and avoid the issue of knowing if it's a destructive operation or not that you want to perform in the api.

and depending of the language you use, we might already have a wrapper that hide all these details and take care of calling the right url with the right params

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.