I am using the dotnet Podio API to fetch and update items. Whenever I try to update an item, using the ItemService.UpdateItem() function, that has an app relation I get an exception along the lines of:

Invalid value {"files": [], "sharefile_vault_url": null, "title": "10", "app_item_id": 1, "app": {"status": "active", "sharefile_vault_url": null, ... "sharefile_vault_folder_id": null, "revision": 0} (object): must be integer

This happens even when the app relation is neither being accessed nor changed.

It seems that when updating an item with a relation, the relation must be a reference id (or some integer) and cannot be the referenced object itself, though this is provided when fetching the item. Setting the relation to an integer id does not help and the same exception is produced.

If the item template has an app relation but the relation is empty for an individual item, the exception is not thrown.

I've tried recreating the apps in Podio to see if there were some inherent faults with the structures of the apps.

I've tried updating the relation of an item to the id of the relation it was already referencing before updating the item.

I've tried using the ItemService.UpdateItemFieldValues() function. Here, the exception is not thrown but the item isn't updated either (How can fields be specified in this function?).

string clientId = "client";
string clientSecret = "secret";
int employeeAppId = 123456789;

var podio = new Podio(clientId, clientSecret);
podio.AuthenticateWithPassword("username", "password");

string employeeQrIdExternalId = "id";
Dictionary<string, object> filter = new Dictionary<string, object>
{
   {employeeQrIdExternalId, "1234"}
};
var filteredItems = podio.ItemService.FilterItems(appId: employeeAppId, filters: filter);
Item employee = filteredItems.Items.First();

podio.ItemService.UpdateItem(employee); // exception is thrown

1 Answers

0
Akbar Badhusha On

You can't use the item object you got from the filter item directly to update back to podio. You need to create a new item to do that.

Eg:

    string clientId = "client";
    string clientSecret = "secret";
    int employeeAppId = 123456789;

    var podio = new Podio(clientId, clientSecret);
    podio.AuthenticateWithPassword("username", "password");

    string employeeQrIdExternalId = "id";
    Dictionary<string, object> filter = new Dictionary<string, object>
    {
       {employeeQrIdExternalId, "1234"}
    };
    var filteredItems = podio.ItemService.FilterItems(appId: employeeAppId, filters: filter);
    Item employeeFilteredItem = filteredItems.Items.First();
    var employee= new Item();
    employee.ItemId = employeeFilteredItem.ItemId;

//Set your fields here, updating app reference field will be like below 
    var appReferenceField = employee.Field<AppItemField>("app-reference");
appReferenceField.ItemIds = new List<int>
{
    1234, 4568 // item ids of referenced app items
};
    podio.ItemService.UpdateItem(employee);

How to set your fields can be found here How to update fields