Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
DECLARE @sbResponseBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://api.freshbooks.com/accounting/account/{{accountId}}/users/staffs/{{staffId}}', @sbResponseBody
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
RETURN
END
DECLARE @jResp int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT
EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @jResp, 'EmitCompact', 0
PRINT 'Response Body:'
EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
PRINT @sTmp0
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "response": {
-- "result": {
-- "staff": {
-- "accounting_systemid": "wkMd2g",
-- "api_token": "9249ac8633763523fe614cdeb28787b9",
-- "bus_phone": "",
-- "currency_code": null,
-- "display_name": "RyenMarr",
-- "email": "api.freshbooks@gmail.com",
-- "fax": "",
-- "fname": "Ryen",
-- "home_phone": null,
-- "id": 1,
-- "language": "en",
-- "last_login": null,
-- "level": 3,
-- "lname": "Marr",
-- "mob_phone": "",
-- "note": null,
-- "num_logins": 0,
-- "organization": "Postman Sandbox",
-- "p_city": "",
-- "p_code": "",
-- "p_country": "",
-- "p_province": "",
-- "p_street": "",
-- "p_street2": "",
-- "rate": null,
-- "role": "admin",
-- "signup_date": "2019-04-18 09:14:53",
-- "updated": "2019-04-24 14:37:58",
-- "userid": 1,
-- "username": "api.freshbooks@gmail.com",
-- "vis_state": 0
-- }
-- }
-- }
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @Accounting_systemid nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Accounting_systemid OUT, 'response.result.staff.accounting_systemid'
DECLARE @Api_token nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Api_token OUT, 'response.result.staff.api_token'
DECLARE @Bus_phone nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Bus_phone OUT, 'response.result.staff.bus_phone'
DECLARE @Currency_code nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Currency_code OUT, 'response.result.staff.currency_code'
DECLARE @Display_name nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Display_name OUT, 'response.result.staff.display_name'
DECLARE @v_Email nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @v_Email OUT, 'response.result.staff.email'
DECLARE @Fax nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Fax OUT, 'response.result.staff.fax'
DECLARE @Fname nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Fname OUT, 'response.result.staff.fname'
DECLARE @Home_phone nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Home_phone OUT, 'response.result.staff.home_phone'
DECLARE @Id int
EXEC sp_OAMethod @jResp, 'IntOf', @Id OUT, 'response.result.staff.id'
DECLARE @Language nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Language OUT, 'response.result.staff.language'
DECLARE @Last_login nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Last_login OUT, 'response.result.staff.last_login'
DECLARE @Level int
EXEC sp_OAMethod @jResp, 'IntOf', @Level OUT, 'response.result.staff.level'
DECLARE @Lname nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Lname OUT, 'response.result.staff.lname'
DECLARE @Mob_phone nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Mob_phone OUT, 'response.result.staff.mob_phone'
DECLARE @Note nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Note OUT, 'response.result.staff.note'
DECLARE @Num_logins int
EXEC sp_OAMethod @jResp, 'IntOf', @Num_logins OUT, 'response.result.staff.num_logins'
DECLARE @Organization nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Organization OUT, 'response.result.staff.organization'
DECLARE @P_city nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @P_city OUT, 'response.result.staff.p_city'
DECLARE @P_code nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @P_code OUT, 'response.result.staff.p_code'
DECLARE @P_country nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @P_country OUT, 'response.result.staff.p_country'
DECLARE @P_province nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @P_province OUT, 'response.result.staff.p_province'
DECLARE @P_street nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @P_street OUT, 'response.result.staff.p_street'
DECLARE @P_street2 nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @P_street2 OUT, 'response.result.staff.p_street2'
DECLARE @Rate nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Rate OUT, 'response.result.staff.rate'
DECLARE @Role nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Role OUT, 'response.result.staff.role'
DECLARE @Signup_date nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Signup_date OUT, 'response.result.staff.signup_date'
DECLARE @Updated nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Updated OUT, 'response.result.staff.updated'
DECLARE @Userid int
EXEC sp_OAMethod @jResp, 'IntOf', @Userid OUT, 'response.result.staff.userid'
DECLARE @Username nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Username OUT, 'response.result.staff.username'
DECLARE @Vis_state int
EXEC sp_OAMethod @jResp, 'IntOf', @Vis_state OUT, 'response.result.staff.vis_state'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -X GET
-H "Authorization: Bearer <access_token>"
-H "Content-Type: application/json"
https://api.freshbooks.com/accounting/account/{{accountId}}/users/staffs/{{staffId}}
Postman Collection Item JSON
{
"name": "Single Staff",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/users/staffs/{{staffId}}",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"users",
"staffs",
"{{staffId}}"
]
}
},
"response": [
{
"name": "Single Staff",
"originalRequest": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/users/staffs/{{staffId}}",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"users",
"staffs",
"{{staffId}}"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "nginx"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "X-NewRelic-App-Data",
"value": "PxQBWV5TCBABVlVSAwEOVlcTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4DFVdfRgFPCkNFR0gRQlNBEVwQFlEEXkAUCBgCHVQOVQBUAlpdAQNSVlcJCglWTU8GHRUEUFIGUAEAAVJRBgpaXFxQEB8DWA1CBG4="
},
{
"key": "X-RateLimit-Limit",
"value": "20"
},
{
"key": "X-RateLimit-Remaining",
"value": "0"
},
{
"key": "X-RateLimit-Reset",
"value": "1557346267"
},
{
"key": "Retry-After",
"value": "54"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Expires",
"value": "Tue, 08 May 2018 20:10:12 GMT"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"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": "Transfer-Encoding",
"value": "chunked"
},
{
"key": "Date",
"value": "Wed, 08 May 2019 20:10:12 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": "Vary",
"value": "Accept-Encoding"
},
{
"key": "Country",
"value": "CA"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=31536000; includeSubDomains; preload"
}
],
"cookie": [
],
"body": "{\n \"response\": {\n \"result\": {\n \"staff\": {\n \"accounting_systemid\": \"wkMd2g\",\n \"api_token\": \"9249ac8633763523fe614cdeb28787b9\",\n \"bus_phone\": \"\",\n \"currency_code\": null,\n \"display_name\": \"RyenMarr\",\n \"email\": \"api.freshbooks@gmail.com\",\n \"fax\": \"\",\n \"fname\": \"Ryen\",\n \"home_phone\": null,\n \"id\": 1,\n \"language\": \"en\",\n \"last_login\": null,\n \"level\": 3,\n \"lname\": \"Marr\",\n \"mob_phone\": \"\",\n \"note\": null,\n \"num_logins\": 0,\n \"organization\": \"Postman Sandbox\",\n \"p_city\": \"\",\n \"p_code\": \"\",\n \"p_country\": \"\",\n \"p_province\": \"\",\n \"p_street\": \"\",\n \"p_street2\": \"\",\n \"rate\": null,\n \"role\": \"admin\",\n \"signup_date\": \"2019-04-18 09:14:53\",\n \"updated\": \"2019-04-24 14:37:58\",\n \"userid\": 1,\n \"username\": \"api.freshbooks@gmail.com\",\n \"vis_state\": 0\n }\n }\n }\n}"
}
]
}