Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I want to retriever data from APIs by constructing a request body similar to the one shown in the image. I need to make the start_date dynamic, so I want to replace its value with a variable (for example, to get data from the past 3 years.)
When I set start_date directly to a fixed value like 2024-01-01, everything works fine. However, when I try to use a variable like $(vStartDate), I get an error saying the start_date is in an invalid format.
How can I correctly use a variable for start_date without causing a format error?
Hi @mumimgirl ,
In your case, you have to set "with Connection" parameter in the Data Connection, because you can't use Variables in Data Connection editor, you must do it in the script.
For example:
Create a variable in the script
Let vBody = '{
""app_key"":""$(vAPP_KEY)"",
""app_secret"":""$(vAPP_SECRET)"",
""param"":[{""pagina"":1,""registros_por_pagina"":$(vRegistrosPorPagina),""apenas_importado_api"":""N""}]}';
In the end of code
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION(
BODY "$(vBody)"
);
Bye!
Hi @mumimgirl ,
In your case, you have to set "with Connection" parameter in the Data Connection, because you can't use Variables in Data Connection editor, you must do it in the script.
For example:
Create a variable in the script
Let vBody = '{
""app_key"":""$(vAPP_KEY)"",
""app_secret"":""$(vAPP_SECRET)"",
""param"":[{""pagina"":1,""registros_por_pagina"":$(vRegistrosPorPagina),""apenas_importado_api"":""N""}]}';
In the end of code
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION(
BODY "$(vBody)"
);
Bye!
Thank u !!!!!