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

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
pedrohenriqueperna
Creator III
Creator III

Help with SOAP request: bad characters and looping values

Hi!

I'm very noob into the subject, but I'm very persistent and managed to succeed a connection to a government API for addresses in Brazil. It's a SOAP API that will return the complete address of a location based on a "zip code" as a parameter key.

So far so good, but now I got 2 problems:

1. The return is giving me "?" chars for characters with accentuation (I assume it's something related to unicode settings, etc.)

therealdees_1-1705606912318.png

 

2. I have no idea how to pass the different keys I'm trying to check, since the request body already carries a key.

 

The following link has helped me to structure the connection and parameters:

https://community.qlik.com/t5/Official-Support-Articles/How-to-call-a-SOAP-service-with-the-Qlik-Sen...

 

The API URL is:

https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl

 

The request body I'm using:

<?xml version="1.0" encoding="utf-8"?>
<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">
<x:Header/>
<x:Body>
<cli:consultaCEP>
<cep>47850011</cep>
</cli:consultaCEP>
</x:Body>
</x:Envelope>

 

The query headers:

Name: Content-Type

Value: text/xml

 

therealdees_2-1705606942350.png

 

therealdees_3-1705606949608.png

 

 

How can I fix the characters to show the real letters with accentuation, or at least replace them for the same letters without accentuation?

 

How can I pass different values to the body request so I can add this to a script routine?

 

It's a public API so it should work for anyone. You could try using the following (random) zip codes to test (consider I'd have a list of values in a table that I must loop and form a new table or update the previous):

13345731
03383010
86055774
71705008
06803000
47850011
85903220

 

 

1 Solution

Accepted Solutions
pedrohenriqueperna
Creator III
Creator III
Author

After a deep research I managed to do it using the WITH CONNECTING (you must turn it on in the connection settings)

If it helps anyone in the future, this is the final code:

 

LIB CONNECT TO 'PP:API_Correios';

Temp:
LOAD * Inline [cep
05590090
06803000
02352000
06820330
06707100
];

LET vRowCount = NoOfRows('Temp');


For i = 0 to '$(vRowCount)' - 1

LET vCEP = Peek('cep', $(i), 'Temp');

SET vBody =
<?xml version=""1.0"" encoding=""utf-8""?>
<x:Envelope xmlns:x=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:cli=""http://cliente.bean.master.sigep.bsb.correios.com.br/"">
<x:Header/>
<x:Body>
<cli:consultaCEP>
<cep>$(vCEP)</cep>
</cli:consultaCEP>
</x:Body>
</x:Envelope>;

RestConnectorMasterTable:
SQL SELECT
"attr:soap" AS "soap",
"__KEY_Envelope",
(SELECT
"__KEY_Body",
"__FK_Body",
(SELECT
"attr:ns2" AS "ns2",
"__KEY_consultaCEPResponse",
"__FK_consultaCEPResponse",
(SELECT
"bairro",
"cep",
"cidade",
"complemento2",
"end",
"uf",
"__FK_return"
FROM "return" FK "__FK_return")
FROM "consultaCEPResponse" PK "__KEY_consultaCEPResponse" FK "__FK_consultaCEPResponse")
FROM "Body" PK "__KEY_Body" FK "__FK_Body")
FROM XML "Envelope" PK "__KEY_Envelope"
With Connection(
BODY "$(vBody)");

Next i;

Return:
LOAD
cep
,end as rua
,bairro
,cidade
,complemento2 as complemento
,uf
Resident RestConnectorMasterTable
Where Not IsNull([__FK_return]);

Drop Tables RestConnectorMasterTable, Temp;

View solution in original post

2 Replies
pedrohenriqueperna
Creator III
Creator III
Author

Update:

Changing the Query header value fixed the accentuation issue

from: text/xml

to: text/xml;charset=UTF-8

 

Now I need to learn how pass keys to the body 😞

pedrohenriqueperna
Creator III
Creator III
Author

After a deep research I managed to do it using the WITH CONNECTING (you must turn it on in the connection settings)

If it helps anyone in the future, this is the final code:

 

LIB CONNECT TO 'PP:API_Correios';

Temp:
LOAD * Inline [cep
05590090
06803000
02352000
06820330
06707100
];

LET vRowCount = NoOfRows('Temp');


For i = 0 to '$(vRowCount)' - 1

LET vCEP = Peek('cep', $(i), 'Temp');

SET vBody =
<?xml version=""1.0"" encoding=""utf-8""?>
<x:Envelope xmlns:x=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:cli=""http://cliente.bean.master.sigep.bsb.correios.com.br/"">
<x:Header/>
<x:Body>
<cli:consultaCEP>
<cep>$(vCEP)</cep>
</cli:consultaCEP>
</x:Body>
</x:Envelope>;

RestConnectorMasterTable:
SQL SELECT
"attr:soap" AS "soap",
"__KEY_Envelope",
(SELECT
"__KEY_Body",
"__FK_Body",
(SELECT
"attr:ns2" AS "ns2",
"__KEY_consultaCEPResponse",
"__FK_consultaCEPResponse",
(SELECT
"bairro",
"cep",
"cidade",
"complemento2",
"end",
"uf",
"__FK_return"
FROM "return" FK "__FK_return")
FROM "consultaCEPResponse" PK "__KEY_consultaCEPResponse" FK "__FK_consultaCEPResponse")
FROM "Body" PK "__KEY_Body" FK "__FK_Body")
FROM XML "Envelope" PK "__KEY_Envelope"
With Connection(
BODY "$(vBody)");

Next i;

Return:
LOAD
cep
,end as rua
,bairro
,cidade
,complemento2 as complemento
,uf
Resident RestConnectorMasterTable
Where Not IsNull([__FK_return]);

Drop Tables RestConnectorMasterTable, Temp;