lcersly lcersly - 1 month ago 6
Java Question

Podio API - updating contact reference

I have an an Podio app that handles customer accounts where each customer has a manager (podio contact). All of this data resides in another system, and we are in the progress off writing software to synch the two. The software is written in java and using the podio api

I'm currently able to read and set all types of fields, except for the manager field (contact).

This is what is received from the API when a customer is loaded:

Received field

But how do you go about updating the manager reference to something else?

I've tried something like:

List<Map<String, Object>> list = new ArrayList<>();
HashMap<String, Object> values = new HashMap<>();

HashMap<String, Object> value = new HashMap<>();
values.put("value", value);

value.put("mail", "");
//also tried user_id and profile_id

and then using the

ItemAPI.updateItemFieldValues(int itemId, int fieldId,
List<Map<String, Object>> values, boolean silent, boolean hook)

to update the field. Where am I going wrong?


Podio app with 'Contact' field, configured to 'Workspace members / share when new address added' (like this screnshot)
Contact sharing settings

Working example in Ruby

  item_id = <some_item_id>
  field_id = <contact_field_numeric_id>
  field_external_id = <contact_field_external_id>

  # set to empty value by field_id
  empty_value = []
  Podio::ItemField.update(item_id, field_id, single_value)

  # set to single value by field_id
  single_value = [{'value' => {'type' => 'user', 'id' => <Podio user id>}}]
  Podio::ItemField.update(item_id, field_id, single_value)

  # set to multiple values by external field id
  multi_values = [{'value' => {'type' => 'user', 'id' => <Podio user id>}}, 
                  {'value' => {'type' => 'user', 'id' => <another Podio user id>}}]
  Podio::ItemField.update(item_id, field_external_id, multi_values)

Will set this contact field to new value single_value or to list of new values multiple_value. Also, I'd strongly recommend to think again about your data architecture. It might be much more scalable to work with Podio Contact app type and use Reference field instead of using Contact field.

Java example:

HashMap<String, Object> pair = new HashMap<>();
HashMap<String, Object> value = new HashMap<>();
List<Map<String, Object>> list = new ArrayList<>();

// set to empty value
list = new ArrayList<>();
ItemAPI.updateItemFieldValues(<itemId>, <fieldId>, list, <silent>, <hook>)

// set to real value
value = new HashMap<>();
list = new ArrayList<>();
pair.put("id", <user_id>);
pair.put("type", "user");
value.put("value", pair);
ItemAPI.updateItemFieldValues(<itemId>, <fieldId>, list, <silent>, <hook>)