Data API 400 error when using constraints

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:

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

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

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.

    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

Search Constraints On Get Requests

1 Like