Sample code for 30+ languages & platforms
Lianja

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 Lianja Downloads

Lianja
llSuccess = .F.

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

loHttp = createobject("CkHttp")

// 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"
// }

loJson = createobject("CkJsonObject")
// IMPORTANT:  Only include the lines for the search criteria you wish to include.
loJson.UpdateString("search_text","string")
loJson.UpdateString("activity_status_codes[0]","A")
loJson.UpdateString("activity_status_codes[1]","C")
loJson.UpdateString("activity_status_codes[2]","D")
loJson.UpdateString("activity_status_codes[3]","F")
loJson.UpdateString("activity_status_codes[4]","I")
loJson.UpdateString("activity_status_codes[5]","L")
loJson.UpdateString("activity_status_codes[6]","N")
loJson.UpdateString("activity_status_codes[7]","P")
loJson.UpdateString("activity_status_codes[8]","R")
loJson.UpdateString("activity_status_codes[9]","S")
loJson.UpdateString("activity_status_codes[10]","T")
loJson.UpdateString("birth_date","string")
loJson.UpdateString("name","string")
loJson.UpdateString("subject_types[0]","PERSON")
loJson.UpdateString("subject_types[1]","INDIVIDUAL_COMPANY")
loJson.UpdateString("subject_types[2]","COMPANY")
loJson.UpdateString("subject_types[3]","FOREIGN")
loJson.UpdateString("subject_types[4]","OTHER")
loJson.UpdateString("tax_code","string")
loJson.UpdateString("vat_number","string")
loJson.UpdateString("rea.cciaa","string")
loJson.UpdateInt("rea.rea_number",0)
loJson.UpdateString("city_istat_code","string")
loJson.UpdateString("province_code","string")

loHttp.SetRequestHeader("accept","application/json")
loHttp.SetRequestHeader("apikey","********************************")

loResp = createobject("CkHttpResponse")
llSuccess = loHttp.HttpJson("POST","https://api.cerved.com/cervedApi/v1/entitySearch/advanced",loJson,"application/json",loResp)
if (llSuccess = .F.) then
    ? loHttp.LastErrorText
    release loHttp
    release loJson
    release loResp
    return
endif

loSbResponseBody = createobject("CkStringBuilder")
loResp.GetBodySb(loSbResponseBody)
loJResp = createobject("CkJsonObject")
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = .F.

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + str(lnRespStatusCode)
if (lnRespStatusCode >= 400) then
    ? "Response Header:"
    ? loResp.Header
    ? "Failed."
    release loHttp
    release loJson
    release loResp
    release loSbResponseBody
    release loJResp
    return
endif

// 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

lnSubjects_total_number = loJResp.IntOf("subjects_total_number")
i = 0
lnCount_i = loJResp.SizeOfArray("subjects")
do while i < lnCount_i
    loJResp.I = i
    lcSubject_id = loJResp.StringOf("subjects[i].subject_id")
    lcSubject_type = loJResp.StringOf("subjects[i].subject_type")
    lcTax_code = loJResp.StringOf("subjects[i].tax_code")
    lcAddressStreetDescription = loJResp.StringOf("subjects[i].address.street.description")
    lcAddressCityCode = loJResp.StringOf("subjects[i].address.city.code")
    lcAddressCityIstat_code = loJResp.StringOf("subjects[i].address.city.istat_code")
    lcAddressCityDescription = loJResp.StringOf("subjects[i].address.city.description")
    lcAddressProvinceCode = loJResp.StringOf("subjects[i].address.province.code")
    lcAddressProvinceDescription = loJResp.StringOf("subjects[i].address.province.description")
    lcAddressPostal_code = loJResp.StringOf("subjects[i].address.postal_code")
    lcAddressCountryCode = loJResp.StringOf("subjects[i].address.country.code")
    lcAddressCountryDescription = loJResp.StringOf("subjects[i].address.country.description")
    lcCompany_infoLegal_formCode = loJResp.StringOf("subjects[i].company_info.legal_form.code")
    lcCompany_infoLegal_formDescription = loJResp.StringOf("subjects[i].company_info.legal_form.description")
    lcCompany_infoLegal_formClass_code = loJResp.StringOf("subjects[i].company_info.legal_form.class_code")
    lcCompany_infoActivity_statusCode = loJResp.StringOf("subjects[i].company_info.activity_status.code")
    lcCompany_infoActivity_statusDescription = loJResp.StringOf("subjects[i].company_info.activity_status.description")
    lcCompany_infoBusiness_name = loJResp.StringOf("subjects[i].company_info.business_name")
    lcCompany_infoEconomic_activityAtecoCode = loJResp.StringOf("subjects[i].company_info.economic_activity.ateco.code")
    lcCompany_infoEconomic_activityAtecoDescription = loJResp.StringOf("subjects[i].company_info.economic_activity.ateco.description")
    lcCompany_infoHead_office = loJResp.StringOf("subjects[i].company_info.head_office")
    lcCompany_infoLei_code = loJResp.StringOf("subjects[i].company_info.lei_code")
    lcCompany_infoOperational_flag = loJResp.StringOf("subjects[i].company_info.operational_flag")
    lcCompany_infoPublic_administrationPa_subject = loJResp.StringOf("subjects[i].company_info.public_administration.pa_subject")
    lcCompany_infoPublic_administrationPa_supplier = loJResp.StringOf("subjects[i].company_info.public_administration.pa_supplier")
    lcCompany_infoPublic_administrationPa_owned = loJResp.StringOf("subjects[i].company_info.public_administration.pa_owned")
    lcCompany_infoRea_codeCciaa = loJResp.StringOf("subjects[i].company_info.rea_code.cciaa")
    lnCompany_infoRea_codeRea_number = loJResp.IntOf("subjects[i].company_info.rea_code.rea_number")
    lcCompany_infoRea_codeRegistration_date = loJResp.StringOf("subjects[i].company_info.rea_code.registration_date")
    lcCompany_infoVat_number = loJResp.StringOf("subjects[i].company_info.vat_number")
    lcCompany_infoNo_rea_dataForm_code = loJResp.StringOf("subjects[i].company_info.no_rea_data.form_code")
    lcCompany_infoNo_rea_dataForm_description = loJResp.StringOf("subjects[i].company_info.no_rea_data.form_description")
    lcPerson_infoFirst_name = loJResp.StringOf("subjects[i].person_info.first_name")
    lcPerson_infoLast_name = loJResp.StringOf("subjects[i].person_info.last_name")
    lcPerson_infoName = loJResp.StringOf("subjects[i].person_info.name")
    lcPerson_infoBirth_date = loJResp.StringOf("subjects[i].person_info.birth_date")
    lcPerson_infoBirth_placeStreetDescription = loJResp.StringOf("subjects[i].person_info.birth_place.street.description")
    lcPerson_infoBirth_placeCityCode = loJResp.StringOf("subjects[i].person_info.birth_place.city.code")
    lcPerson_infoBirth_placeCityIstat_code = loJResp.StringOf("subjects[i].person_info.birth_place.city.istat_code")
    lcPerson_infoBirth_placeCityDescription = loJResp.StringOf("subjects[i].person_info.birth_place.city.description")
    lcPerson_infoBirth_placeProvinceCode = loJResp.StringOf("subjects[i].person_info.birth_place.province.code")
    lcPerson_infoBirth_placeProvinceDescription = loJResp.StringOf("subjects[i].person_info.birth_place.province.description")
    lcPerson_infoBirth_placePostal_code = loJResp.StringOf("subjects[i].person_info.birth_place.postal_code")
    lcPerson_infoBirth_placeCountryCode = loJResp.StringOf("subjects[i].person_info.birth_place.country.code")
    lcPerson_infoBirth_placeCountryDescription = loJResp.StringOf("subjects[i].person_info.birth_place.country.description")
    i = i + 1
enddo


release loHttp
release loJson
release loResp
release loSbResponseBody
release loJResp