Hi! I am currently trying the bubble Data API and doing a get request to get data from the database using the python requests library, refer to: https://manual.bubble.io/core-resources/api/the-bubble-api/the-data-api/data-api-requests#get-a-list-of-things
Here is the source code for the test I am doing:
from pprint import pprint
from urllib.parse import quote
import requests
import json
TypeName = "User"
Constraint = json.dumps([
{
"sort_field":"email",
"constraint type":"text contains",
"Value":"hotmail",
"exclude_remaining":True,
},
])
url = f"https://purposeful-97926.bubbleapps.io/version-test/api/1.1/obj/{TypeName}?constraints={Constraint}"
print(url)
request = requests.get(
url=url,
headers={
"Authorization":"Bearer <API_KEY>",
"Content-type":"application/json",
},
)
query = request.json()
try:
print(tuple(i["authentication"]["email"]["email"] for i in query["response"]["results"]))
print()
except:
pprint(query)
I am also trying to do it a slightly different way that also did not work:
from pprint import pprint
from urllib.parse import quote
import requests
import json
TypeName = "User"
Constraint = quote(json.dumps([
{
"key":"email",
"constraint type":"text contains",
"Value":"hotmail",
"exclude_remaining":True,
},
]))
url = f"https://purposeful-97926.bubbleapps.io/version-test/api/1.1/obj/{TypeName}?constraints={Constraint}"
print(url)
request = requests.get(
url=url,
headers={
"Authorization":<API_KEY>,
"Content-type":"application/json",
},
)
query = request.json()
try:
print(tuple(i["authentication"]["email"]["email"] for i in query["response"]["results"]))
print()
except:
pprint(query)
the result is:
{'body': {'message': 'Constraint type not found undefined for field email and '
'type User',
'status': 'NOT_FOUND'},
'statusCode': 404}
have you tried constraint_type
with underscore instead of space?
Yes, I did actually, but I see no difference.
meaning you get the same error or that you still get an error but is different?
Maybe you can share the computed url to check what’s the final parameter sent with the request.
I get the same error as when I do it without the underscore, so I prefer to not use the underscore as that is the official documentation method
I cannot access the field ‘email’ in any context unless creating a user(using the bubble API) seems to be the problem rn.
The official documentation uses the underscore. From the error it looks like the constraint type is not correctly passed in the request and results undefined for bubble’s server, so maybe you need to check the final url sent to the server
Error Message with Underscore:
{'body': {'message': 'Constraint type not found text contains for field email '
'and type User',
'status': 'NOT_FOUND'},
'statusCode': 404}
error Message without underscore:
{'body': {'message': 'Constraint type not found undefined for field email and '
'type User',
'status': 'NOT_FOUND'},
'statusCode': 404}
Proof:
If the server is not getting the constraint type it’s probably because a spelling error or an encoding problem of the final url or malformed constraint object.
Things you can do to debug:
- the classic check for privacy rules
- send the request from a different tool
- send a similar request, but for a difderent text field
I will look into that! I will update soon.
Thanks for the help!
So, I have tried with other data types and they work well, somehow the bubble built in “email” variable is not allowed to be searched with or otherwise modified.
the constraint type param should be “constraint_type”. so the documentation was wrong, but the documentation example was correct