Jump to content

API URL With Filter Example


jwogrady

Recommended Posts

I'm using Python's request library to query the API.  The documentation doesn't show what a paramatized filtering url would look like.

For example,

https://source-docs.blesta.com/class-Services.html#_getList

The filter variable is supposed to be passed as an array.

 

#getList( integer $client_id = null, string $status = 'active', integer $page = 1, array $order_by = ['date_added' => 'DESC'], boolean $children = true, array $filters = []  )

Returns a list of services for the given client and status

 

Using python requests, that would be done like this....

def services_getAllByClient():
     data = request(
          'services/', 'getlist', blesta_format, params={'client_id': 741, 'filters': ['package_id', 112]}
     )
     print(data.url)

 

>>> app.services_getAllByClient()
https://[myblestainstall.com]/api/services/getlist.json?client_id=741&filters=package_id&filters=112

It's not filtering....   What would correct paramaratized files look like?

 

Link to comment
Share on other sites

  • 1 year later...

An example of an API URL with a filter would look like this:

 
arduino
https://api.example.com/items?category=books&price_min=10&price_max=50

In this example:

  • category=books filters items by category.
  • price_min=10 filters items with a price of at least 10.
  • price_max=50 filters items with a price no higher than 50.

Filters are typically added as query parameters in the URL after the ?.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...