unicodeCpp / Support API / Create Trial Account
Back to Collection Items
#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttpW http;
bool success;
http.put_BasicAuth(true);
http.put_Login(L"login");
http.put_Password(L"password");
http.SetRequestHeader(L"Accept",L"application/json");
CkHttpResponseW *resp = http.QuickRequest(L"POST",L"https://example.zendesk.com/api/v2/accounts");
if (http.get_LastMethodSuccess() == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
CkStringBuilderW sbResponseBody;
resp->GetBodySb(sbResponseBody);
CkJsonObjectW jResp;
jResp.LoadSb(sbResponseBody);
jResp.put_EmitCompact(false);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",jResp.emit());
int respStatusCode = resp->get_StatusCode();
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",resp->header());
wprintf(L"Failed.\n");
delete resp;
return;
}
delete resp;
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "account": {
// "name": "<string>",
// "subdomain": "<string>",
// "url": "<string>"
// }
// }
// 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 wchar_t *Name = jResp.stringOf(L"account.name");
const wchar_t *Subdomain = jResp.stringOf(L"account.subdomain");
const wchar_t *v_Url = jResp.stringOf(L"account.url");
}
Curl Command
curl -u login:password -X POST
-H "Accept: application/json"
https://example.zendesk.com/api/v2/accounts
Postman Collection Item JSON
{
"name": "Create Trial Account",
"request": {
"method": "POST",
"header": [
{
"key": "Accept",
"value": "application/json"
}
],
"url": {
"raw": "{{baseUrl}}/api/v2/accounts",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"accounts"
]
}
},
"response": [
{
"name": "Created response",
"originalRequest": {
"method": "POST",
"header": [
{
"description": "Added as a part of security scheme: basic",
"key": "Authorization",
"value": "Basic <credentials>"
}
],
"url": {
"raw": "{{baseUrl}}/api/v2/accounts",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v2",
"accounts"
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"account\": {\n \"name\": \"<string>\",\n \"subdomain\": \"<string>\",\n \"url\": \"<string>\"\n }\n}"
}
]
}