4

How do I set a custom field value for an Activity via the REST API?

I can create an activity on a contact. I am looking to set a value for a custom field within that activity as well.

For reference my current POST request looks something like this:

<www_path>?entity=activity&action=create&activity_id=0&target_contact_id=0

Any insight is appreciated! Thanks for the help!

3

You need to know the custom field ID of the field in question. If the ID is 14, you can use:

<www_path>?entity=activity&action=create&activity_id=0&target_contact_id=0&custom_14=myvalue

In general, if you're asking these sorts of questions, you can answer them best by using the API explorer: Help menu > Developer > API Explorer. You can use it to design your query, and it will build your REST string for you - including looking up custom field IDs.

To get the ID via the GUI, you can go to Administer menu > Customize Data and Screens > Custom Fields, then select "View and Edit Custom Fields" for the appropriate group. If you hover your mouse over the "Edit Field" link, you'll see a URL that ends in "&id=x". "x" is your field ID.

To get the field ID via the API, do a call to CustomField.get. Here's a REST call to get the ID of a field called "Mail Designation":

/sites/all/modules/civicrm/extern/rest.php?entity=CustomField&action=get&json={"sequential":1,"label":"Mail Designation"}&api_key=yourkey&key=sitekey

Better still, use CustomField.getvalue to return just the ID:

/sites/all/modules/civicrm/extern/rest.php?entity=CustomField&action=getvalue&json={"sequential":1,"return":"id","label":"Mail Designation"}&api_key=yourkey&key=sitekey
  • Jon, thanks for the answer and including that resource. I believe this is what I need. Cheers! -matt – mac Jun 19 '15 at 20:03
  • Jon - a follow up. Any clue how to get the ID of a custom field via the api or GUI? Thanks for the help. – mac Jun 19 '15 at 20:27
  • @mcphilly I edited my answer to include your follow-up question. – Jon G - Megaphone Tech Jun 25 '15 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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