PowerBuilder / New FreshBooks / Update Project
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_SbRequestBody
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
integer li_Id
integer li_Identity_id
string ls_Role
string ls_First_name
string ls_Last_name
string ls_Email
string ls_Company
integer li_Active
string ls_Name
integer li_Value
integer li_Id
string ls_Title
string ls_Description
string ls_Due_date
integer li_Client_id
integer li_Internal
string ls_Budget
string ls_Fixed_price
string ls_Rate
string ls_Billing_method
string ls_Project_type
integer li_Active
integer li_Complete
integer li_Sample
string ls_Created_at
string ls_Updated_at
string ls_Logged_duration
string ls_Billed_amount
string ls_Billed_status
string ls_Retainer_id
integer li_GroupId
integer i
integer li_Count_i
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// 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
// }
// }
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("project.title","K2 Hiking Guide")
loo_Json.UpdateString("project.due_date","2019-04-20")
loo_Json.UpdateInt("project.client_id",123)
// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"
loo_Http.SetRequestHeader("Content-Type","application/json")
loo_SbRequestBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Json.EmitSb(loo_SbRequestBody)
loo_Resp = loo_Http.PTextSb("PUT","https://api.freshbooks.com/projects/business/{{businessId}}/projects/{{projectId}}",loo_SbRequestBody,"utf-8","application/json",0,0)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody
return
end if
loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Resp
destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
destroy loo_Resp
// 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
li_Id = loo_JResp.IntOf("project.id")
ls_Title = loo_JResp.StringOf("project.title")
ls_Description = loo_JResp.StringOf("project.description")
ls_Due_date = loo_JResp.StringOf("project.due_date")
li_Client_id = loo_JResp.IntOf("project.client_id")
li_Internal = loo_JResp.BoolOf("project.internal")
ls_Budget = loo_JResp.StringOf("project.budget")
ls_Fixed_price = loo_JResp.StringOf("project.fixed_price")
ls_Rate = loo_JResp.StringOf("project.rate")
ls_Billing_method = loo_JResp.StringOf("project.billing_method")
ls_Project_type = loo_JResp.StringOf("project.project_type")
li_Active = loo_JResp.BoolOf("project.active")
li_Complete = loo_JResp.BoolOf("project.complete")
li_Sample = loo_JResp.BoolOf("project.sample")
ls_Created_at = loo_JResp.StringOf("project.created_at")
ls_Updated_at = loo_JResp.StringOf("project.updated_at")
ls_Logged_duration = loo_JResp.StringOf("project.logged_duration")
ls_Billed_amount = loo_JResp.StringOf("project.billed_amount")
ls_Billed_status = loo_JResp.StringOf("project.billed_status")
ls_Retainer_id = loo_JResp.StringOf("project.retainer_id")
li_GroupId = loo_JResp.IntOf("project.group.id")
i = 0
li_Count_i = loo_JResp.SizeOfArray("project.services")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("project.group.members")
do while i < li_Count_i
loo_JResp.I = i
li_Id = loo_JResp.IntOf("project.group.members[i].id")
li_Identity_id = loo_JResp.IntOf("project.group.members[i].identity_id")
ls_Role = loo_JResp.StringOf("project.group.members[i].role")
ls_First_name = loo_JResp.StringOf("project.group.members[i].first_name")
ls_Last_name = loo_JResp.StringOf("project.group.members[i].last_name")
ls_Email = loo_JResp.StringOf("project.group.members[i].email")
ls_Company = loo_JResp.StringOf("project.group.members[i].company")
li_Active = loo_JResp.BoolOf("project.group.members[i].active")
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("project.group.pending_invitations")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("abilities")
do while i < li_Count_i
loo_JResp.I = i
ls_Name = loo_JResp.StringOf("abilities[i].name")
li_Value = loo_JResp.BoolOf("abilities[i].value")
i = i + 1
loop
destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_SbResponseBody
destroy loo_JResp
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}"
}
]
}