Skip to content

Using ItemService.FilterItems() with non-string fields #15

@Andarki

Description

@Andarki

When calling ItemService.FilterItems() for string fields this works:

Dictionary<string, string> filters = new Dictionary<string, string>() { { "title", "Support" } };                
PodioCollection<Item> items = client.ItemService.FilterItems(MyApp.AppId.Value, 100, 0, filters);

When attempting to do the same on the enumerated field 'status':

Dictionary<string, string> filters = new Dictionary<string, string>() { { "status", "Active" } };

The error Invalid value "Active" (string): must be array is thrown by the API.
I have been experimenting using PodioRestHelper.JSONRequest (as done internally by FilterItems) and got the following code to work (2 is the Enumerator id for 'Active'). Note that Podio API insists that status must be an array.

Dictionary<string, object> filter = new Dictionary<string, object>() { 
{ "status", new object[] { 2 } }
};

var requestData = new {filters = filter};

var request = PodioRestHelper.JSONRequest<PodioCollection<Item>>(Constants.PODIOAPI_BASEURL + "/item/app/" + MyApp.AppId.Value + "/filter/", client.AuthInfo.AccessToken, requestData, PodioRestHelper.RequestMethod.POST).Data;

I suggest that ItemService.FilterItems() should accept a Dictionary<string, object> to enable this use case. Furthermore, the method should have a comment on how to invoke it for different datatypes (string, enum, int etc.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions