Sample code for 30+ languages & platforms
PowerBuilder

SCIS Search

See more SCiS Schools Catalogue Examples

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

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_SbQuery
oleobject loo_SbUrl
oleobject loo_SbResponseBody
oleobject loo_JResp
long li_RespStatusCode
string ls_V_index
string ls_V_type
long li_V_sourceDateIssuedMarc
string ls_V_sourceIsbn13
string ls_V_sourceImageFileName
string ls_V_sourcePublicationDetails
string ls_V_sourceIsbn10
string ls_V_sourceId
string ls_V_id
string ls_V_score
long j
long li_Count_j
string ls_StrVal
long li_DataHitsTotal
string ls_DataHitsMax_score
long li_DataTook
long li_DataTimed_out
long i
long li_Count_i

li_Success = 0

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  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.
loo_Http.Login = "myLogin"
loo_Http.Password = "myPassword"
loo_Http.BasicAuth = 1

loo_SbQuery = create oleobject
li_rc = loo_SbQuery.ConnectToNewObject("Chilkat.StringBuilder")

loo_SbQuery.Append("titleSearch:dogs AND publicationYear:2015")

loo_SbUrl = create oleobject
li_rc = loo_SbUrl.ConnectToNewObject("Chilkat.StringBuilder")

loo_SbUrl.Append("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..
loo_SbUrl.Append(loo_SbQuery.GetEncoded("url","utf-8"))
loo_SbUrl.Append("&from=0&size=20&sort=author&order=asc")

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Http.QuickGetSb(loo_SbUrl.GetAsString(),loo_SbResponseBody)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_SbQuery
    destroy loo_SbUrl
    destroy loo_SbResponseBody
    return
end if

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Http.LastHeader
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_SbQuery
    destroy loo_SbUrl
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

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

li_DataHitsTotal = loo_JResp.IntOf("data.hits.total")
ls_DataHitsMax_score = loo_JResp.StringOf("data.hits.max_score")
li_DataTook = loo_JResp.IntOf("data.took")
li_DataTimed_out = loo_JResp.BoolOf("data.timed_out")
i = 0
li_Count_i = loo_JResp.SizeOfArray("data.hits.hits")
do while i < li_Count_i
    loo_JResp.I = i
    ls_V_index = loo_JResp.StringOf("data.hits.hits[i]._index")
    ls_V_type = loo_JResp.StringOf("data.hits.hits[i]._type")
    li_V_sourceDateIssuedMarc = loo_JResp.IntOf("data.hits.hits[i]._source.dateIssuedMarc")
    ls_V_sourceIsbn13 = loo_JResp.StringOf("data.hits.hits[i]._source.isbn13")
    ls_V_sourceImageFileName = loo_JResp.StringOf("data.hits.hits[i]._source.imageFileName")
    ls_V_sourcePublicationDetails = loo_JResp.StringOf("data.hits.hits[i]._source.publicationDetails")
    ls_V_sourceIsbn10 = loo_JResp.StringOf("data.hits.hits[i]._source.isbn10")
    ls_V_sourceId = loo_JResp.StringOf("data.hits.hits[i]._source.id")
    ls_V_id = loo_JResp.StringOf("data.hits.hits[i]._id")
    ls_V_score = loo_JResp.StringOf("data.hits.hits[i]._score")
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("data.hits.hits[i]._source.isbn")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("data.hits.hits[i]._source.isbn[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("data.hits.hits[i]._source.languageTermCode")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("data.hits.hits[i]._source.languageTermCode[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("data.hits.hits[i]._source.mainAuthor.namePersonalPrimary")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("data.hits.hits[i]._source.mainAuthor.namePersonalPrimary[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("data.hits.hits[i]._source.title.titlePrimary")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("data.hits.hits[i]._source.title.titlePrimary[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("data.hits.hits[i]._source.title.noteStmOfResponsibility")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("data.hits.hits[i]._source.title.noteStmOfResponsibility[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("data.hits.hits[i]._source.scisType")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("data.hits.hits[i]._source.scisType[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("data.hits.hits[i]._source.languageTermValue")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("data.hits.hits[i]._source.languageTermValue[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("data.hits.hits[i].sort")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("data.hits.hits[i].sort[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("data.hits.hits[i]._source.contributor.namePersonalOther")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("data.hits.hits[i]._source.contributor.namePersonalOther[j]")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("data.hits.hits[i]._source.contributor.nameCorporateOther")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_StrVal = loo_JResp.StringOf("data.hits.hits[i]._source.contributor.nameCorporateOther[j]")
        j = j + 1
    loop
    i = i + 1
loop


destroy loo_Http
destroy loo_SbQuery
destroy loo_SbUrl
destroy loo_SbResponseBody
destroy loo_JResp