Sample code for 30+ languages & platforms
Lua

Cerved API Entity Contacts

See more Cerved Examples

The service returns the list of contacts of a Subject (legal entities) identified by "id_soggetto"

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local http = chilkat.Http.new()

-- Implements the following CURL command:

-- curl -X GET \
--   https://api.cerved.com/cervedApi/v1/entityProfile/contacts?id_soggetto=12345678 \
--   -H 'accept: application/json' \
--   -H 'apikey: ********************************'

-- Use the following online tool to generate HTTP code from a CURL command
-- Convert a cURL Command to HTTP Source Code

http:set_request_header("accept", "application/json")
http:set_request_header("apikey", "********************************")

local sbResponseBody = chilkat.StringBuilder.new()
local success = http:quick_get_sb("https://api.cerved.com/cervedApi/v1/entityProfile/contacts?id_soggetto=12345678", sbResponseBody)
if not success then
    print(http.last_error_text)
    return
end

local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false

print("Response Body:")
print(jResp:emit())

local respStatusCode = http.last_status
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
    print("Response Header:")
    print(http.last_header)
    print("Failed.")
    return
end

-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)

-- {
--   "indirizzi_email": [
--     {
--       "email": "string",
--       "categoria": "string"
--     }
--   ],
--   "indirizzi_email_certificate": [
--     {
--       "email": "string",
--       "categoria": "string"
--     }
--   ],
--   "telefoni": [
--     {
--       "fonte": "string",
--       "sede": "string",
--       "numero": "string",
--       "uso": "string"
--     }
--   ],
--   "siti_web": [
--     {
--       "url": "string",
--       "tipo": "string"
--     }
--   ]
-- }

-- Sample code for parsing the JSON response...
-- Use the following online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON

local email = ""
local categoria = ""
local fonte = ""
local sede = ""
local numero = ""
local uso = ""
local url = ""
local tipo = ""

local i = 0
local count_i = jResp:size_of_array("indirizzi_email")
while i < count_i do
    jResp.i = i
    email = jResp:string_of("indirizzi_email[i].email")
    categoria = jResp:string_of("indirizzi_email[i].categoria")
    i = i + 1
end

i = 0
count_i = jResp:size_of_array("indirizzi_email_certificate")
while i < count_i do
    jResp.i = i
    email = jResp:string_of("indirizzi_email_certificate[i].email")
    categoria = jResp:string_of("indirizzi_email_certificate[i].categoria")
    i = i + 1
end

i = 0
count_i = jResp:size_of_array("telefoni")
while i < count_i do
    jResp.i = i
    fonte = jResp:string_of("telefoni[i].fonte")
    sede = jResp:string_of("telefoni[i].sede")
    numero = jResp:string_of("telefoni[i].numero")
    uso = jResp:string_of("telefoni[i].uso")
    i = i + 1
end

i = 0
count_i = jResp:size_of_array("siti_web")
while i < count_i do
    jResp.i = i
    url = jResp:string_of("siti_web[i].url")
    tipo = jResp:string_of("siti_web[i].tipo")
    i = i + 1
end