Skip to content

API call to populate form fields returns error #197

Answered by lovasoa
chris-bragg-sift asked this question in Q&A
Discussion options

You must be logged in to vote

Hello and welcome to sqlpage !

All sqlpage pseudo-functions are executed inside sqlpage and their results are passed to the database as text. The error message function json_each(text) does not exist comes from the fact that sqlpage.exec(...) is a value of type text and json_each expects a value of type json. You can cast values with

select ... from json_each( sqlpage.exec(...)::json );

If you want to reuse a value without creating an intermediate table, you can use variables in sqlpage with set:

set target_url = 'http://example.com/api/company/' || $name;
set json_results = sqlpage.exec('curl', $target_url);

select 'card' as component;
select key as title, value as description
from json…

Replies: 5 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@chris-bragg-sift
Comment options

Answer selected by chris-bragg-sift
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@lovasoa
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
functions Related to built-in sqlpage functions
2 participants