【问题标题】:App relation must be an integer when updating item更新项目时应用关系必须是整数
【发布时间】:2019-06-01 16:38:44
【问题描述】:

我正在使用 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

【问题讨论】:

    标签: .net podio


    【解决方案1】:

    您不能直接使用从过滤器项目中获得的项目对象来更新回播客。为此,您需要创建一个新项目。

    例如:

        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

    【讨论】:

    • 谢谢你。我还找到了一种解决方法,我从底层 JArray 中删除关系并在修改之前将其重置。不过,您的解决方案要干净得多。我是否需要将所有字段再次分配给新创建的项目?
    • 不,只需要声明需要更新的字段。新项目中指定的字段将被更新,其他字段将保持不变。如果要清空某个字段,可以声明该字段,忽略赋值部分。
    猜你喜欢
    • 2013-09-05
    • 2019-01-02
    • 2011-02-17
    • 2014-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-23
    • 1970-01-01
    相关资源
    最近更新 更多