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
DECLARE @iTmp0 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
-- Use this online tool to generate code from sample JSON: Generate Code to Create JSON
-- The following JSON is sent in the request body.
-- {
-- "bill_vendor": {
-- "vendor_name": "IKEA",
-- "primary_contact_first_name": "Jimmy",
-- "primary_contact_last_name": "McNamara",
-- "primary_contact_email": "jmcnamara@ikea.com",
-- "primary_contact": null,
-- "street": "332 Carlton Ave.",
-- "street2": null,
-- "city": "San Francisco",
-- "province": "California",
-- "postal_code": null,
-- "country": "United States",
-- "account_number": "45454545",
-- "phone": "4158859378",
-- "website": "ikea.com",
-- "currency_code": "USD",
-- "language": "en",
-- "is_1099": false,
-- "tax_defaults": [
-- ]
-- }
-- }
DECLARE @json int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'bill_vendor.vendor_name', 'IKEA'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'bill_vendor.primary_contact_first_name', 'Jimmy'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'bill_vendor.primary_contact_last_name', 'McNamara'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'bill_vendor.primary_contact_email', 'jmcnamara@ikea.com'
EXEC sp_OAMethod @json, 'UpdateNull', @success OUT, 'bill_vendor.primary_contact'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'bill_vendor.street', '332 Carlton Ave.'
EXEC sp_OAMethod @json, 'UpdateNull', @success OUT, 'bill_vendor.street2'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'bill_vendor.city', 'San Francisco'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'bill_vendor.province', 'California'
EXEC sp_OAMethod @json, 'UpdateNull', @success OUT, 'bill_vendor.postal_code'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'bill_vendor.country', 'United States'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'bill_vendor.account_number', '45454545'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'bill_vendor.phone', '4158859378'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'bill_vendor.website', 'ikea.com'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'bill_vendor.currency_code', 'USD'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'bill_vendor.language', 'en'
EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'bill_vendor.is_1099', 0
EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'bill_vendor.tax_defaults'
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
DECLARE @resp int
EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors', 'application/json', @json
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
RETURN
END
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 @resp, 'GetBodySb', @success OUT, @sbResponseBody
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 @resp, 'StatusCode', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
RETURN
END
EXEC @hr = sp_OADestroy @resp
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "response": {
-- "result": {
-- "bill_vendor": {
-- "account_number": "45454545",
-- "city": "San Francisco",
-- "country": "United States",
-- "created_at": "2020-10-09 15:25:05",
-- "currency_code": "USD",
-- "is_1099": false,
-- "language": "en",
-- "outstanding_balance": [
-- ],
-- "overdue_balance": [
-- ],
-- "phone": "4158859378",
-- "postal_code": null,
-- "primary_contact_email": "jmcnamara@ikea.com",
-- "primary_contact_first_name": "Jimmy",
-- "primary_contact_last_name": "McNamara",
-- "province": "California",
-- "street": "332 Carlton Ave.",
-- "street2": null,
-- "tax_defaults": [
-- ],
-- "updated_at": "2020-10-09 15:25:05",
-- "vendor_name": "IKEA",
-- "vendorid": 5,
-- "vis_state": 0,
-- "website": "ikea.com"
-- }
-- }
-- }
-- }
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @Account_number nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Account_number OUT, 'response.result.bill_vendor.account_number'
DECLARE @City nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @City OUT, 'response.result.bill_vendor.city'
DECLARE @Country nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Country OUT, 'response.result.bill_vendor.country'
DECLARE @Created_at nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Created_at OUT, 'response.result.bill_vendor.created_at'
DECLARE @Currency_code nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Currency_code OUT, 'response.result.bill_vendor.currency_code'
DECLARE @Is_1099 int
EXEC sp_OAMethod @jResp, 'BoolOf', @Is_1099 OUT, 'response.result.bill_vendor.is_1099'
DECLARE @Language nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Language OUT, 'response.result.bill_vendor.language'
DECLARE @Phone nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Phone OUT, 'response.result.bill_vendor.phone'
DECLARE @Postal_code nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Postal_code OUT, 'response.result.bill_vendor.postal_code'
DECLARE @Primary_contact_email nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Primary_contact_email OUT, 'response.result.bill_vendor.primary_contact_email'
DECLARE @Primary_contact_first_name nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Primary_contact_first_name OUT, 'response.result.bill_vendor.primary_contact_first_name'
DECLARE @Primary_contact_last_name nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Primary_contact_last_name OUT, 'response.result.bill_vendor.primary_contact_last_name'
DECLARE @Province nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Province OUT, 'response.result.bill_vendor.province'
DECLARE @Street nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Street OUT, 'response.result.bill_vendor.street'
DECLARE @Street2 nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Street2 OUT, 'response.result.bill_vendor.street2'
DECLARE @Updated_at nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Updated_at OUT, 'response.result.bill_vendor.updated_at'
DECLARE @Vendor_name nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Vendor_name OUT, 'response.result.bill_vendor.vendor_name'
DECLARE @Vendorid int
EXEC sp_OAMethod @jResp, 'IntOf', @Vendorid OUT, 'response.result.bill_vendor.vendorid'
DECLARE @Vis_state int
EXEC sp_OAMethod @jResp, 'IntOf', @Vis_state OUT, 'response.result.bill_vendor.vis_state'
DECLARE @Website nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Website OUT, 'response.result.bill_vendor.website'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'response.result.bill_vendor.outstanding_balance'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
SELECT @i = @i + 1
END
SELECT @i = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'response.result.bill_vendor.overdue_balance'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
SELECT @i = @i + 1
END
SELECT @i = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'response.result.bill_vendor.tax_defaults'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '{
"bill_vendor": {
"vendor_name": "IKEA",
"primary_contact_first_name": "Jimmy",
"primary_contact_last_name": "McNamara",
"primary_contact_email": "jmcnamara@ikea.com",
"primary_contact": null,
"street": "332 Carlton Ave.",
"street2": null,
"city": "San Francisco",
"province": "California",
"postal_code": null,
"country": "United States",
"account_number": "45454545",
"phone": "4158859378",
"website": "ikea.com",
"currency_code": "USD",
"language": "en",
"is_1099": false,
"tax_defaults": []
}
}'
https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors
Postman Collection Item JSON
{
"name": "Add Vendor",
"request": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"bill_vendor\": {\n \"vendor_name\": \"IKEA\",\n \"primary_contact_first_name\": \"Jimmy\",\n \"primary_contact_last_name\": \"McNamara\",\n \"primary_contact_email\": \"jmcnamara@ikea.com\",\n \"primary_contact\": null,\n \"street\": \"332 Carlton Ave.\",\n \"street2\": null,\n \"city\": \"San Francisco\",\n \"province\": \"California\",\n \"postal_code\": null,\n \"country\": \"United States\",\n \"account_number\": \"45454545\",\n \"phone\": \"4158859378\",\n \"website\": \"ikea.com\",\n \"currency_code\": \"USD\",\n \"language\": \"en\",\n \"is_1099\": false,\n \"tax_defaults\": []\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"bill_vendors",
"bill_vendors"
]
}
},
"response": [
{
"name": "Add Vendor",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"bill_vendor\": {\n \"vendor_name\": \"IKEA\",\n \"primary_contact_first_name\": \"Jimmy\",\n \"primary_contact_last_name\": \"McNamara\",\n \"primary_contact_email\": \"jmcnamara@ikea.com\",\n \"primary_contact\": null,\n \"street\": \"332 Carlton Ave.\",\n \"street2\": null,\n \"city\": \"San Francisco\",\n \"province\": \"California\",\n \"postal_code\": null,\n \"country\": \"United States\",\n \"account_number\": \"45454545\",\n \"phone\": \"4158859378\",\n \"website\": \"ikea.com\",\n \"currency_code\": \"USD\",\n \"language\": \"en\",\n \"is_1099\": false,\n \"tax_defaults\": []\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"bill_vendors",
"bill_vendors"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "nginx"
},
{
"key": "Date",
"value": "Fri, 09 Oct 2020 15:25:05 GMT"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "X-NewRelic-App-Data",
"value": "PxQBWV5TCBABVlVSAwEOVlcTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4DFVdfRgFPCkNFR0gGWFpfPRAGDFQNShECWl1eXxNcD1UOQRFGGgdNVk0LBwVTVVUOBQBQXQMOBFNXT1QFUxRACl5RBQRRDwMAVwRbVFJSVkRPXlJcFwQ/"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "Content-Security-Policy",
"value": "default-src 'self'"
},
{
"key": "X-Content-Security-Policy",
"value": "default-src 'self'"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=31556926; includeSubDomains; preload"
},
{
"key": "Referrer-Policy",
"value": "strict-origin-when-cross-origin"
},
{
"key": "X-RateLimit-Limit",
"value": "600"
},
{
"key": "X-RateLimit-Remaining",
"value": "599"
},
{
"key": "X-RateLimit-Reset",
"value": "1602257165"
},
{
"key": "Retry-After",
"value": "59"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Via",
"value": "1.1 google"
},
{
"key": "Alt-Svc",
"value": "h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\""
},
{
"key": "Transfer-Encoding",
"value": "chunked"
}
],
"cookie": [
],
"body": "{\n \"response\": {\n \"result\": {\n \"bill_vendor\": {\n \"account_number\": \"45454545\",\n \"city\": \"San Francisco\",\n \"country\": \"United States\",\n \"created_at\": \"2020-10-09 15:25:05\",\n \"currency_code\": \"USD\",\n \"is_1099\": false,\n \"language\": \"en\",\n \"outstanding_balance\": [],\n \"overdue_balance\": [],\n \"phone\": \"4158859378\",\n \"postal_code\": null,\n \"primary_contact_email\": \"jmcnamara@ikea.com\",\n \"primary_contact_first_name\": \"Jimmy\",\n \"primary_contact_last_name\": \"McNamara\",\n \"province\": \"California\",\n \"street\": \"332 Carlton Ave.\",\n \"street2\": null,\n \"tax_defaults\": [],\n \"updated_at\": \"2020-10-09 15:25:05\",\n \"vendor_name\": \"IKEA\",\n \"vendorid\": 5,\n \"vis_state\": 0,\n \"website\": \"ikea.com\"\n }\n }\n }\n}"
}
]
}