Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
DiegoF
Creator
Creator

Looping REST APIs

Hello qlik professionals,

I have a for each loop that takes some parameters of numbers in some pre existing dimensions that loops through possible values for a REST API, that I alter their values each round with variables:

For vAnio = 2023 To Year(Today())

FOR vMes = 1 TO 9// Month(Today())
FOR EACH vProvinciaEstacion IN FieldValueList('PROVINCIA_ESTACION')    

                LET vURL = '"https://www.juntadeandalucia.es/agriculturaypesca/ifapa/riaws/datosmensuales/' 
                & Text(vProvinciaEstacion) &'/' & $(vAnio) &'/'& $(vMes)&'"';
                
                
RestConnectorMasterTable:
SQL 
SELECT 
"anyo",
"mes",
"numDias",
"tempMedia",
"tempMax",
"diaHorMinTempMax",
"tempMin",
"diaHorMinTempMin",
"humedadMedia",
"humedadMax",
"diahorMinHumMax",
"humedadMin",
"diahorMinHumMin",
"velViento",
"dirViento",
"velVientoMax",
"diahorMinVelMax",
"dirVientoVelMax",
"precipitacion",
"radiacion",
"bateria",
"fechaUtlMod"
                    
FROM JSON (wrap on) "root"
                 WITH CONNECTION ( URL $(vURL));
NEXT vProvinciaEstacion
    
	NEXT vMes
Next vAnio
The loop works well, or at least most of the times the results I see are correct, haven´t gone through all of them, but on the ouptut, it tells me there are a lot of errors, so I don´t know if it´s exactly going throught everything ok or not.
The thing is, the errors that are telling me, are no errors, for example, it says this combination cannot be found (404):
DiegoF_0-1698665988154.png

 

But that´s not true, this API call exists, if you search it, it will return the array I´m looking for, and it actually adds a returned line in my table: 

https://www.juntadeandalucia.es/agriculturaypesca/ifapa/riaws/datosmensuales/18/11/2023/1

Sometimes when I have it programmed so it runs every x days, doesn´t work well and I don´t get the info that day, whats the problem and how can I fix it?

All help is much appreciated,

Thank you!

 
Labels (6)
4 Replies
ajaykakkar93
Specialist III
Specialist III

Hi,
the above works for me, as in your case it might be because of Set & LET may be use he below code hope it helps you

For vAnio = 2023 To Year(Today())

For vMes  = 1 To 9

set urlParam = $(vAnio)&'/'&$(vMes);

  trace urlParam: $(urlParam);
  
  /* use SET instead of LET*/
  SET vURL = '"https://www.juntadeandalucia.es/agriculturaypesca/ifapa/riaws/datosmensuales/18/11/'& $(urlParam)&'"';

 
  trace vURL: $(vURL);


  
LIB CONNECT TO 'REST_jsonplaceholder';

RestConnectorMasterTable:
SQL SELECT 
	"anyo",
	"mes",
	"numDias",
	"tempMedia",
	"tempMax",
	"diaHorMinTempMax",
	"tempMin",
	"diaHorMinTempMin",
	"humedadMedia",
	"humedadMax",
	"diahorMinHumMax",
	"humedadMin",
	"diahorMinHumMin",
	"velViento",
	"dirViento",
	"velVientoMax",
	"diahorMinVelMax",
	"dirVientoVelMax",
	"precipitacion",
	"radiacion",
	"bateria",
	"fechaUtlMod"
FROM JSON (wrap on) "root"
  WITH CONNECTION (URL $(vURL));

[root]:
LOAD	[anyo],
	[mes],
	[numDias],
	[tempMedia],
	[tempMax],
	[diaHorMinTempMax],
	[tempMin],
	[diaHorMinTempMin],
	[humedadMedia],
	[humedadMax],
	[diahorMinHumMax],
	[humedadMin],
	[diahorMinHumMin],
	[velViento],
	[dirViento],
	[velVientoMax],
	[diahorMinVelMax],
	[dirVientoVelMax],
	[precipitacion],
	[radiacion],
	[bateria],
	[fechaUtlMod]
RESIDENT RestConnectorMasterTable;


DROP TABLE RestConnectorMasterTable;




NEXT vMes ;
NEXT vAnio ;



exit Script;

 

Please mark the correct replies as Solution. Regards, ARK
Profile| GitHub|YouTube|Extension|Mashup|Qlik API|Qlik NPrinting

DiegoF
Creator
Creator
Author

It doesn´t work with Set for me, dw I already figured it out

ajaykakkar93
Specialist III
Specialist III

I am attaching the app which is loaded for 2022 

Connection settings (please allow with connection option)

ajaykakkar93_0-1699416198340.png

App is attached with the same code 

 

Please mark the correct replies as Solution. Regards, ARK
Profile| GitHub|YouTube|Extension|Mashup|Qlik API|Qlik NPrinting

marksouzacosta
Partner - Specialist
Partner - Specialist

As an addition to this topic, I'm excited to share my latest tutorial on integrating Asana with Qlik Cloud using REST APIs!

In this step-by-step guide, you'll learn:
- How to use Asana REST APIs with Postman
- Creating REST Data Connections in Qlik Cloud
- Extracting data from Asana and saving as Parquet files
- Enhancing connections with custom parameters and pagination

Check out the full video on YouTube:
Integrate Asana with Qlik Cloud Using REST APIs: A Step-by-Step Guide
https://youtu.be/lFwar30BNkQ?si=UZoM_x9L5amdJSnf

Regards,

Mark Costa

Read more at Data Voyagers - datavoyagers.net