Sample code for 30+ languages & platforms
Unicode C

SCIS Search

See more SCiS Schools Catalogue Examples

Demonstrates the SCIS (Schools Catalogue Information Service) search API call.

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 sbQuery;
    HCkStringBuilderW sbUrl;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *v_index;
    const wchar_t *v_type;
    int v_sourceDateIssuedMarc;
    const wchar_t *v_sourceIsbn13;
    const wchar_t *v_sourceImageFileName;
    const wchar_t *v_sourcePublicationDetails;
    const wchar_t *v_sourceIsbn10;
    const wchar_t *v_sourceId;
    const wchar_t *v_id;
    const wchar_t *v_score;
    int j;
    int count_j;
    const wchar_t *strVal;
    int dataHitsTotal;
    const wchar_t *dataHitsMax_score;
    int dataTook;
    BOOL dataTimed_out;
    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 -i -X GET --url 'https://api.scisdata.com/catalogue/api/search?query=titleSearch%3Adogs%20AND%20publicationYear%3A2015&from=0&size=20&sort=author&order=asc' -H 'Authorization: Basic ****'

    // Use the following online tool to generate HTTP code from a CURL command
    // Convert a cURL Command to HTTP Source Code

    // This causes the "Authorization: Basic ****" to be added to each request.
    CkHttpW_putLogin(http,L"myLogin");
    CkHttpW_putPassword(http,L"myPassword");
    CkHttpW_putBasicAuth(http,TRUE);

    sbQuery = CkStringBuilderW_Create();
    CkStringBuilderW_Append(sbQuery,L"titleSearch:dogs AND publicationYear:2015");

    sbUrl = CkStringBuilderW_Create();
    CkStringBuilderW_Append(sbUrl,L"https://api.scisdata.com/catalogue/api/search?query=");
    // If non-usascii chars are included in the search, we don't know if utf-8 or windows-1252 is desired by the server.  You'll need to find out..
    CkStringBuilderW_Append(sbUrl,CkStringBuilderW_getEncoded(sbQuery,L"url",L"utf-8"));
    CkStringBuilderW_Append(sbUrl,L"&from=0&size=20&sort=author&order=asc");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,CkStringBuilderW_getAsString(sbUrl),sbResponseBody);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbQuery);
        CkStringBuilderW_Dispose(sbUrl);
        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(sbQuery);
        CkStringBuilderW_Dispose(sbUrl);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "data": {
    //     "hits": {
    //       "hits": [
    //         {
    //           "_index": "scisdata2",
    //           "_type": "bibdatatype",
    //           "_source": {
    //             "isbn": [
    //               "9781517638160"
    //             ],
    //             "languageTermCode": [
    //               "eng"
    //             ],
    //             "mainAuthor": {
    //               "namePersonalPrimary": [
    //                 "Abbott, Eleanor Hallowell."
    //               ]
    //             },
    //             "title": {
    //               "titlePrimary": [
    //                 "Peace on Earth, good-will to dogs"
    //               ],
    //               "noteStmOfResponsibility": [
    //                 "by Eleanor Hallowell Abbott."
    //               ]
    //             },
    //             "scisType": [
    //               "Book"
    //             ],
    //             "dateIssuedMarc": 2015,
    //             "languageTermValue": [
    //               "English"
    //             ],
    //             "contributor": {},
    //             "isbn13": "9781517638160",
    //             "imageFileName": "9781517638160.jpg",
    //             "publicationDetails": "United States, Create Space Independent Publishing Platform, 2015",
    //             "isbn10": "151763816X",
    //             "id": "1867852"
    //           },
    //           "_id": "1867852",
    //           "sort": [
    //             "abbott, eleanor hallowell."
    //           ],
    //           "_score": null
    //         },
    //         {
    //           "_index": "scisdata2",
    //           "_type": "bibdatatype",
    //           "_source": {
    //             "isbn": [
    //               "9781780747910"
    //             ],
    //             "languageTermCode": [
    //               "eng"
    //             ],
    //             "mainAuthor": {
    //               "namePersonalPrimary": [
    //                 "Adams, Richard."
    //               ]
    //             },
    //             "title": {
    //               "titlePrimary": [
    //                 "The plague dogs"
    //               ],
    //               "noteStmOfResponsibility": [
    //                 "Richard Adams."
    //               ]
    //             },
    //             "scisType": [
    //               "Book"
    //             ],
    //             "dateIssuedMarc": 2015,
    //             "languageTermValue": [
    //               "English"
    //             ],
    //             "contributor": {},
    //             "isbn13": "9781780747910",
    //             "imageFileName": "9781780747910.jpg",
    //             "publicationDetails": "New York, Rock the Boat, 2015",
    //             "isbn10": "1780747918",
    //             "id": "1749228"
    //           },
    //           "_id": "1749228",
    //           "sort": [
    //             "adams, richard."
    //           ],
    //           "_score": null
    //         },
    //          ...
    //       ],
    //       "total": 84,
    //       "max_score": null
    //     },
    //     "took": 585,
    //     "timed_out": false
    //   },
    //   "subscriptionStatus": {}
    // }

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

    dataHitsTotal = CkJsonObjectW_IntOf(jResp,L"data.hits.total");
    dataHitsMax_score = CkJsonObjectW_stringOf(jResp,L"data.hits.max_score");
    dataTook = CkJsonObjectW_IntOf(jResp,L"data.took");
    dataTimed_out = CkJsonObjectW_BoolOf(jResp,L"data.timed_out");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.hits.hits");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        v_index = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._index");
        v_type = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._type");
        v_sourceDateIssuedMarc = CkJsonObjectW_IntOf(jResp,L"data.hits.hits[i]._source.dateIssuedMarc");
        v_sourceIsbn13 = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._source.isbn13");
        v_sourceImageFileName = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._source.imageFileName");
        v_sourcePublicationDetails = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._source.publicationDetails");
        v_sourceIsbn10 = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._source.isbn10");
        v_sourceId = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._source.id");
        v_id = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._id");
        v_score = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._score");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"data.hits.hits[i]._source.isbn");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._source.isbn[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"data.hits.hits[i]._source.languageTermCode");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._source.languageTermCode[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"data.hits.hits[i]._source.mainAuthor.namePersonalPrimary");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._source.mainAuthor.namePersonalPrimary[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"data.hits.hits[i]._source.title.titlePrimary");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._source.title.titlePrimary[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"data.hits.hits[i]._source.title.noteStmOfResponsibility");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._source.title.noteStmOfResponsibility[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"data.hits.hits[i]._source.scisType");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._source.scisType[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"data.hits.hits[i]._source.languageTermValue");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._source.languageTermValue[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"data.hits.hits[i].sort");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i].sort[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"data.hits.hits[i]._source.contributor.namePersonalOther");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._source.contributor.namePersonalOther[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"data.hits.hits[i]._source.contributor.nameCorporateOther");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"data.hits.hits[i]._source.contributor.nameCorporateOther[j]");
            j = j + 1;
        }

        i = i + 1;
    }



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

    }