Tcl
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 0
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set http [new_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"
# }
set json [new_CkJsonObject]
# IMPORTANT: Only include the lines for the search criteria you wish to include.
CkJsonObject_UpdateString $json "search_text" "string"
CkJsonObject_UpdateString $json "activity_status_codes[0]" "A"
CkJsonObject_UpdateString $json "activity_status_codes[1]" "C"
CkJsonObject_UpdateString $json "activity_status_codes[2]" "D"
CkJsonObject_UpdateString $json "activity_status_codes[3]" "F"
CkJsonObject_UpdateString $json "activity_status_codes[4]" "I"
CkJsonObject_UpdateString $json "activity_status_codes[5]" "L"
CkJsonObject_UpdateString $json "activity_status_codes[6]" "N"
CkJsonObject_UpdateString $json "activity_status_codes[7]" "P"
CkJsonObject_UpdateString $json "activity_status_codes[8]" "R"
CkJsonObject_UpdateString $json "activity_status_codes[9]" "S"
CkJsonObject_UpdateString $json "activity_status_codes[10]" "T"
CkJsonObject_UpdateString $json "birth_date" "string"
CkJsonObject_UpdateString $json "name" "string"
CkJsonObject_UpdateString $json "subject_types[0]" "PERSON"
CkJsonObject_UpdateString $json "subject_types[1]" "INDIVIDUAL_COMPANY"
CkJsonObject_UpdateString $json "subject_types[2]" "COMPANY"
CkJsonObject_UpdateString $json "subject_types[3]" "FOREIGN"
CkJsonObject_UpdateString $json "subject_types[4]" "OTHER"
CkJsonObject_UpdateString $json "tax_code" "string"
CkJsonObject_UpdateString $json "vat_number" "string"
CkJsonObject_UpdateString $json "rea.cciaa" "string"
CkJsonObject_UpdateInt $json "rea.rea_number" 0
CkJsonObject_UpdateString $json "city_istat_code" "string"
CkJsonObject_UpdateString $json "province_code" "string"
CkHttp_SetRequestHeader $http "accept" "application/json"
CkHttp_SetRequestHeader $http "apikey" "********************************"
set resp [new_CkHttpResponse]
set success [CkHttp_HttpJson $http "POST" "https://api.cerved.com/cervedApi/v1/entitySearch/advanced" $json "application/json" $resp]
if {$success == 0} then {
puts [CkHttp_lastErrorText $http]
delete_CkHttp $http
delete_CkJsonObject $json
delete_CkHttpResponse $resp
exit
}
set sbResponseBody [new_CkStringBuilder]
CkHttpResponse_GetBodySb $resp $sbResponseBody
set jResp [new_CkJsonObject]
CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0
puts "Response Body:"
puts [CkJsonObject_emit $jResp]
set respStatusCode [CkHttpResponse_get_StatusCode $resp]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
puts "Response Header:"
puts [CkHttpResponse_header $resp]
puts "Failed."
delete_CkHttp $http
delete_CkJsonObject $json
delete_CkHttpResponse $resp
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp
exit
}
# 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
set subjects_total_number [CkJsonObject_IntOf $jResp "subjects_total_number"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "subjects"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set subject_id [CkJsonObject_stringOf $jResp "subjects[i].subject_id"]
set subject_type [CkJsonObject_stringOf $jResp "subjects[i].subject_type"]
set tax_code [CkJsonObject_stringOf $jResp "subjects[i].tax_code"]
set addressStreetDescription [CkJsonObject_stringOf $jResp "subjects[i].address.street.description"]
set addressCityCode [CkJsonObject_stringOf $jResp "subjects[i].address.city.code"]
set addressCityIstat_code [CkJsonObject_stringOf $jResp "subjects[i].address.city.istat_code"]
set addressCityDescription [CkJsonObject_stringOf $jResp "subjects[i].address.city.description"]
set addressProvinceCode [CkJsonObject_stringOf $jResp "subjects[i].address.province.code"]
set addressProvinceDescription [CkJsonObject_stringOf $jResp "subjects[i].address.province.description"]
set addressPostal_code [CkJsonObject_stringOf $jResp "subjects[i].address.postal_code"]
set addressCountryCode [CkJsonObject_stringOf $jResp "subjects[i].address.country.code"]
set addressCountryDescription [CkJsonObject_stringOf $jResp "subjects[i].address.country.description"]
set company_infoLegal_formCode [CkJsonObject_stringOf $jResp "subjects[i].company_info.legal_form.code"]
set company_infoLegal_formDescription [CkJsonObject_stringOf $jResp "subjects[i].company_info.legal_form.description"]
set company_infoLegal_formClass_code [CkJsonObject_stringOf $jResp "subjects[i].company_info.legal_form.class_code"]
set company_infoActivity_statusCode [CkJsonObject_stringOf $jResp "subjects[i].company_info.activity_status.code"]
set company_infoActivity_statusDescription [CkJsonObject_stringOf $jResp "subjects[i].company_info.activity_status.description"]
set company_infoBusiness_name [CkJsonObject_stringOf $jResp "subjects[i].company_info.business_name"]
set company_infoEconomic_activityAtecoCode [CkJsonObject_stringOf $jResp "subjects[i].company_info.economic_activity.ateco.code"]
set company_infoEconomic_activityAtecoDescription [CkJsonObject_stringOf $jResp "subjects[i].company_info.economic_activity.ateco.description"]
set company_infoHead_office [CkJsonObject_stringOf $jResp "subjects[i].company_info.head_office"]
set company_infoLei_code [CkJsonObject_stringOf $jResp "subjects[i].company_info.lei_code"]
set company_infoOperational_flag [CkJsonObject_stringOf $jResp "subjects[i].company_info.operational_flag"]
set company_infoPublic_administrationPa_subject [CkJsonObject_stringOf $jResp "subjects[i].company_info.public_administration.pa_subject"]
set company_infoPublic_administrationPa_supplier [CkJsonObject_stringOf $jResp "subjects[i].company_info.public_administration.pa_supplier"]
set company_infoPublic_administrationPa_owned [CkJsonObject_stringOf $jResp "subjects[i].company_info.public_administration.pa_owned"]
set company_infoRea_codeCciaa [CkJsonObject_stringOf $jResp "subjects[i].company_info.rea_code.cciaa"]
set company_infoRea_codeRea_number [CkJsonObject_IntOf $jResp "subjects[i].company_info.rea_code.rea_number"]
set company_infoRea_codeRegistration_date [CkJsonObject_stringOf $jResp "subjects[i].company_info.rea_code.registration_date"]
set company_infoVat_number [CkJsonObject_stringOf $jResp "subjects[i].company_info.vat_number"]
set company_infoNo_rea_dataForm_code [CkJsonObject_stringOf $jResp "subjects[i].company_info.no_rea_data.form_code"]
set company_infoNo_rea_dataForm_description [CkJsonObject_stringOf $jResp "subjects[i].company_info.no_rea_data.form_description"]
set person_infoFirst_name [CkJsonObject_stringOf $jResp "subjects[i].person_info.first_name"]
set person_infoLast_name [CkJsonObject_stringOf $jResp "subjects[i].person_info.last_name"]
set person_infoName [CkJsonObject_stringOf $jResp "subjects[i].person_info.name"]
set person_infoBirth_date [CkJsonObject_stringOf $jResp "subjects[i].person_info.birth_date"]
set person_infoBirth_placeStreetDescription [CkJsonObject_stringOf $jResp "subjects[i].person_info.birth_place.street.description"]
set person_infoBirth_placeCityCode [CkJsonObject_stringOf $jResp "subjects[i].person_info.birth_place.city.code"]
set person_infoBirth_placeCityIstat_code [CkJsonObject_stringOf $jResp "subjects[i].person_info.birth_place.city.istat_code"]
set person_infoBirth_placeCityDescription [CkJsonObject_stringOf $jResp "subjects[i].person_info.birth_place.city.description"]
set person_infoBirth_placeProvinceCode [CkJsonObject_stringOf $jResp "subjects[i].person_info.birth_place.province.code"]
set person_infoBirth_placeProvinceDescription [CkJsonObject_stringOf $jResp "subjects[i].person_info.birth_place.province.description"]
set person_infoBirth_placePostal_code [CkJsonObject_stringOf $jResp "subjects[i].person_info.birth_place.postal_code"]
set person_infoBirth_placeCountryCode [CkJsonObject_stringOf $jResp "subjects[i].person_info.birth_place.country.code"]
set person_infoBirth_placeCountryDescription [CkJsonObject_stringOf $jResp "subjects[i].person_info.birth_place.country.description"]
set i [expr $i + 1]
}
delete_CkHttp $http
delete_CkJsonObject $json
delete_CkHttpResponse $resp
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp