更新项目

时间:2019-06-01 16:38:44

标签: .net podio

我正在使用dotnet Podio API来获取和更新项目。每当我尝试使用ItemService.UpdateItem()函数更新具有应用程序关系的项目时,都会出现以下异常:

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

即使没有访问或更改应用关系,也会发生这种情况。

似乎在更新带有关系的项目时,该关系必须是引用ID(或某个整数),并且不能是被引用的对象本身,尽管在获取项目时会提供该对象。将关系设置为整数id无济于事,并且会产生相同的异常。

如果项目模板具有应用程序关系,但单个项目的关系为空,则不会引发异常。

我尝试在Podio中重新创建应用程序,以查看应用程序的结构是否存在一些固有的缺陷。

在更新项目之前,我尝试将项目的关系更新为它已经引用的关系的ID。

我尝试使用ItemService.UpdateItemFieldValues()函数。在这里,不会引发异常,但是项目也不会更新(如何在此函数中指定字段?)。

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 个答案:

答案 0 :(得分:0)

您不能直接使用从过滤器项获得的项对象更新回podio。您需要创建一个新项目来做到这一点。

例如:

    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 update fields