Post

3 followers Follow
0
Avatar

.NET FilterItems

Hi again -

I'm making progress with my science project and have run up against the wall.  I'm attepting to fetch items in my app based on a Category field where the value is set to 'Open'.  I know I'm doing something wrong in the filter - it appears that it's honoring the field id since if I pass 'null' as the second member in the pair I successfully retrieve items with no value in that field.  However if I pass the the value I'm looking for is get an error. I have also tried passing the optionId (1 or 2) with the same result.

            Dictionary<string, string> filter = new Dictionary<string, string>();

            filter.Add("23157745", "Open"); // Invalid value u'Open': Must not be basestring (at values)

            //filter.Add("23157745", null); // works

var client = Podio.API.Client.ConnectAsApp(podioClientId, podioClientSecret, podioAppId.ToString(), podioAppToken, uri);

            int limit = 100; // Max allowed is 500 items per request;

            int offset = 0;

            var items = client.ItemService.FilterItems(podioAppId, limit, offset, filter);

Thoughts?

Rich Stoldt Answered

Please sign in to leave a comment.

17 comments

0
Avatar

Hi Rich,

I believe you should be passing the option id as an array instead of a single value.

/Andreas

Andreas Haugstrup Pedersen 0 votes
Comment actions Permalink
0
Avatar

I only mentioned optionId in the context of providing a '1' or '2' as the value in the filter as opposed to the text values 'Open' or 'Closed'.  I have already figured out how to update the Category field.  I'm just trying to find out if there's something I'm missing in creating the filter.

Rich Stoldt 0 votes
Comment actions Permalink
0
Avatar

You should pass in an array of option ids to filter by. Something like this (untested):

filter.Add("23157745", [1]);

Casper Fabricius 0 votes
Comment actions Permalink
0
Avatar

Hmmm ... looking at the FilterItems method, it looks like it's taking a Dictionary object of <string,string> as the filter parameter.  Am I reading this wrong?

        public PodioCollection<Item> FilterItems(int appId, int limit, int offset, Dictionary<string, string> filters = null, bool? remembered = null, string sortBy = null, bool? sortDesc = null)

So filter.Add("123123123", "1") should work, no?

Rich Stoldt 0 votes
Comment actions Permalink
0
Avatar

_response.PodioError.error_description: Invalid value u'1': Must not be basestring (at values)

(new System.Collections.Generic.Mscorlib_DictionaryDebugView<string,string>(_response.RequestData)).Items[0].Key: json

(new System.Collections.Generic.Mscorlib_DictionaryDebugView<string,string>(_response.RequestData)).Items[0].Value: {"filters":{"20912595":"1"},"sort_by":null,"sort_desc":null,"limit":100,"offset":0,"remember":null}

Rich Stoldt 0 votes
Comment actions Permalink
0
Avatar

"Must not be basestring" means that "1" should not be passed as a string. Try it as an plain int, simply 1, or as an array as I suggested [1].

Casper Fabricius 0 votes
Comment actions Permalink
0
Avatar

Thanks.  I tried you suggestion but no luck.  Since the FilterItems method accepts a Dictionary <string , string> object for the filter the code won't even compile.

1>V:\VS tools\Contour\Sample\ContourUtil\util.cs(186,25,186,90): error CS1502: The best overloaded method match for 'Podio.API.Services.ItemService.FilterItems(int, int, int, System.Collections.Generic.Dictionary<string,string>, bool?, string, bool?)' has some invalid arguments

1>V:\VS tools\Contour\Sample\ContourUtil\util.cs(186,83,186,89): error CS1503: Argument 4: cannot convert from 'System.Collections.Generic.Dictionary<string,int>' to 'System.Collections.Generic.Dictionary<string,string>'

Rich Stoldt 0 votes
Comment actions Permalink
0
Avatar

Probably a bug in the .NET client then. Should probably have been Dictionary<string, object>. The .NET client is user contributed, and we don't currently have any resources to bugfix and expand the client. We will happily accept pull requests.

Casper Fabricius 0 votes
Comment actions Permalink
0
Avatar

Indeed this is the issue!  Attaching modified ItemService.cs - changed the request variable to IDictionary<string, object>.  Modified the code to pass same - works great now.

            var client = Client.ConnectAsApp(podioClientId, podioClientSecret, podioAppId.ToString(), podioAppToken, uri);

            int limit = 100; // Max allowed is 500 items per request;

            int offset = 0;

            int status_new = 1; // Status = New

            int status_submitted = 2; // Status = Submitted

            string fld_status = "23326810";

            Dictionary<string, object> filter = new Dictionary<string, object>();

            int[] parm = new int[1];

            parm[0] = status_submitted;

            filter.Add(fld_status, parm);

            var items = client.ItemService.FilterItems(podioAppId, limit, offset, filter);

Much appreciated!  Hope this helps.

Rich Stoldt 0 votes
Comment actions Permalink
0
Avatar

Hi Rich, Casper,

This modification seems to be exactly what I need to filter my request.

But as I use SharpDevelop and not Visual Studio, i can't import casper's sources from GitHub.

Can you publish an updated .dll with this new ItemService.cs ?

Many thanks.

Aurélien PETIT 0 votes
Comment actions Permalink
0
Avatar

You should be able to just download the source from GitHub as a ZIP or TARBALL.  I don't know if they've incorporated my changes into their baseline so you'll need to look.  You may need do diff their ItemService.cs with my version.

Rich Stoldt 0 votes
Comment actions Permalink
0
Avatar

Can I get you to do a pull-request on GitHub with the bugfix, then I'll happily merge it into the codebase.

Kasper Andersen 0 votes
Comment actions Permalink
0
Avatar

Done.  Sorry but it took me this long - I had to figure out the whole GitHub thing.  At least I avoided posting another n00b question :)

Rich Stoldt 0 votes
Comment actions Permalink
0
Avatar

Thank you for your contibution! - I have made a comment regarding your pull-request on GitHub, could I ask you to revise it?

Kasper Andersen 0 votes
Comment actions Permalink
0
Avatar

How may I create a filter that returns items where a simple text field is empty? The API errors with all attempts at guessing so far: 1) null, 2) "", 3) String.Empty

And while we're at it, how might I filter using OR, NOT, RegEx, substring, etc.?

Steve Dieckbrader 0 votes
Comment actions Permalink
0
Avatar

Hi Steve,

The Filter Items method only makes it possible to filter for empty values on the following field types: Contact, App Reference, Category and Question. It's not possible to search or filter for empty values in any other field type.

For more advanced search you can take a look at our search interface at: https://developers.podio.com/doc/search -- it will get you some of the way.

/Andreas

Andreas Haugstrup Pedersen 0 votes
Comment actions Permalink