# Bubble api with constraints

**URL:** <https://forum.bubble.io/t/bubble-api-with-constraints/118336>\
**Category:** APIs\
**Created:** [October 28, 2020, 4:54pm UTC](https://forum.bubble.io/t/bubble-api-with-constraints/118336 "2020-10-28T16:54:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eraldolattari](https://avatars.discourse-cdn.com/v4/letter/e/35a633/32.png) [@eraldolattari](https://forum.bubble.io/u/eraldolattari)\
**Post date:** [October 28, 2020, 4:54pm UTC](https://forum.bubble.io/t/bubble-api-with-constraints/118336/1 "2020-10-28T16:54:48Z")

</div>

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 ?

 ![image](https://us1.discourse-cdn.com/bubble/original/3X/8/b/8b868f1d7d539e7686e06098ce88bea8010b1522.png)

---

<div class="post-metadata">

**Author:** ![jroberts](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@jroberts](https://forum.bubble.io/u/jroberts)\
**Post date:** [November 4, 2020, 9:07pm UTC](https://forum.bubble.io/t/bubble-api-with-constraints/118336/2 "2020-11-04T21:07:27Z")

</div>

@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"}]`

 ![Screen Shot 2020-11-04 at 4.06.33 PM](https://us1.discourse-cdn.com/bubble/original/3X/2/1/210f750c84765ec6e4ab39be4d5469de26eb7f79.png)

Hope that helps.

---

<div class="post-metadata">

**Author:** ![aviavia4u](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@aviavia4u](https://forum.bubble.io/u/aviavia4u)\
**Post date:** [November 17, 2020, 8:58pm UTC](https://forum.bubble.io/t/bubble-api-with-constraints/118336/3 "2020-11-17T20:58:53Z")

</div>

> [@jroberts](#):
>
> encoded JSON URL

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

---

<div class="post-metadata">

**Author:** ![boston85719](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/boston85719/32/77286_2.png) [@boston85719](https://forum.bubble.io/u/boston85719)\
**Post date:** [March 30, 2021, 6:32am UTC](https://forum.bubble.io/t/bubble-api-with-constraints/118336/4 "2021-03-30T06:32:00Z")

</div>

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](https://us1.discourse-cdn.com/bubble/original/3X/c/8/c812055c54767ee44f86a767ccef6002f042a908.png)

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