Zig
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// 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"
// }
const json = try chilkat.JsonObject.init();
defer json.deinit();
// IMPORTANT: Only include the lines for the search criteria you wish to include.
json.updateString("search_text", "string") catch {};
json.updateString("activity_status_codes[0]", "A") catch {};
json.updateString("activity_status_codes[1]", "C") catch {};
json.updateString("activity_status_codes[2]", "D") catch {};
json.updateString("activity_status_codes[3]", "F") catch {};
json.updateString("activity_status_codes[4]", "I") catch {};
json.updateString("activity_status_codes[5]", "L") catch {};
json.updateString("activity_status_codes[6]", "N") catch {};
json.updateString("activity_status_codes[7]", "P") catch {};
json.updateString("activity_status_codes[8]", "R") catch {};
json.updateString("activity_status_codes[9]", "S") catch {};
json.updateString("activity_status_codes[10]", "T") catch {};
json.updateString("birth_date", "string") catch {};
json.updateString("name", "string") catch {};
json.updateString("subject_types[0]", "PERSON") catch {};
json.updateString("subject_types[1]", "INDIVIDUAL_COMPANY") catch {};
json.updateString("subject_types[2]", "COMPANY") catch {};
json.updateString("subject_types[3]", "FOREIGN") catch {};
json.updateString("subject_types[4]", "OTHER") catch {};
json.updateString("tax_code", "string") catch {};
json.updateString("vat_number", "string") catch {};
json.updateString("rea.cciaa", "string") catch {};
json.updateInt("rea.rea_number", 0) catch {};
json.updateString("city_istat_code", "string") catch {};
json.updateString("province_code", "string") catch {};
http.setRequestHeader("accept", "application/json");
http.setRequestHeader("apikey", "********************************");
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpJson("POST", "https://api.cerved.com/cervedApi/v1/entitySearch/advanced", json, "application/json", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const sb_response_body = try chilkat.StringBuilder.init();
defer sb_response_body.deinit();
resp.getBodySb(sb_response_body) catch {};
const j_resp = try chilkat.JsonObject.init();
defer j_resp.deinit();
j_resp.loadSb(sb_response_body) catch {};
j_resp.setEmitCompact(false);
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try j_resp.emit(alloc)});
const resp_status_code = resp.getStatusCode();
std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
if (resp_status_code >= 400) {
std.debug.print("Response Header:\n", .{});
std.debug.print("{s}\n", .{try resp.getHeader(alloc)});
std.debug.print("Failed.\n", .{});
return;
}
// 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
var subject_id: [:0]const u8 = "";
var subject_type: [:0]const u8 = "";
var tax_code: [:0]const u8 = "";
var address_street_description: [:0]const u8 = "";
var address_city_code: [:0]const u8 = "";
var address_city_istat_code: [:0]const u8 = "";
var address_city_description: [:0]const u8 = "";
var address_province_code: [:0]const u8 = "";
var address_province_description: [:0]const u8 = "";
var address_postal_code: [:0]const u8 = "";
var address_country_code: [:0]const u8 = "";
var address_country_description: [:0]const u8 = "";
var company_info_legal_form_code: [:0]const u8 = "";
var company_info_legal_form_description: [:0]const u8 = "";
var company_info_legal_form_class_code: [:0]const u8 = "";
var company_info_activity_status_code: [:0]const u8 = "";
var company_info_activity_status_description: [:0]const u8 = "";
var company_info_business_name: [:0]const u8 = "";
var company_info_economic_activity_ateco_code: [:0]const u8 = "";
var company_info_economic_activity_ateco_description: [:0]const u8 = "";
var company_info_head_office: [:0]const u8 = "";
var company_info_lei_code: [:0]const u8 = "";
var company_info_operational_flag: [:0]const u8 = "";
var company_info_public_administration_pa_subject: [:0]const u8 = "";
var company_info_public_administration_pa_supplier: [:0]const u8 = "";
var company_info_public_administration_pa_owned: [:0]const u8 = "";
var company_info_rea_code_cciaa: [:0]const u8 = "";
var company_info_rea_code_rea_number: i32 = 0;
var company_info_rea_code_registration_date: [:0]const u8 = "";
var company_info_vat_number: [:0]const u8 = "";
var company_info_no_rea_data_form_code: [:0]const u8 = "";
var company_info_no_rea_data_form_description: [:0]const u8 = "";
var person_info_first_name: [:0]const u8 = "";
var person_info_last_name: [:0]const u8 = "";
var person_info_name: [:0]const u8 = "";
var person_info_birth_date: [:0]const u8 = "";
var person_info_birth_place_street_description: [:0]const u8 = "";
var person_info_birth_place_city_code: [:0]const u8 = "";
var person_info_birth_place_city_istat_code: [:0]const u8 = "";
var person_info_birth_place_city_description: [:0]const u8 = "";
var person_info_birth_place_province_code: [:0]const u8 = "";
var person_info_birth_place_province_description: [:0]const u8 = "";
var person_info_birth_place_postal_code: [:0]const u8 = "";
var person_info_birth_place_country_code: [:0]const u8 = "";
var person_info_birth_place_country_description: [:0]const u8 = "";
_ = j_resp.intOf("subjects_total_number");
var i: i32 = 0;
const count_i = j_resp.sizeOfArray("subjects");
while (i < count_i) {
j_resp.setI(i);
subject_id = try j_resp.stringOf(alloc, "subjects[i].subject_id");
subject_type = try j_resp.stringOf(alloc, "subjects[i].subject_type");
tax_code = try j_resp.stringOf(alloc, "subjects[i].tax_code");
address_street_description = try j_resp.stringOf(alloc, "subjects[i].address.street.description");
address_city_code = try j_resp.stringOf(alloc, "subjects[i].address.city.code");
address_city_istat_code = try j_resp.stringOf(alloc, "subjects[i].address.city.istat_code");
address_city_description = try j_resp.stringOf(alloc, "subjects[i].address.city.description");
address_province_code = try j_resp.stringOf(alloc, "subjects[i].address.province.code");
address_province_description = try j_resp.stringOf(alloc, "subjects[i].address.province.description");
address_postal_code = try j_resp.stringOf(alloc, "subjects[i].address.postal_code");
address_country_code = try j_resp.stringOf(alloc, "subjects[i].address.country.code");
address_country_description = try j_resp.stringOf(alloc, "subjects[i].address.country.description");
company_info_legal_form_code = try j_resp.stringOf(alloc, "subjects[i].company_info.legal_form.code");
company_info_legal_form_description = try j_resp.stringOf(alloc, "subjects[i].company_info.legal_form.description");
company_info_legal_form_class_code = try j_resp.stringOf(alloc, "subjects[i].company_info.legal_form.class_code");
company_info_activity_status_code = try j_resp.stringOf(alloc, "subjects[i].company_info.activity_status.code");
company_info_activity_status_description = try j_resp.stringOf(alloc, "subjects[i].company_info.activity_status.description");
company_info_business_name = try j_resp.stringOf(alloc, "subjects[i].company_info.business_name");
company_info_economic_activity_ateco_code = try j_resp.stringOf(alloc, "subjects[i].company_info.economic_activity.ateco.code");
company_info_economic_activity_ateco_description = try j_resp.stringOf(alloc, "subjects[i].company_info.economic_activity.ateco.description");
company_info_head_office = try j_resp.stringOf(alloc, "subjects[i].company_info.head_office");
company_info_lei_code = try j_resp.stringOf(alloc, "subjects[i].company_info.lei_code");
company_info_operational_flag = try j_resp.stringOf(alloc, "subjects[i].company_info.operational_flag");
company_info_public_administration_pa_subject = try j_resp.stringOf(alloc, "subjects[i].company_info.public_administration.pa_subject");
company_info_public_administration_pa_supplier = try j_resp.stringOf(alloc, "subjects[i].company_info.public_administration.pa_supplier");
company_info_public_administration_pa_owned = try j_resp.stringOf(alloc, "subjects[i].company_info.public_administration.pa_owned");
company_info_rea_code_cciaa = try j_resp.stringOf(alloc, "subjects[i].company_info.rea_code.cciaa");
company_info_rea_code_rea_number = j_resp.intOf("subjects[i].company_info.rea_code.rea_number");
company_info_rea_code_registration_date = try j_resp.stringOf(alloc, "subjects[i].company_info.rea_code.registration_date");
company_info_vat_number = try j_resp.stringOf(alloc, "subjects[i].company_info.vat_number");
company_info_no_rea_data_form_code = try j_resp.stringOf(alloc, "subjects[i].company_info.no_rea_data.form_code");
company_info_no_rea_data_form_description = try j_resp.stringOf(alloc, "subjects[i].company_info.no_rea_data.form_description");
person_info_first_name = try j_resp.stringOf(alloc, "subjects[i].person_info.first_name");
person_info_last_name = try j_resp.stringOf(alloc, "subjects[i].person_info.last_name");
person_info_name = try j_resp.stringOf(alloc, "subjects[i].person_info.name");
person_info_birth_date = try j_resp.stringOf(alloc, "subjects[i].person_info.birth_date");
person_info_birth_place_street_description = try j_resp.stringOf(alloc, "subjects[i].person_info.birth_place.street.description");
person_info_birth_place_city_code = try j_resp.stringOf(alloc, "subjects[i].person_info.birth_place.city.code");
person_info_birth_place_city_istat_code = try j_resp.stringOf(alloc, "subjects[i].person_info.birth_place.city.istat_code");
person_info_birth_place_city_description = try j_resp.stringOf(alloc, "subjects[i].person_info.birth_place.city.description");
person_info_birth_place_province_code = try j_resp.stringOf(alloc, "subjects[i].person_info.birth_place.province.code");
person_info_birth_place_province_description = try j_resp.stringOf(alloc, "subjects[i].person_info.birth_place.province.description");
person_info_birth_place_postal_code = try j_resp.stringOf(alloc, "subjects[i].person_info.birth_place.postal_code");
person_info_birth_place_country_code = try j_resp.stringOf(alloc, "subjects[i].person_info.birth_place.country.code");
person_info_birth_place_country_description = try j_resp.stringOf(alloc, "subjects[i].person_info.birth_place.country.description");
i = i + 1;
}
}