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;
int business_id;
int id;
const char *name;
BOOL billable;
int vis_state;
int identity_id;
const char *role;
const char *first_name;
const char *last_name;
const char *email;
const char *company;
BOOL active;
BOOL value;
int Id;
const char *Title;
const char *Description;
const char *Due_date;
int Client_id;
BOOL Internal;
const char *Budget;
const char *Fixed_price;
const char *Rate;
const char *Billing_method;
const char *Project_type;
BOOL Active;
BOOL Complete;
BOOL Sample;
const char *Created_at;
const char *Updated_at;
const char *Logged_duration;
const char *Billed_amount;
const char *Billed_status;
const char *Retainer_id;
int GroupId;
int i;
int count_i;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,"<access_token>");
sbResponseBody = CkStringBuilder_Create();
success = CkHttp_QuickGetSb(http,"https://api.freshbooks.com/projects/business/{{businessId}}/projects/{{projectId}}",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)
// {
// "project": {
// "id": 2976412,
// "title": "Very Custom Computer thing",
// "description": null,
// "due_date": null,
// "client_id": 31006,
// "internal": false,
// "budget": null,
// "fixed_price": null,
// "rate": null,
// "billing_method": "project_rate",
// "project_type": "fixed_price",
// "active": true,
// "complete": false,
// "sample": false,
// "created_at": "2019-04-18T13:43:31",
// "updated_at": "2019-04-18T13:43:31",
// "logged_duration": null,
// "services": [
// {
// "business_id": 1966214,
// "id": 3575792,
// "name": "Computer Hardware",
// "billable": true,
// "vis_state": 0
// }
// ],
// "billed_amount": "0.00",
// "billed_status": "unbilled",
// "retainer_id": null,
// "group": {
// "id": 4942784,
// "members": [
// {
// "id": 6446258,
// "identity_id": 1882548,
// "role": "owner",
// "first_name": "Ryan",
// "last_name": "Marr",
// "email": "api.freshbooks@freshbooks.com",
// "company": "Postman Sandbox",
// "active": true
// }
// ],
// "pending_invitations": [
// ]
// }
// },
// "abilities": [
// {
// "name": "can_edit",
// "value": true
// },
// {
// "name": "can_archive",
// "value": true
// },
// {
// "name": "can_generate_invoice",
// "value": true
// },
// {
// "name": "can_delete",
// "value": true
// },
// {
// "name": "can_invite_team_member",
// "value": true
// },
// {
// "name": "can_manage_services",
// "value": true
// },
// {
// "name": "can_edit_hourly_budget",
// "value": true
// },
// {
// "name": "can_view_fixed_price",
// "value": true
// },
// {
// "name": "can_edit_fixed_price",
// "value": true
// },
// {
// "name": "can_edit_end_date",
// "value": true
// },
// {
// "name": "can_edit_flat_rate",
// "value": true
// },
// {
// "name": "can_edit_project_type",
// "value": true
// },
// {
// "name": "can_edit_title",
// "value": true
// },
// {
// "name": "can_view_review_tab",
// "value": true
// },
// {
// "name": "can_view_discuss_tab",
// "value": false
// },
// {
// "name": "can_track_time",
// "value": true
// },
// {
// "name": "can_create_comment",
// "value": true
// }
// ]
// }
// 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_IntOf(jResp,"project.id");
Title = CkJsonObject_stringOf(jResp,"project.title");
Description = CkJsonObject_stringOf(jResp,"project.description");
Due_date = CkJsonObject_stringOf(jResp,"project.due_date");
Client_id = CkJsonObject_IntOf(jResp,"project.client_id");
Internal = CkJsonObject_BoolOf(jResp,"project.internal");
Budget = CkJsonObject_stringOf(jResp,"project.budget");
Fixed_price = CkJsonObject_stringOf(jResp,"project.fixed_price");
Rate = CkJsonObject_stringOf(jResp,"project.rate");
Billing_method = CkJsonObject_stringOf(jResp,"project.billing_method");
Project_type = CkJsonObject_stringOf(jResp,"project.project_type");
Active = CkJsonObject_BoolOf(jResp,"project.active");
Complete = CkJsonObject_BoolOf(jResp,"project.complete");
Sample = CkJsonObject_BoolOf(jResp,"project.sample");
Created_at = CkJsonObject_stringOf(jResp,"project.created_at");
Updated_at = CkJsonObject_stringOf(jResp,"project.updated_at");
Logged_duration = CkJsonObject_stringOf(jResp,"project.logged_duration");
Billed_amount = CkJsonObject_stringOf(jResp,"project.billed_amount");
Billed_status = CkJsonObject_stringOf(jResp,"project.billed_status");
Retainer_id = CkJsonObject_stringOf(jResp,"project.retainer_id");
GroupId = CkJsonObject_IntOf(jResp,"project.group.id");
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"project.services");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
business_id = CkJsonObject_IntOf(jResp,"project.services[i].business_id");
id = CkJsonObject_IntOf(jResp,"project.services[i].id");
name = CkJsonObject_stringOf(jResp,"project.services[i].name");
billable = CkJsonObject_BoolOf(jResp,"project.services[i].billable");
vis_state = CkJsonObject_IntOf(jResp,"project.services[i].vis_state");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"project.group.members");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
id = CkJsonObject_IntOf(jResp,"project.group.members[i].id");
identity_id = CkJsonObject_IntOf(jResp,"project.group.members[i].identity_id");
role = CkJsonObject_stringOf(jResp,"project.group.members[i].role");
first_name = CkJsonObject_stringOf(jResp,"project.group.members[i].first_name");
last_name = CkJsonObject_stringOf(jResp,"project.group.members[i].last_name");
email = CkJsonObject_stringOf(jResp,"project.group.members[i].email");
company = CkJsonObject_stringOf(jResp,"project.group.members[i].company");
active = CkJsonObject_BoolOf(jResp,"project.group.members[i].active");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"project.group.pending_invitations");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"abilities");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
name = CkJsonObject_stringOf(jResp,"abilities[i].name");
value = CkJsonObject_BoolOf(jResp,"abilities[i].value");
i = i + 1;
}
CkHttp_Dispose(http);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}
Curl Command
curl -X GET
-H "Authorization: Bearer <access_token>"
https://api.freshbooks.com/projects/business/{{businessId}}/projects/{{projectId}}
Postman Collection Item JSON
{
"name": "Single Project",
"request": {
"method": "GET",
"header": [
],
"url": {
"raw": "https://api.freshbooks.com/projects/business/{{businessId}}/projects/{{projectId}}",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"projects",
"business",
"{{businessId}}",
"projects",
"{{projectId}}"
]
}
},
"response": [
{
"name": "Single Project",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "https://api.freshbooks.com/projects/business/{{businessId}}/projects/{{projectId}}",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"projects",
"business",
"{{businessId}}",
"projects",
"{{projectId}}"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "nginx"
},
{
"key": "Content-Type",
"value": "application/vnd.api+json"
},
{
"key": "X-Version",
"value": "1905.7.0"
},
{
"key": "X-NewRelic-App-Data",
"value": "PxQBWV5TCBABVllUBAQOU10TGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4FDFZFVRYSBxlDUhULRERQBxVNEkINUgdbTBpAVhZWFEMCVlgURFgLAwBMERxUTVIZAAFUXAIBBFZVVFcJUw1XCg8YHwJJG1hUUABaBwcHVFMFDVEEUFVAG1dWChdUaw=="
},
{
"key": "X-RateLimit-Limit",
"value": "20"
},
{
"key": "X-RateLimit-Remaining",
"value": "14"
},
{
"key": "X-RateLimit-Reset",
"value": "1557345999"
},
{
"key": "Retry-After",
"value": "60"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Expires",
"value": "Tue, 08 May 2018 20:05:38 GMT"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Via",
"value": "1.1 google"
},
{
"key": "Via",
"value": "1.1 varnish"
},
{
"key": "Accept-Ranges",
"value": "bytes"
},
{
"key": "Accept-Ranges",
"value": "bytes"
},
{
"key": "Age",
"value": "0"
},
{
"key": "Age",
"value": "0"
},
{
"key": "Content-Length",
"value": "1653"
},
{
"key": "Date",
"value": "Wed, 08 May 2019 20:05:38 GMT"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "X-Served-By",
"value": "cache-mdw17361-MDW"
},
{
"key": "X-Cache",
"value": "MISS"
},
{
"key": "X-Cache-Hits",
"value": "0"
},
{
"key": "Country",
"value": "CA"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=31536000; includeSubDomains; preload"
}
],
"cookie": [
],
"body": "{\n \"project\": {\n \"id\": 2976412,\n \"title\": \"Very Custom Computer thing\",\n \"description\": null,\n \"due_date\": null,\n \"client_id\": 31006,\n \"internal\": false,\n \"budget\": null,\n \"fixed_price\": null,\n \"rate\": null,\n \"billing_method\": \"project_rate\",\n \"project_type\": \"fixed_price\",\n \"active\": true,\n \"complete\": false,\n \"sample\": false,\n \"created_at\": \"2019-04-18T13:43:31\",\n \"updated_at\": \"2019-04-18T13:43:31\",\n \"logged_duration\": null,\n \"services\": [\n {\n \"business_id\": 1966214,\n \"id\": 3575792,\n \"name\": \"Computer Hardware\",\n \"billable\": true,\n \"vis_state\": 0\n }\n ],\n \"billed_amount\": \"0.00\",\n \"billed_status\": \"unbilled\",\n \"retainer_id\": null,\n \"group\": {\n \"id\": 4942784,\n \"members\": [\n {\n \"id\": 6446258,\n \"identity_id\": 1882548,\n \"role\": \"owner\",\n \"first_name\": \"Ryan\",\n \"last_name\": \"Marr\",\n \"email\": \"api.freshbooks@freshbooks.com\",\n \"company\": \"Postman Sandbox\",\n \"active\": true\n }\n ],\n \"pending_invitations\": []\n }\n },\n \"abilities\": [\n {\n \"name\": \"can_edit\",\n \"value\": true\n },\n {\n \"name\": \"can_archive\",\n \"value\": true\n },\n {\n \"name\": \"can_generate_invoice\",\n \"value\": true\n },\n {\n \"name\": \"can_delete\",\n \"value\": true\n },\n {\n \"name\": \"can_invite_team_member\",\n \"value\": true\n },\n {\n \"name\": \"can_manage_services\",\n \"value\": true\n },\n {\n \"name\": \"can_edit_hourly_budget\",\n \"value\": true\n },\n {\n \"name\": \"can_view_fixed_price\",\n \"value\": true\n },\n {\n \"name\": \"can_edit_fixed_price\",\n \"value\": true\n },\n {\n \"name\": \"can_edit_end_date\",\n \"value\": true\n },\n {\n \"name\": \"can_edit_flat_rate\",\n \"value\": true\n },\n {\n \"name\": \"can_edit_project_type\",\n \"value\": true\n },\n {\n \"name\": \"can_edit_title\",\n \"value\": true\n },\n {\n \"name\": \"can_view_review_tab\",\n \"value\": true\n },\n {\n \"name\": \"can_view_discuss_tab\",\n \"value\": false\n },\n {\n \"name\": \"can_track_time\",\n \"value\": true\n },\n {\n \"name\": \"can_create_comment\",\n \"value\": true\n }\n ]\n}"
}
]
}