Podio API - C# - 无法使用appitemid

时间:2018-04-19 01:05:36

标签: podio

尝试在应用程序下获取工作区的项目列表。能够检索每个工作区下的工作区列表和应用程序。但无法检索空间/应用程序下的项目。尝试使用' FilterItems'和' GetItemByAppItemId',但itemid结果为null。关于如何使这个工作的任何建议?

这是代码,

public DataTable GetDeliverables()
    {

        string spaceName = string.Empty;
        var spaceResult = podio.SpaceService.GetOrganizationSpaces(orgID);          
        try
        {              
            foreach (var space in spaceResult)
            {
                var appResult = podio.ApplicationService.GetAppsBySpace(space.SpaceId);
                spaceName = space.Name;

                foreach (var appItem in appResult)
                {
                    if (appItem.Config.ItemName != null)
                    {
                        if (appItem.Config.ItemName.Contains("Deliverable"))
                        {                             
                          var itemResult = podio.ItemService.GetAppValues(appItem.AppId);
                          if (itemResult != null)
                            {
                                foreach (var fields in itemResult.Fields)
                                {
                                    if (fields.Values != null && fields.Values.ToString() != "[]")
                                    {
                                        var values = fields.Values.ToString();
                                        if (values.ToString().Contains("\"title\": \"Marketing\""))
                                        {
                                            /*Get Value*/
                                            JArray jsonArrayForValues = JArray.Parse(values);
                                            var jsonValue = JObject.Parse(jsonArrayForValues[0].ToString());
                                            JObject objValue = JObject.Parse(jsonValue.ToString());
                                            var item = jsonValue.SelectToken("items");
                                            DataTable dt = (DataTable)JsonConvert.DeserializeObject(item.ToString(), (typeof(DataTable)));
                                            DataTable dttable = new DataTable();
                                            dttable = dt.AsEnumerable()
                                                         .Where(r => r.Field<string>("Title") == "Marketing")
                                                         .CopyToDataTable();

                                            object app_item_id = dttable.Rows[0]["app_item_id"];
                                            object item_id = dttable.Rows[0]["item_id"];

                                            if (Convert.ToInt32(app_item_id) != 0)
                                            {
                                                var dataForAppItem = podio.ItemService.GetItemByAppItemId(appItem.AppId, Convert.ToInt32(app_item_id));
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }                      
                }
            }
 DataTable dtnewtable = new DataTable(); 
 return dtnewtable;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

由于

1 个答案:

答案 0 :(得分:0)

请尝试以下代码,确保您正在处理速率限制。还要确保您的podio客户端对其中的每个操作都有足够的权限。

public string ExtractUserdata(Podio podioClient)
 {
    var spaces = _podioOperationService.GetSpaces(podioClient, org.OrgId);
    if (spaces?.Any() == true)
    {
        foreach (var space in spaces)
        {        
            var apps = _podioOperationService.GetApps(podioClient, space.SpaceId);
            if (apps?.Any() == true)
            {
                foreach (var app in apps)
                {      
                   var items = FilterAllPodioItems(app.AppId, podioClient);
                  // Do your operations here

                }
            }
        }
    }     
    return "Success";
}

public List<Item> FilterAllPodioItems(int appid, Podio podioClient)
{
    var allFilterItems = new List<Item>();
    try
    {
        int offset = 0;
        int limit = 500;
        bool continueOperation = true;

        do
        {
            var filteredItems = podioClient.ItemService.FilterItems(appId: appid, limit: limit, offset: offset);
            if (filteredItems.Items?.Any() == true)
            {
                allFilterItems.AddRange(filteredItems.Items);
            }
            offset = offset + limit;
            if (filteredItems == null || filteredItems.Filtered <= offset)
            {
                continueOperation = false;
            }
        } while (continueOperation);

    }
    catch (Exception)
    {
        throw;
    }

    return allFilterItems;
}