Lua
Lua
Cerved API Advanced Entity Search
See more Cerved Examples
The "Advanced Entity Search" API allows you to find subjects in the Cerved database that meet specific search criteria, specified through the parameters provided as input to the service.Chilkat Lua Downloads
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 POST \
-- https://api.cerved.com/cervedApi/v1/entitySearch/advanced \
-- -H 'accept: application/json' \
-- -H 'apikey: ********************************' \
-- -d '{
-- "search_text": "string",
-- "activity_status_codes": [
-- "A",
-- "C",
-- "D",
-- "F",
-- "I",
-- "L",
-- "N",
-- "P",
-- "R",
-- "S",
-- "T"
-- ],
-- "birth_date": "string",
-- "name": "string",
-- "subject_types": [
-- "PERSON",
-- "INDIVIDUAL_COMPANY",
-- "COMPANY",
-- "FOREIGN",
-- "OTHER"
-- ],
-- "tax_code": "string",
-- "vat_number": "string",
-- "rea": {
-- "cciaa": "string",
-- "rea_number": 0
-- },
-- "city_istat_code": "string",
-- "province_code": "string"
-- }'
-- Use the following online tool to generate HTTP code from a CURL command
-- Convert a cURL Command to HTTP Source Code
-- Use this online tool to generate code from sample JSON:
-- Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "search_text": "string",
-- "activity_status_codes": [
-- "A",
-- "C",
-- "D",
-- "F",
-- "I",
-- "L",
-- "N",
-- "P",
-- "R",
-- "S",
-- "T"
-- ],
-- "birth_date": "string",
-- "name": "string",
-- "subject_types": [
-- "PERSON",
-- "INDIVIDUAL_COMPANY",
-- "COMPANY",
-- "FOREIGN",
-- "OTHER"
-- ],
-- "tax_code": "string",
-- "vat_number": "string",
-- "rea": {
-- "cciaa": "string",
-- "rea_number": 0
-- },
-- "city_istat_code": "string",
-- "province_code": "string"
-- }
local json = chilkat.JsonObject.new()
-- IMPORTANT: Only include the lines for the search criteria you wish to include.
json:update_string("search_text", "string")
json:update_string("activity_status_codes[0]", "A")
json:update_string("activity_status_codes[1]", "C")
json:update_string("activity_status_codes[2]", "D")
json:update_string("activity_status_codes[3]", "F")
json:update_string("activity_status_codes[4]", "I")
json:update_string("activity_status_codes[5]", "L")
json:update_string("activity_status_codes[6]", "N")
json:update_string("activity_status_codes[7]", "P")
json:update_string("activity_status_codes[8]", "R")
json:update_string("activity_status_codes[9]", "S")
json:update_string("activity_status_codes[10]", "T")
json:update_string("birth_date", "string")
json:update_string("name", "string")
json:update_string("subject_types[0]", "PERSON")
json:update_string("subject_types[1]", "INDIVIDUAL_COMPANY")
json:update_string("subject_types[2]", "COMPANY")
json:update_string("subject_types[3]", "FOREIGN")
json:update_string("subject_types[4]", "OTHER")
json:update_string("tax_code", "string")
json:update_string("vat_number", "string")
json:update_string("rea.cciaa", "string")
json:update_int("rea.rea_number", 0)
json:update_string("city_istat_code", "string")
json:update_string("province_code", "string")
http:set_request_header("accept", "application/json")
http:set_request_header("apikey", "********************************")
local resp = chilkat.HttpResponse.new()
local success = http:http_json("POST", "https://api.cerved.com/cervedApi/v1/entitySearch/advanced", json, "application/json", resp)
if not success then
print(http.last_error_text)
return
end
local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false
print("Response Body:")
print(jResp:emit())
local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
print("Response Header:")
print(resp.header)
print("Failed.")
return
end
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "subjects": [
-- {
-- "subject_id": "string",
-- "subject_type": "string",
-- "tax_code": "string",
-- "address": {
-- "street": {
-- "description": "string"
-- },
-- "city": {
-- "code": "string",
-- "istat_code": "string",
-- "description": "string"
-- },
-- "province": {
-- "code": "string",
-- "description": "string"
-- },
-- "postal_code": "string",
-- "country": {
-- "code": "string",
-- "description": "string"
-- }
-- },
-- "company_info": {
-- "legal_form": {
-- "code": "string",
-- "description": "string",
-- "class_code": "string"
-- },
-- "activity_status": {
-- "code": "string",
-- "description": "string"
-- },
-- "business_name": "string",
-- "economic_activity": {
-- "ateco": {
-- "code": "string",
-- "description": "string"
-- }
-- },
-- "head_office": "true",
-- "lei_code": "string",
-- "operational_flag": "true",
-- "public_administration": {
-- "pa_subject": "true",
-- "pa_supplier": "true",
-- "pa_owned": "true"
-- },
-- "rea_code": {
-- "cciaa": "string",
-- "rea_number": 0,
-- "registration_date": "string"
-- },
-- "vat_number": "string",
-- "no_rea_data": {
-- "form_code": "string",
-- "form_description": "string"
-- }
-- },
-- "person_info": {
-- "first_name": "string",
-- "last_name": "string",
-- "name": "string",
-- "birth_date": "string",
-- "birth_place": {
-- "street": {
-- "description": "string"
-- },
-- "city": {
-- "code": "string",
-- "istat_code": "string",
-- "description": "string"
-- },
-- "province": {
-- "code": "string",
-- "description": "string"
-- },
-- "postal_code": "string",
-- "country": {
-- "code": "string",
-- "description": "string"
-- }
-- }
-- }
-- }
-- ],
-- "subjects_total_number": 0
-- }
-- 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 subject_id = ""
local subject_type = ""
local tax_code = ""
local addressStreetDescription = ""
local addressCityCode = ""
local addressCityIstat_code = ""
local addressCityDescription = ""
local addressProvinceCode = ""
local addressProvinceDescription = ""
local addressPostal_code = ""
local addressCountryCode = ""
local addressCountryDescription = ""
local company_infoLegal_formCode = ""
local company_infoLegal_formDescription = ""
local company_infoLegal_formClass_code = ""
local company_infoActivity_statusCode = ""
local company_infoActivity_statusDescription = ""
local company_infoBusiness_name = ""
local company_infoEconomic_activityAtecoCode = ""
local company_infoEconomic_activityAtecoDescription = ""
local company_infoHead_office = ""
local company_infoLei_code = ""
local company_infoOperational_flag = ""
local company_infoPublic_administrationPa_subject = ""
local company_infoPublic_administrationPa_supplier = ""
local company_infoPublic_administrationPa_owned = ""
local company_infoRea_codeCciaa = ""
local company_infoRea_codeRea_number = 0
local company_infoRea_codeRegistration_date = ""
local company_infoVat_number = ""
local company_infoNo_rea_dataForm_code = ""
local company_infoNo_rea_dataForm_description = ""
local person_infoFirst_name = ""
local person_infoLast_name = ""
local person_infoName = ""
local person_infoBirth_date = ""
local person_infoBirth_placeStreetDescription = ""
local person_infoBirth_placeCityCode = ""
local person_infoBirth_placeCityIstat_code = ""
local person_infoBirth_placeCityDescription = ""
local person_infoBirth_placeProvinceCode = ""
local person_infoBirth_placeProvinceDescription = ""
local person_infoBirth_placePostal_code = ""
local person_infoBirth_placeCountryCode = ""
local person_infoBirth_placeCountryDescription = ""
local subjects_total_number = jResp:int_of("subjects_total_number")
local i = 0
local count_i = jResp:size_of_array("subjects")
while i < count_i do
jResp.i = i
subject_id = jResp:string_of("subjects[i].subject_id")
subject_type = jResp:string_of("subjects[i].subject_type")
tax_code = jResp:string_of("subjects[i].tax_code")
addressStreetDescription = jResp:string_of("subjects[i].address.street.description")
addressCityCode = jResp:string_of("subjects[i].address.city.code")
addressCityIstat_code = jResp:string_of("subjects[i].address.city.istat_code")
addressCityDescription = jResp:string_of("subjects[i].address.city.description")
addressProvinceCode = jResp:string_of("subjects[i].address.province.code")
addressProvinceDescription = jResp:string_of("subjects[i].address.province.description")
addressPostal_code = jResp:string_of("subjects[i].address.postal_code")
addressCountryCode = jResp:string_of("subjects[i].address.country.code")
addressCountryDescription = jResp:string_of("subjects[i].address.country.description")
company_infoLegal_formCode = jResp:string_of("subjects[i].company_info.legal_form.code")
company_infoLegal_formDescription = jResp:string_of("subjects[i].company_info.legal_form.description")
company_infoLegal_formClass_code = jResp:string_of("subjects[i].company_info.legal_form.class_code")
company_infoActivity_statusCode = jResp:string_of("subjects[i].company_info.activity_status.code")
company_infoActivity_statusDescription = jResp:string_of("subjects[i].company_info.activity_status.description")
company_infoBusiness_name = jResp:string_of("subjects[i].company_info.business_name")
company_infoEconomic_activityAtecoCode = jResp:string_of("subjects[i].company_info.economic_activity.ateco.code")
company_infoEconomic_activityAtecoDescription = jResp:string_of("subjects[i].company_info.economic_activity.ateco.description")
company_infoHead_office = jResp:string_of("subjects[i].company_info.head_office")
company_infoLei_code = jResp:string_of("subjects[i].company_info.lei_code")
company_infoOperational_flag = jResp:string_of("subjects[i].company_info.operational_flag")
company_infoPublic_administrationPa_subject = jResp:string_of("subjects[i].company_info.public_administration.pa_subject")
company_infoPublic_administrationPa_supplier = jResp:string_of("subjects[i].company_info.public_administration.pa_supplier")
company_infoPublic_administrationPa_owned = jResp:string_of("subjects[i].company_info.public_administration.pa_owned")
company_infoRea_codeCciaa = jResp:string_of("subjects[i].company_info.rea_code.cciaa")
company_infoRea_codeRea_number = jResp:int_of("subjects[i].company_info.rea_code.rea_number")
company_infoRea_codeRegistration_date = jResp:string_of("subjects[i].company_info.rea_code.registration_date")
company_infoVat_number = jResp:string_of("subjects[i].company_info.vat_number")
company_infoNo_rea_dataForm_code = jResp:string_of("subjects[i].company_info.no_rea_data.form_code")
company_infoNo_rea_dataForm_description = jResp:string_of("subjects[i].company_info.no_rea_data.form_description")
person_infoFirst_name = jResp:string_of("subjects[i].person_info.first_name")
person_infoLast_name = jResp:string_of("subjects[i].person_info.last_name")
person_infoName = jResp:string_of("subjects[i].person_info.name")
person_infoBirth_date = jResp:string_of("subjects[i].person_info.birth_date")
person_infoBirth_placeStreetDescription = jResp:string_of("subjects[i].person_info.birth_place.street.description")
person_infoBirth_placeCityCode = jResp:string_of("subjects[i].person_info.birth_place.city.code")
person_infoBirth_placeCityIstat_code = jResp:string_of("subjects[i].person_info.birth_place.city.istat_code")
person_infoBirth_placeCityDescription = jResp:string_of("subjects[i].person_info.birth_place.city.description")
person_infoBirth_placeProvinceCode = jResp:string_of("subjects[i].person_info.birth_place.province.code")
person_infoBirth_placeProvinceDescription = jResp:string_of("subjects[i].person_info.birth_place.province.description")
person_infoBirth_placePostal_code = jResp:string_of("subjects[i].person_info.birth_place.postal_code")
person_infoBirth_placeCountryCode = jResp:string_of("subjects[i].person_info.birth_place.country.code")
person_infoBirth_placeCountryDescription = jResp:string_of("subjects[i].person_info.birth_place.country.description")
i = i + 1
end