Bubble api with constraints

Hello everyone, I’m trying to retrieve some data from my table from postman. I entered a constraints, as per bubble documentation, however all the elements in my table are always returned to me, and not just those I requested. What am I doing wrong ?

1 Like

@eraldolattari, GET requests don’t use the body payload. You have to specify the constraints in an encoded JSON URL parameter.

Here’s an example shown in Curl and Paw (like Postman)

curl "https://app.myapp.com/api/1.1/obj/sw_request?cursor=0&limit=1000&constraints=%5B%7B%22key%22:%22Modified%20Date%22,%22constraint_type%22:%22greater%20than%22,%22value%22:%222020-09-01T00:00:00Z%22%7D,%7B%22key%22:%22Modified%20Date%22,%22constraint_type%22:%22less%20than%22,%22value%22:%222020-10-31T04:32:14.907Z%22%7D,%7B%22key%22:%22status%22,%22constraint_type%22:%22not%20equal%22,%22value%22:%22Waiting%22%7D%5D" \
 -H 'Authorization: Bearer blahblahblah' \
 -H 'Content-Type: application/json'

The source json constraints looks like this before URL encoding:
[{"key":"Modified Date","constraint_type":"greater than","value":"2020-09-01T00:00:00Z"},{"key":"Modified Date","constraint_type":"less than","value":"2020-10-31T04:32:14.907Z"},{"key":"status","constraint_type":"not equal","value":"Waiting"}]

Hope that helps.

1 Like

Use:
const constraintsDecoded = encodeURIComponent(JSON.stringify(constraints));
Then on the URL: domain .com/x/y/?apikey=123&constraints=constraintsDecoded

1 Like

I am new to APIs and I’ve been scouring the forum for help on how to set up things…yesterday spent some time with another user going over some of those issues, one being search constraints.

We attempted to use the URL encoded method and it just wasn’t working for us…I believe we may have not utilized the correct formatting since I copied your source json and it works now.

One question about it

  1. How can it be dynamic? I’d like to be able to use the constraints in a dynamic way to allow users to filter the API results.

During my session with another user, we did actually get the constraints to be in the body parameters, which does allow for a dynamic expression in the GET request from the repeating group datasource.

[ { "key": "country", "constraint_type": "contains", "value": "India" }]

Screen Shot 2021-03-30 at 1.29.41 PM

At this stage in my exploration I am just trying to get more familiar with all the various ways to set up API calls.