Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
mumimgirl
Contributor
Contributor

Rest Connector

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?

 

Labels (3)
1 Solution

Accepted Solutions
rafaelencinas
Partner - Creator II
Partner - Creator II

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!

 

Senior Qlik Architect
Cobra, Stallone, "You're a problem and I'm the solution"

View solution in original post

2 Replies
rafaelencinas
Partner - Creator II
Partner - Creator II

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!

 

Senior Qlik Architect
Cobra, Stallone, "You're a problem and I'm the solution"
mumimgirl
Contributor
Contributor
Author

Thank u !!!!!