ObjFieldApi will run an api and create a dropdown based on the result, however it
is more of an example template to display how to use API integration in your own
form fields.
FieldType in def_formfield is where you put the url:
API(https://pokeapi.co/api/v2/pokemon?limit=10)
Fieldoptions takes a number of parameters in the format of a json object:
e.g.1
{
"iteration_start": 2,
"indexes": ["coord", "lon"],
"ttl": 30000,
"db_type": "SQL",
"params": {"appid": "559f0afbda97185450c21a046341a819"},
"headers": {},
"callback": "Y"
}
e.g.2
{
"iteration_start": 1,
"indexes": ["results", "name"],
"ttl": 30000,
"db_type": "MONGO",
"callback": "Y"
}
iteration_start tells the code at what point an array starts.
Indexes are the ordered flow of the dictionary indexes.
for example, e.g.2 has the following output:
{
"count": 1302,
"next": "https://pokeapi.co/api/v2/pokemon?offset=3&limit=3",
"previous": null,
"results": [
{
"name": "bulbasaur",
"url": "https://pokeapi.co/api/v2/pokemon/1/"
},
{
"name": "ivysaur",
"url": "https://pokeapi.co/api/v2/pokemon/2/"
},
{
"name": "venusaur",
"url": "https://pokeapi.co/api/v2/pokemon/3/"
}
]
}
iteration_start = 1, tells the code to look at the first index value,
then start iterating. In this example, that would take the code inside
the "results" array, and then it would iterate through all of the
names in that array.
ttl decides how long a value is cached before you need to call the api
again. I recommend caching using "db_type": "MONGO" for higher speeds.
Although setting the variable: "callback":"Y" is not necessary for all fields, it
is convention to use that variable to make it apparent that you are using an api
call.
cythonize -3 -a -i ObjFieldApi.py
Compiling /home/axion/projects/axion/factory.field/ObjFieldApi.py because it changed..[1/1] Cythonizing /home/axion/projects/axion/factory.field/ObjFieldApi.py
Updated : 2025-06-08