# Data API 400 error when using constraints

**URL:** <https://forum.bubble.io/t/data-api-400-error-when-using-constraints/130640>\
**Category:** APIs\
**Created:** [January 15, 2021, 3:15am UTC](https://forum.bubble.io/t/data-api-400-error-when-using-constraints/130640 "2021-01-15T03:15:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hershagarwal](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hershagarwal](https://forum.bubble.io/u/hershagarwal)\
**Post date:** [January 15, 2021, 3:15am UTC](https://forum.bubble.io/t/data-api-400-error-when-using-constraints/130640/1 "2021-01-15T03:15:03Z")

</div>

Would love to get advice on what I may be doing wrong here. I’m attempting to retrieve a list of things using the Data API. I’m successfully able to retrieve the list without any constraints, but as soon as I add the constraint, I receive a 400 error.

I know that the data I’m filtering for exists, and don’t believe there is any error in my constraints. Therefore, I’m guessing it’s an issue with how I am encoding it, but all of my attempts have failed so far. I’ve tried the following:

- Different parameters, many of which shouldn’t filter anything out
- Different capitalization of the key
- Using the verbatim URL encode snippet from the bubble manual (swapped in my key name and constraint)

Any idea what I may be doing wrong?

**My code for the constraints is here:**

```auto
constraints = [
            {
                "key": "Hours",
                "constraint_type": "is_not_empty",
            }
        ]
        params = {'cursor': cursor, 'api_token': API_KEY, 'constraints': constraints}
        url = base_url + urllib.parse.urlencode(params) 
```

**Printed URL**

```auto
https://websitename.bubbleapps.io/version-test/api/1.1/obj/employeetiming?cursor=0&api_token=token&constraints=%5B%7B%27key%27%3A+%27hours%27%2C+%27constraint_type%27%3A+%27is_not_empty%27%7D%5D
```

---

<div class="post-metadata">

**Author:** ![hershagarwal](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hershagarwal](https://forum.bubble.io/u/hershagarwal)\
**Post date:** [January 15, 2021, 3:34am UTC](https://forum.bubble.io/t/data-api-400-error-when-using-constraints/130640/2 "2021-01-15T03:34:36Z")

</div>

Wow, of course I finally stumbled across the answer immediately after posting this! Figured I would leave this up for anyone struggling with it, or if any Bubble vets can provide some context as to the technical details of what I was doing wrong.

Instead of using urllib to encode the constraints, it looks like they’re supposed to be directly concatenated to the url.

```auto
    url = base_url + urllib.parse.urlencode(params) +'&constraints=' + json.dumps(constraints)

[obj/employeetiming?cursor=0&api_token=726c66a77cf14f145374c0cbf335b625&constraints=[{"key":]
```

Many thanks to simon7! I somehow didn’t find these the first 10 searches I did.

[GET API call from 3rd party to bubble](http://forum.bubble.io/t/get-api-call-from-3rd-party-to-bubble/79913)

[Search Constraints On Get Requests](http://forum.bubble.io/t/search-constraints-on-get-requests/83899)
