Jump to content


Photo

Search parameters in API with C#

C# API

  • Please log in to reply
2 replies to this topic

#1 Wiggert

Wiggert

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 15 May 2014 - 02:01 PM

Hi All,

 

I am trying to perform a search for users query trough the Zurmo API.

However i can't get the search query parameters to work. 

 

I'm developing in C# and this is how it looks like

 

            RestClient client = new RestClient(zURL + "index.php/users/user/api/search/filter/");
            RestRequest request = new RestRequest(Method.POST);


            request.AddHeader("Accept", "application/json");
            request.AddHeader("ZURMO_API_REQUEST_TYPE","REST");
            request.AddHeader("ZURMO_SESSION_ID",AuthSettings.data.sessionId);
            request.AddHeader("ZURMO_TOKEN", AuthSettings.data.token);
            request.RequestFormat = DataFormat.Json;


            string searchquery = @"{ ""data"": {     ""search"": {         ""modelClassName"": ""User"",         ""searchAttributeData"": {             ""clauses"": [                 {                     ""attributeName"": ""username"",                     ""operatorType"": ""startsWith"",                     ""value"": ""wi""                 },                 {                     ""attributeName"": ""username"",                     ""operatorType"": ""startsWith"",                     ""value"": ""wi""                 }             ],             ""structure"": ""1 OR 2""         }     },     ""pagination"": {         ""page"": ""1"",         ""pageSize"": ""100""     },     ""sort"": ""username asc"" } }";

            request.AddBody(searchquery);

All i'm getting back is invalid index: data

 

Who knows?

 

Thanks in advance,

 

Wiggert

 


#2 bgege

bgege

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 27 December 2014 - 07:07 AM

Hi, 

 

Here is an example for an URL encoded search filter. This searches for owner id 12 and lastName Jim. 

 

http://INSERT_ZURMO_...h[owner][id]=12

 

I'm about as far from php as it gets, so the trick for me was to find a homepage which executes php code online, put the Zurmo example codes in there, and press execute to find out what kind of URL does it spit out. 

 

Hope it helps!

 

Gergely



#3 murrayl

murrayl

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 02 January 2015 - 07:31 PM

@Wiggert - you got further than me with c# ! care to share your authentication code as I cannot seem to get in on the api using RestSharp.  Fiddler seems to be showing the right request though...There's nothing wierd like a prehashed password or anything?







Also tagged with one or more of these keywords: C#, API

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users