Back to Collection Items
#include <CkHttp.h>
#include <CkStringBuilder.h>
#include <CkJsonObject.h>
void ChilkatSample(void)
{
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http;
bool success;
http.SetRequestHeader("Authorization","");
CkStringBuilder sbResponseBody;
success = http.QuickGetSb("https://api.squadcast.com/v3users/:userID",sbResponseBody);
if (success == false) {
std::cout << http.lastErrorText() << "\r\n";
return;
}
CkJsonObject jResp;
jResp.LoadSb(sbResponseBody);
jResp.put_EmitCompact(false);
std::cout << "Response Body:" << "\r\n";
std::cout << jResp.emit() << "\r\n";
int respStatusCode = http.get_LastStatus();
std::cout << "Response Status Code = " << respStatusCode << "\r\n";
if (respStatusCode >= 400) {
std::cout << "Response Header:" << "\r\n";
std::cout << http.lastHeader() << "\r\n";
std::cout << "Failed." << "\r\n";
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "data": {
// "id": "5d81d9187000fb6b9def7e31",
// "first_name": "Manigandan",
// "last_name": "Dharmalingam",
// "email": "manigandan@squadcast.com",
// "contact": {
// "dial_code": "+91",
// "phone_number": "9578628779"
// },
// "secondary_emails": [
// ],
// "email_verified": true,
// "time_zone": "Asia/Calcutta",
// "title": "",
// "bio": "",
// "notification_rules": [
// {
// "type": "Email",
// "time": 0
// },
// {
// "type": "Push",
// "time": 0
// },
// {
// "type": "SMS",
// "time": 1
// },
// {
// "type": "Phone",
// "time": 2
// }
// ],
// "user_image": false
// }
// }
// 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.
const char *v_type = 0;
int time;
const char *Id = jResp.stringOf("data.id");
const char *First_name = jResp.stringOf("data.first_name");
const char *Last_name = jResp.stringOf("data.last_name");
const char *v_Email = jResp.stringOf("data.email");
const char *Dial_code = jResp.stringOf("data.contact.dial_code");
const char *Phone_number = jResp.stringOf("data.contact.phone_number");
bool Email_verified = jResp.BoolOf("data.email_verified");
const char *Time_zone = jResp.stringOf("data.time_zone");
const char *Title = jResp.stringOf("data.title");
const char *Bio = jResp.stringOf("data.bio");
bool User_image = jResp.BoolOf("data.user_image");
int i = 0;
int count_i = jResp.SizeOfArray("data.secondary_emails");
while (i < count_i) {
jResp.put_I(i);
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray("data.notification_rules");
while (i < count_i) {
jResp.put_I(i);
v_type = jResp.stringOf("data.notification_rules[i].type");
time = jResp.IntOf("data.notification_rules[i].time");
i = i + 1;
}
}
Curl Command
curl -X GET
-H "Authorization: "
https://api.squadcast.com/v3users/:userID
Postman Collection Item JSON
{
"name": "Get User By ID",
"request": {
"auth": {
"type": "noauth"
},
"method": "GET",
"header": [
{
"key": "Authorization",
"value": ""
}
],
"url": {
"raw": "{{baseUrl}}users/:userID",
"host": [
"{{baseUrl}}users"
],
"path": [
":userID"
],
"variable": [
{
"key": "userID",
"value": "<string>",
"type": "string",
"description": "(Required) user id"
}
]
},
"description": "Returns a users details of the given `userID` in the request param.\nRequires `access_token` as a `Bearer {{token}}` in the `Authorization` header with `read` scope."
},
"response": [
{
"name": "Unauthorized",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/users/:userID",
"host": [
"{{baseUrl}}"
],
"path": [
"users",
":userID"
],
"variable": [
{
"key": "userID"
}
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"meta\": {\n \"status\": \"<integer>\",\n \"error_message\": \"<string>\"\n }\n}"
},
{
"name": "OK",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/users/:userID",
"host": [
"{{baseUrl}}"
],
"path": [
"users",
":userID"
],
"variable": [
{
"key": "userID"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"data\": {\n \"id\": \"5d81d9187000fb6b9def7e31\",\n \"first_name\": \"Manigandan\",\n \"last_name\": \"Dharmalingam\",\n \"email\": \"manigandan@squadcast.com\",\n \"contact\": {\n \"dial_code\": \"+91\",\n \"phone_number\": \"9578628779\"\n },\n \"secondary_emails\": [],\n \"email_verified\": true,\n \"time_zone\": \"Asia/Calcutta\",\n \"title\": \"\",\n \"bio\": \"\",\n \"notification_rules\": [\n {\n \"type\": \"Email\",\n \"time\": 0\n },\n {\n \"type\": \"Push\",\n \"time\": 0\n },\n {\n \"type\": \"SMS\",\n \"time\": 1\n },\n {\n \"type\": \"Phone\",\n \"time\": 2\n }\n ],\n \"user_image\": false\n }\n}"
},
{
"name": "Not Found",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/users/:userID",
"host": [
"{{baseUrl}}"
],
"path": [
"users",
":userID"
],
"variable": [
{
"key": "userID"
}
]
}
},
"status": "Not Found",
"code": 404,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"meta\": {\n \"status\": \"<integer>\",\n \"error_message\": \"<string>\"\n }\n}"
},
{
"name": "Internal Server Error",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/users/:userID",
"host": [
"{{baseUrl}}"
],
"path": [
"users",
":userID"
],
"variable": [
{
"key": "userID"
}
]
}
},
"status": "Internal Server Error",
"code": 500,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"meta\": {\n \"status\": \"<integer>\",\n \"error_message\": \"<string>\"\n }\n}"
},
{
"name": "Forbidden",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/users/:userID",
"host": [
"{{baseUrl}}"
],
"path": [
"users",
":userID"
],
"variable": [
{
"key": "userID"
}
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"meta\": {\n \"status\": \"<integer>\",\n \"error_message\": \"<string>\"\n }\n}"
}
]
}