Sample code for 30+ languages & platforms
PureBasic

Yousign: List Files

See more Yousign Examples

List Yousign files.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkHttp.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    success.i = 0

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; Implements the following CURL command:

    ; curl --location --request GET 'https://staging-api.yousign.com/files' \
    ; --header 'Authorization: Bearer YOUR_API_KEY' \
    ; --header 'Content-Type: application/json'

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

    ; Adds the "Authorization: Bearer YOUR_API_KEY" header.
    CkHttp::setCkAuthToken(http, "YOUR_API_KEY")
    CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkHttp::ckQuickGetSb(http,"https://staging-api.yousign.com/files",sbResponseBody)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(json,sbResponseBody)
    CkJsonObject::setCkEmitCompact(json, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(json)

    respStatusCode.i = CkHttp::ckLastStatus(http)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttp::ckLastHeader(http)
        Debug "Failed."
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

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

    ; {
    ;   "id": "\/files\/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    ;   "name": "abc.pdf",
    ;   "type": "signable",
    ;   "contentType": "application\/pdf",
    ;   "description": null,
    ;   "createdAt": "2020-05-27T09:14:12+02:00",
    ;   "updatedAt": "2020-05-27T09:14:12+02:00",
    ;   "sha256": "ea2a92b0eff5bebfa3ccd869fd61e27bb7fe973d0dff63f106d8b0d614469fa0",
    ;   "metadata": [
    ;   ],
    ;   "workspace": "\/workspaces\/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    ;   "creator": null,
    ;   "fileObjects": [
    ;   ],
    ;   "protected": false,
    ;   "position": 0,
    ;   "parent": null,
    ;   "fieldsCompatible": true,
    ;   "company": "\/companies\/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
    ; }

    ; Use the following online tool to generate parsing code from sample JSON:
    ; Generate Parsing Code from JSON

    id.s = CkJsonObject::ckStringOf(json,"id")
    name.s = CkJsonObject::ckStringOf(json,"name")
    v_type.s = CkJsonObject::ckStringOf(json,"type")
    contentType.s = CkJsonObject::ckStringOf(json,"contentType")
    description.s = CkJsonObject::ckStringOf(json,"description")
    createdAt.s = CkJsonObject::ckStringOf(json,"createdAt")
    updatedAt.s = CkJsonObject::ckStringOf(json,"updatedAt")
    sha256.s = CkJsonObject::ckStringOf(json,"sha256")
    workspace.s = CkJsonObject::ckStringOf(json,"workspace")
    creator.s = CkJsonObject::ckStringOf(json,"creator")
    v_protected.i = CkJsonObject::ckBoolOf(json,"protected")
    position.i = CkJsonObject::ckIntOf(json,"position")
    parent.s = CkJsonObject::ckStringOf(json,"parent")
    fieldsCompatible.i = CkJsonObject::ckBoolOf(json,"fieldsCompatible")
    company.s = CkJsonObject::ckStringOf(json,"company")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(json,"metadata")
    While i < count_i
        CkJsonObject::setCkI(json, i)
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(json,"fileObjects")
    While i < count_i
        CkJsonObject::setCkI(json, i)
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure