Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Handle hoJson
Variant vSbRequestBody
Handle hoSbRequestBody
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
Integer iId
Integer iIdentity_id
String sRole
String sFirst_name
String sLast_name
String sEmail
String sCompany
Boolean iActive
String sName
Boolean iValue
Integer iId
String sTitle
String sDescription
String sDue_date
Integer iClient_id
Boolean iInternal
String sBudget
String sFixed_price
String sRate
String sBilling_method
String sProject_type
Boolean iActive
Boolean iComplete
Boolean iSample
String sCreated_at
String sUpdated_at
String sLogged_duration
String sBilled_amount
String sBilled_status
String sRetainer_id
Integer iGroupId
Integer i
Integer iCount_i
String sTemp1
Boolean bTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "project": {
// "title": "K2 Hiking Guide",
// "due_date": "2019-04-20",
// "client_id": 123
// }
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "project.title" "K2 Hiking Guide" To iSuccess
Get ComUpdateString Of hoJson "project.due_date" "2019-04-20" To iSuccess
Get ComUpdateInt Of hoJson "project.client_id" 123 To iSuccess
// Adds the "Authorization: Bearer <access_token>" header.
Set ComAuthToken Of hoHttp To "<access_token>"
Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
Send CreateComObject of hoSbRequestBody
End
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get ComEmitSb Of hoJson vSbRequestBody To iSuccess
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get ComPTextSb Of hoHttp "PUT" "https://api.freshbooks.com/projects/business/{{businessId}}/projects/{{projectId}}" vSbRequestBody "utf-8" "application/json" False False To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJResp To False
Showln "Response Body:"
Get ComEmit Of hoJResp To sTemp1
Showln sTemp1
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Send Destroy of hoResp
Procedure_Return
End
Send Destroy of hoResp
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "project": {
// "id": 3018266,
// "title": "K2 Hiking Guide",
// "description": null,
// "due_date": "2019-04-20",
// "client_id": 31006,
// "internal": false,
// "budget": null,
// "fixed_price": "3000.00",
// "rate": null,
// "billing_method": null,
// "project_type": "fixed_price",
// "active": true,
// "complete": false,
// "sample": false,
// "created_at": "2019-05-08T20:06:55",
// "updated_at": "2019-05-08T20:07:37",
// "logged_duration": null,
// "services": [
// ],
// "billed_amount": "0.00",
// "billed_status": "unbilled",
// "retainer_id": null,
// "group": {
// "id": 5049390,
// "members": [
// {
// "id": 6578346,
// "identity_id": 37256,
// "role": "owner",
// "first_name": "Marshall",
// "last_name": "Johnston",
// "email": "api.freshbooks@gmail.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": true
// },
// {
// "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
Get ComIntOf Of hoJResp "project.id" To iId
Get ComStringOf Of hoJResp "project.title" To sTitle
Get ComStringOf Of hoJResp "project.description" To sDescription
Get ComStringOf Of hoJResp "project.due_date" To sDue_date
Get ComIntOf Of hoJResp "project.client_id" To iClient_id
Get ComBoolOf Of hoJResp "project.internal" To iInternal
Get ComStringOf Of hoJResp "project.budget" To sBudget
Get ComStringOf Of hoJResp "project.fixed_price" To sFixed_price
Get ComStringOf Of hoJResp "project.rate" To sRate
Get ComStringOf Of hoJResp "project.billing_method" To sBilling_method
Get ComStringOf Of hoJResp "project.project_type" To sProject_type
Get ComBoolOf Of hoJResp "project.active" To iActive
Get ComBoolOf Of hoJResp "project.complete" To iComplete
Get ComBoolOf Of hoJResp "project.sample" To iSample
Get ComStringOf Of hoJResp "project.created_at" To sCreated_at
Get ComStringOf Of hoJResp "project.updated_at" To sUpdated_at
Get ComStringOf Of hoJResp "project.logged_duration" To sLogged_duration
Get ComStringOf Of hoJResp "project.billed_amount" To sBilled_amount
Get ComStringOf Of hoJResp "project.billed_status" To sBilled_status
Get ComStringOf Of hoJResp "project.retainer_id" To sRetainer_id
Get ComIntOf Of hoJResp "project.group.id" To iGroupId
Move 0 To i
Get ComSizeOfArray Of hoJResp "project.services" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "project.group.members" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComIntOf Of hoJResp "project.group.members[i].id" To iId
Get ComIntOf Of hoJResp "project.group.members[i].identity_id" To iIdentity_id
Get ComStringOf Of hoJResp "project.group.members[i].role" To sRole
Get ComStringOf Of hoJResp "project.group.members[i].first_name" To sFirst_name
Get ComStringOf Of hoJResp "project.group.members[i].last_name" To sLast_name
Get ComStringOf Of hoJResp "project.group.members[i].email" To sEmail
Get ComStringOf Of hoJResp "project.group.members[i].company" To sCompany
Get ComBoolOf Of hoJResp "project.group.members[i].active" To iActive
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "project.group.pending_invitations" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "abilities" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "abilities[i].name" To sName
Get ComBoolOf Of hoJResp "abilities[i].value" To iValue
Move (i + 1) To i
Loop
End_Procedure
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
-H "Content-Type: application/json"
-d '{
"project": {
"title": "K2 Hiking Guide",
"due_date": "2019-04-20",
"client_id": {{customerId}}
}
}'
https://api.freshbooks.com/projects/business/{{businessId}}/projects/{{projectId}}
Postman Collection Item JSON
{
"name": "Update Project",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"project\": {\n \"title\": \"K2 Hiking Guide\",\n \"due_date\": \"2019-04-20\",\n \"client_id\": {{customerId}}\n }\n}"
},
"url": {
"raw": "https://api.freshbooks.com/projects/business/{{businessId}}/projects/{{projectId}}",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"projects",
"business",
"{{businessId}}",
"projects",
"{{projectId}}"
]
},
"description": "Update project with project title. \n\n*`client_id` in this case is `customerId`*"
},
"response": [
{
"name": "Update Project",
"originalRequest": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"project\": {\n \"title\": \"K2 Hiking Guide\",\n \"due_date\": \"2019-04-20\",\n \"client_id\": {{customerId}}\n }\n}"
},
"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": "PxQBWV5TCBABVllUBAQOU10TGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4FDFZFVRYSBxlDUhULRERQBxVNEkINUgdbTBpAVhZWFEMCVlgURFgLAwBMERxUTVIZAwRfVQYGBFpfVFMIVApVAQsYAwNSFUMEUlVSVFNUVF5aWgcEUwAAFR1RBwhCU24="
},
{
"key": "X-RateLimit-Limit",
"value": "20"
},
{
"key": "X-RateLimit-Remaining",
"value": "9"
},
{
"key": "X-RateLimit-Reset",
"value": "1557346118"
},
{
"key": "Retry-After",
"value": "60"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Expires",
"value": "Tue, 08 May 2018 20:07:37 GMT"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Via",
"value": "1.1 google"
},
{
"key": "Via",
"value": "1.1 varnish"
},
{
"key": "Content-Length",
"value": "1552"
},
{
"key": "Accept-Ranges",
"value": "bytes"
},
{
"key": "Date",
"value": "Wed, 08 May 2019 20:07:37 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\": 3018266,\n \"title\": \"K2 Hiking Guide\",\n \"description\": null,\n \"due_date\": \"2019-04-20\",\n \"client_id\": 31006,\n \"internal\": false,\n \"budget\": null,\n \"fixed_price\": \"3000.00\",\n \"rate\": null,\n \"billing_method\": null,\n \"project_type\": \"fixed_price\",\n \"active\": true,\n \"complete\": false,\n \"sample\": false,\n \"created_at\": \"2019-05-08T20:06:55\",\n \"updated_at\": \"2019-05-08T20:07:37\",\n \"logged_duration\": null,\n \"services\": [],\n \"billed_amount\": \"0.00\",\n \"billed_status\": \"unbilled\",\n \"retainer_id\": null,\n \"group\": {\n \"id\": 5049390,\n \"members\": [\n {\n \"id\": 6578346,\n \"identity_id\": 37256,\n \"role\": \"owner\",\n \"first_name\": \"Marshall\",\n \"last_name\": \"Johnston\",\n \"email\": \"api.freshbooks@gmail.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\": true\n },\n {\n \"name\": \"can_track_time\",\n \"value\": true\n },\n {\n \"name\": \"can_create_comment\",\n \"value\": true\n }\n ]\n}"
}
]
}