Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.)
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:
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
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
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;
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 😞
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;