Chilkat Online Tools

C / Sunshine Conversations API / Get App

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkStringBuilder sbResponseBody;
    HCkJsonObject jResp;
    int respStatusCode;
    const char *Id;
    const char *DisplayName;
    int ConversationRetentionSeconds;
    BOOL MaskCreditCardNumbers;
    BOOL UseAnimalNames;
    BOOL EchoPostback;
    BOOL IgnoreAutoConversationStart;
    BOOL MultiConvoEnabled;
    const char *AttachmentsAccess;
    int AttachmentsTokenExpirationSeconds;
    const char *Lang;

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

    http = CkHttp_Create();

    CkHttp_putBasicAuth(http,TRUE);
    CkHttp_putLogin(http,"username");
    CkHttp_putPassword(http,"password");

    sbResponseBody = CkStringBuilder_Create();
    success = CkHttp_QuickGetSb(http,"https://domain.com/",sbResponseBody);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObject_Create();
    CkJsonObject_LoadSb(jResp,sbResponseBody);
    CkJsonObject_putEmitCompact(jResp,FALSE);

    printf("Response Body:\n");
    printf("%s\n",CkJsonObject_emit(jResp));

    respStatusCode = CkHttp_getLastStatus(http);
    printf("Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        printf("Response Header:\n");
        printf("%s\n",CkHttp_lastHeader(http));
        printf("Failed.\n");
        CkHttp_Dispose(http);
        CkStringBuilder_Dispose(sbResponseBody);
        CkJsonObject_Dispose(jResp);
        return;
    }

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

    // {
    //   "app": {
    //     "id": "5d8cff3cd55b040010928b5b",
    //     "displayName": "utoc",
    //     "settings": {
    //       "conversationRetentionSeconds": 35855812,
    //       "maskCreditCardNumbers": true,
    //       "useAnimalNames": false,
    //       "echoPostback": true,
    //       "ignoreAutoConversationStart": true,
    //       "multiConvoEnabled": true,
    //       "attachmentsAccess": "public",
    //       "attachmentsTokenExpirationSeconds": 64028
    //     },
    //     "metadata": {
    //       "lang": "en-ca"
    //     }
    //   }
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    Id = CkJsonObject_stringOf(jResp,"app.id");
    DisplayName = CkJsonObject_stringOf(jResp,"app.displayName");
    ConversationRetentionSeconds = CkJsonObject_IntOf(jResp,"app.settings.conversationRetentionSeconds");
    MaskCreditCardNumbers = CkJsonObject_BoolOf(jResp,"app.settings.maskCreditCardNumbers");
    UseAnimalNames = CkJsonObject_BoolOf(jResp,"app.settings.useAnimalNames");
    EchoPostback = CkJsonObject_BoolOf(jResp,"app.settings.echoPostback");
    IgnoreAutoConversationStart = CkJsonObject_BoolOf(jResp,"app.settings.ignoreAutoConversationStart");
    MultiConvoEnabled = CkJsonObject_BoolOf(jResp,"app.settings.multiConvoEnabled");
    AttachmentsAccess = CkJsonObject_stringOf(jResp,"app.settings.attachmentsAccess");
    AttachmentsTokenExpirationSeconds = CkJsonObject_IntOf(jResp,"app.settings.attachmentsTokenExpirationSeconds");
    Lang = CkJsonObject_stringOf(jResp,"app.metadata.lang");


    CkHttp_Dispose(http);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jResp);

    }

Curl Command

curl -X GET
	-u 'username:password'
https://domain.com/

Postman Collection Item JSON

{
  "name": "Get App",
  "_postman_id": "b6b38388-b3be-454f-aca6-f0624470ea02",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": "{{url}}/v2/apps/{{appId}}",
    "description": "Fetches an individual app."
  },
  "response": [
    {
      "id": "12c94751-e245-4540-8c81-865dccad09d5",
      "name": "Ok",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId"
          ],
          "variable": [
            {
              "key": "appId"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"app\": {\n  \"id\": \"5d8cff3cd55b040010928b5b\",\n  \"displayName\": \"utoc\",\n  \"settings\": {\n   \"conversationRetentionSeconds\": 35855812,\n   \"maskCreditCardNumbers\": true,\n   \"useAnimalNames\": false,\n   \"echoPostback\": true,\n   \"ignoreAutoConversationStart\": true,\n   \"multiConvoEnabled\": true,\n   \"attachmentsAccess\": \"public\",\n   \"attachmentsTokenExpirationSeconds\": 64028\n  },\n  \"metadata\": {\n   \"lang\": \"en-ca\"\n  }\n }\n}"
    },
    {
      "id": "8aa1f69d-ba23-420b-ae3f-870557fcf2ce",
      "name": "App not found",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: bearer",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "Bearer <token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/v2/apps/:appId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "v2",
            "apps",
            ":appId"
          ],
          "variable": [
            {
              "key": "appId"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}