PowerBuilder / New FreshBooks / Add Business
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
oleobject loo_Date_format
integer li_Id
integer li_Group_id
string ls_Role
integer li_Identity_id
string ls_First_name
string ls_Last_name
string ls_Email
string ls_Company
integer li_Business_id
integer li_Unacknowledged_change
integer li_Active
integer li_Id
string ls_Name
string ls_Account_id
integer li_Business_groupId
string ls_Category
integer li_AddressId
string ls_Street
string ls_City
string ls_Province
string ls_Country
string ls_Postal_code
string ls_Phone_number
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.
// {
// "name": "Kevin's Corral",
// "date_format": "mm/dd/yyyy",
// "address_attributes": {
// "country": "Canada"
// },
// "phone_number_attributes": null
// }
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("name","Kevin's Corral")
loo_Json.UpdateString("date_format","mm/dd/yyyy")
loo_Json.UpdateString("address_attributes.country","Canada")
loo_Json.UpdateNull("phone_number_attributes")
// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"
loo_Http.SetRequestHeader("Content-Type","application/json")
loo_Resp = loo_Http.PostJson3("https://api.freshbooks.com/auth/api/v1/users/business","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
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_SbResponseBody
destroy loo_JResp
return
end if
destroy loo_Resp
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "response": {
// "id": 1986590,
// "name": "Kevin's Corral",
// "account_id": "lwy0vG",
// "business_group": {
// "id": 4977602,
// "category": "business",
// "members": [
// {
// "id": 6487912,
// "group_id": 4977602,
// "role": "owner",
// "identity_id": 37256,
// "first_name": "Marshall",
// "last_name": "Johnston",
// "email": "api.freshbooks@gmail.com",
// "company": "Kevin's Corral",
// "business_id": 1986590,
// "unacknowledged_change": false,
// "active": true
// }
// ]
// },
// "date_format": "mm/dd/yyyy",
// "address": {
// "id": 2448988,
// "street": null,
// "city": null,
// "province": null,
// "country": "Canada",
// "postal_code": null
// },
// "phone_number": null,
// "business_clients": [
// ]
// }
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
loo_Date_format = create oleobject
// Use "Chilkat_9_5_0.DtObj" for versions of Chilkat < 10.0.0
li_rc = loo_Date_format.ConnectToNewObject("Chilkat.DtObj")
li_Id = loo_JResp.IntOf("response.id")
ls_Name = loo_JResp.StringOf("response.name")
ls_Account_id = loo_JResp.StringOf("response.account_id")
li_Business_groupId = loo_JResp.IntOf("response.business_group.id")
ls_Category = loo_JResp.StringOf("response.business_group.category")
loo_JResp.DtOf("response.date_format",0,loo_Date_format)
li_AddressId = loo_JResp.IntOf("response.address.id")
ls_Street = loo_JResp.StringOf("response.address.street")
ls_City = loo_JResp.StringOf("response.address.city")
ls_Province = loo_JResp.StringOf("response.address.province")
ls_Country = loo_JResp.StringOf("response.address.country")
ls_Postal_code = loo_JResp.StringOf("response.address.postal_code")
ls_Phone_number = loo_JResp.StringOf("response.phone_number")
i = 0
li_Count_i = loo_JResp.SizeOfArray("response.business_group.members")
do while i < li_Count_i
loo_JResp.I = i
li_Id = loo_JResp.IntOf("response.business_group.members[i].id")
li_Group_id = loo_JResp.IntOf("response.business_group.members[i].group_id")
ls_Role = loo_JResp.StringOf("response.business_group.members[i].role")
li_Identity_id = loo_JResp.IntOf("response.business_group.members[i].identity_id")
ls_First_name = loo_JResp.StringOf("response.business_group.members[i].first_name")
ls_Last_name = loo_JResp.StringOf("response.business_group.members[i].last_name")
ls_Email = loo_JResp.StringOf("response.business_group.members[i].email")
ls_Company = loo_JResp.StringOf("response.business_group.members[i].company")
li_Business_id = loo_JResp.IntOf("response.business_group.members[i].business_id")
li_Unacknowledged_change = loo_JResp.BoolOf("response.business_group.members[i].unacknowledged_change")
li_Active = loo_JResp.BoolOf("response.business_group.members[i].active")
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("response.business_clients")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp
destroy loo_Date_format
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-H "Content-Type: application/json"
-d '{
"name": "Kevin\'s Corral",
"date_format": "mm/dd/yyyy",
"address_attributes": {
"country": "Canada"
},
"phone_number_attributes": null
}'
https://api.freshbooks.com/auth/api/v1/users/business
Postman Collection Item JSON
{
"name": "Add Business",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"Kevin's Corral\",\n \"date_format\": \"mm/dd/yyyy\",\n \"address_attributes\": {\n \"country\": \"Canada\"\n },\n \"phone_number_attributes\": null\n}"
},
"url": {
"raw": "https://api.freshbooks.com/auth/api/v1/users/business",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"auth",
"api",
"v1",
"users",
"business"
]
}
},
"response": [
{
"name": "Add Business",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"Kevin's Corral\",\n \"date_format\": \"mm/dd/yyyy\",\n \"address_attributes\": {\n \"country\": \"Canada\"\n },\n \"phone_number_attributes\": null\n}"
},
"url": {
"raw": "https://my.freshbooks.com/service/api/auth/api/v1/users/business",
"protocol": "https",
"host": [
"my",
"freshbooks",
"com"
],
"path": [
"service",
"api",
"auth",
"api",
"v1",
"users",
"business"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "nginx"
},
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-Download-Options",
"value": "noopen"
},
{
"key": "X-Permitted-Cross-Domain-Policies",
"value": "none"
},
{
"key": "Referrer-Policy",
"value": "strict-origin-when-cross-origin"
},
{
"key": "ETag",
"value": "W/\"ece9403d440d4badd777fca953dd9580\""
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "X-Request-Id",
"value": "49e5ba95-b7dc-42c7-b0c3-8d61d99d1f39"
},
{
"key": "X-Runtime",
"value": "0.670145"
},
{
"key": "X-NewRelic-App-Data",
"value": "PxQBWV5TCBABVlVSBAUHUFQTGhEhCQ0WQg1UDl1KG39aAV0NVBZSEAEZZQAFCBdyUxAIDVl1XhUUUEJQClxZMF8XTAtWXw4IYQpMFVQyVhZLVVYNCkEUAx5UTVIZBwBXVgUEBFNVWlAIUApQDxQZAx9HDlIAVQpQBQBUV1AFXFUBXUM/"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Expires",
"value": "Wed, 25 Apr 2018 16:51:20 GMT"
},
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Via",
"value": "1.1 google"
},
{
"key": "Via",
"value": "1.1 varnish"
},
{
"key": "Transfer-Encoding",
"value": "chunked"
},
{
"key": "Accept-Ranges",
"value": "bytes"
},
{
"key": "Date",
"value": "Thu, 25 Apr 2019 16:51:20 GMT"
},
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "X-Served-By",
"value": "cache-mdw17366-MDW"
},
{
"key": "X-Cache",
"value": "MISS"
},
{
"key": "X-Cache-Hits",
"value": "0"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "Country",
"value": "CA"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=31536000; includeSubDomains; preload"
}
],
"cookie": [
],
"body": "{\n \"response\": {\n \"id\": 1986590,\n \"name\": \"Kevin's Corral\",\n \"account_id\": \"lwy0vG\",\n \"business_group\": {\n \"id\": 4977602,\n \"category\": \"business\",\n \"members\": [\n {\n \"id\": 6487912,\n \"group_id\": 4977602,\n \"role\": \"owner\",\n \"identity_id\": 37256,\n \"first_name\": \"Marshall\",\n \"last_name\": \"Johnston\",\n \"email\": \"api.freshbooks@gmail.com\",\n \"company\": \"Kevin's Corral\",\n \"business_id\": 1986590,\n \"unacknowledged_change\": false,\n \"active\": true\n }\n ]\n },\n \"date_format\": \"mm/dd/yyyy\",\n \"address\": {\n \"id\": 2448988,\n \"street\": null,\n \"city\": null,\n \"province\": null,\n \"country\": \"Canada\",\n \"postal_code\": null\n },\n \"phone_number\": null,\n \"business_clients\": []\n }\n}"
}
]
}