Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello!
How to change request body in JSON script on WITH CONNECTION to read any pages? I'm using method POST with request body.
My actual scenario is: on my string I can only pull twenty registries per page but I need to increment a loop to get all the others registries.
Thanks.
Hello Cláudio
I'm having the exact same problem. Did you have any luck with that ? If so, could you share the solution ?
Thanks
Hello, Gleybson
I solved ... follow instructions below:
1. Create a REST connection.
2. Write the script below:
LIB CONNECT TO 'Categoria';
Config:
SQL SELECT
"total_de_paginas"
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION(Url "http://XXXXXX/categorias/");
Let total = Peek('total_de_paginas',0,'Config');
Let totalfetched = 0;
let vPagina = 1;
for startAt = 1 to total
let vRequestBody = '{"call":"ListarCategorias","app_key":"XXXXXXXX","app_secret":"XXXXXXXXXX","param":[{"pagina":"$(vPagina)","registros_por_pagina":100,"apenas_importado_api":"N"}]}';
let vRequestBody = replace(vRequestBody,'"', chr(34)&chr(34));
RestConnectorMasterTable:
SQL SELECT
"__KEY_root",
(SELECT
"codigo",
"conta_despesa",
"conta_inativa",
"conta_receita",
"definida_pelo_usuario",
"descricao",
"descricao_padrao",
"id_conta_contabil",
"nao_exibir",
"natureza",
"tag_conta_contabil",
"totalizadora",
"transferencia",
"__FK_categoria_cadastro"
FROM "categoria_cadastro" FK "__FK_categoria_cadastro")
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION(Url "http://XXXXXX/categorias/", BODY "$(vRequestBody)");
vPagina = vPagina + 1;
NEXT startAt;
Categorias:
LOAD
[codigo] AS [codigo],
[conta_despesa] AS [conta_despesa],
[conta_inativa] AS [conta_inativa],
[conta_receita] AS [conta_receita],
[definida_pelo_usuario] AS [definida_pelo_usuario],
[descricao] AS [descricao],
[descricao_padrao] AS [descricao_padrao],
[id_conta_contabil] AS [id_conta_contabil],
[nao_exibir] AS [nao_exibir],
[natureza] AS [natureza],
[tag_conta_contabil] AS [tag_conta_contabil],
[totalizadora] AS [totalizadora],
[transferencia] AS [transferencia],
[__FK_categoria_cadastro] AS [__KEY_root]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__FK_categoria_cadastro]);
DROP TABLE RestConnectorMasterTable;
Looks fine, but it doesn't seem to woirk in my case, despite various tweaking.
Basically , the POST call is answered properly with the original BODY set in the REST Connection form, but once I try to change the BODY using WITH CONNECTION() sufix, I've got this:
Connector error: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
Funny enough, it's a completely public API I am trying with, that doesn't even require user & pass or other authentification...
Asked Qlik for support