CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Set an attribute to undefined/unassigned/blank/null via API
Pages: [1]

Author Topic: Set an attribute to undefined/unassigned/blank/null via API  (Read 2111 times)

sheldon

  • I’m new here
  • *
  • Posts: 7
  • Karma: 0
Set an attribute to undefined/unassigned/blank/null via API
August 19, 2013, 09:13:57 am
Hello,

I'm trying to set the "assigned to" field of an Activity to be unassigned (or blank/undefined/null) via the API. I am not sure how to format the request.

Here is an example of setting the assigned to field:
Code: [Select]
civicrm/extern/rest.php?entity=Activity&action=create&id=1234&assignee_contact_id=5678&json=1
Does anyone know how to un-set this field?

Thanks!
Sheldon

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Set an attribute to undefined/unassigned/blank/null via API
August 20, 2013, 06:43:24 pm
In general, you might try passing in the string literal "null" or to an empty array. To set to an empty array, you probably need to change the form of the request to something like:

civicrm/extern/rest.php?entity=Activity&action=create&json={"id":"1234","assignee_contact_id":[]}

(ie The "json" parameter can be a json-encoded version of the API data. This allows you to set the field to something precise like 0, "", false, null, [], {}, etc.)

FWIW, the assignee_contact_id field is a "special" field that may have its own unique behavior, so it may not work the same way as other fields. One needs to test to see.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Set an attribute to undefined/unassigned/blank/null via API
August 20, 2013, 09:45:11 pm
What is the language of the client doing these requests? If you're lucky, there is already a library that does the params conversion between native and json, calls the rest.php and convert the result.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

sheldon

  • I’m new here
  • *
  • Posts: 7
  • Karma: 0
Re: Set an attribute to undefined/unassigned/blank/null via API
August 22, 2013, 08:19:46 am
Hi, thanks for the replies! Unfortunately nothing is working. The client is custom built in Ruby.

If I pass null:
Code: [Select]
/civicrm/ajax/rest?entity=Activity&action=create&id=106684&assignee_contact_id=null&json=1&debug=1I receive:
Code: [Select]
"error_message":"Invalid  Contact Id"

If I pass an empty array:
Code: [Select]
/civicrm/ajax/rest?entity=Activity&action=create&id=106684&assignee_contact_id=[]&json=1&debug=1I receive:
Code: [Select]
"error_code":"syntax error"

If I pass these values in via the json param:
Code: [Select]
/civicrm/ajax/rest?entity=Activity&action=create&debug=1&json={"id":"106684","assignee_contact_id":[]}
Code: [Select]
/civicrm/ajax/rest?entity=Activity&action=create&debug=1&json={"id":"106684","assignee_contact_id":"null"}
Code: [Select]
/civicrm/ajax/rest?entity=Activity&action=create&debug=1&json={"id":"106684","assignee_contact_id":null}
Code: [Select]
/civicrm/ajax/rest?entity=Activity&action=create&debug=1&json={"id":"106684","assignee_contact_id":false}
Code: [Select]
/civicrm/ajax/rest?entity=Activity&action=create&debug=1&json={"id":"106684","assignee_contact_id":{}}etc.
I receive the exact same errors.

 ???

Thanks again for the help.
« Last Edit: August 22, 2013, 08:22:50 am by sheldon »

sheldon

  • I’m new here
  • *
  • Posts: 7
  • Karma: 0
Re: Set an attribute to undefined/unassigned/blank/null via API
August 27, 2013, 09:10:59 am
No more ideas eh?  :-\ :)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Set an attribute to undefined/unassigned/blank/null via API
August 27, 2013, 12:41:17 pm
Err, the easiest is probably to create an api/v3/ActivityAssignment.php that contains the _create, _get and _delete functions needed (well, only civicrm_api3_activity_assigment_delete) and use this new api.

Check out Phone.php as an example, should work.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Set an attribute to undefined/unassigned/blank/null via API
August 27, 2013, 02:06:28 pm
In 4.4 I would expect the action to be

civicrm_api3( 'ActivityContact', 'get', array('contact_id' => 50, 'activity_id' => 40,  'api.activity_contact.delete' =>  1));

I don't know if the Activity Contact api has been implemented as part of the 4.4 schema changes - but in 4.3 & earlier I would suggest just going with something brutal like SQL (preferably wrapped up in a wrapper to look like the above so you can easily transition.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Set an attribute to undefined/unassigned/blank/null via API

This forum was archived on 2017-11-26.