Sample code for 30+ languages & platforms
Unicode C

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 Unicode C Downloads

Unicode C
#include <C_CkHttpW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *email;
    const wchar_t *categoria;
    const wchar_t *fonte;
    const wchar_t *sede;
    const wchar_t *numero;
    const wchar_t *uso;
    const wchar_t *url;
    const wchar_t *tipo;
    int i;
    int count_i;

    success = FALSE;

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

    http = CkHttpW_Create();

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

    CkHttpW_SetRequestHeader(http,L"accept",L"application/json");
    CkHttpW_SetRequestHeader(http,L"apikey",L"********************************");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,L"https://api.cerved.com/cervedApi/v1/entityProfile/contacts?id_soggetto=12345678",sbResponseBody);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpW_getLastStatus(http);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpW_lastHeader(http));
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    // See this example explaining how this memory should be used: const char * functions.

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"indirizzi_email");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        email = CkJsonObjectW_stringOf(jResp,L"indirizzi_email[i].email");
        categoria = CkJsonObjectW_stringOf(jResp,L"indirizzi_email[i].categoria");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"indirizzi_email_certificate");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        email = CkJsonObjectW_stringOf(jResp,L"indirizzi_email_certificate[i].email");
        categoria = CkJsonObjectW_stringOf(jResp,L"indirizzi_email_certificate[i].categoria");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"telefoni");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        fonte = CkJsonObjectW_stringOf(jResp,L"telefoni[i].fonte");
        sede = CkJsonObjectW_stringOf(jResp,L"telefoni[i].sede");
        numero = CkJsonObjectW_stringOf(jResp,L"telefoni[i].numero");
        uso = CkJsonObjectW_stringOf(jResp,L"telefoni[i].uso");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"siti_web");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        url = CkJsonObjectW_stringOf(jResp,L"siti_web[i].url");
        tipo = CkJsonObjectW_stringOf(jResp,L"siti_web[i].tipo");
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }