Chilkat Online Tools

SQL Server / New FreshBooks / Get System

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
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.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
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://api.freshbooks.com/accounting/account/{{accountId}}/systems/systems/{{businessId}}', @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
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.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": {
    --       "system": {
    --         "accountid": "wkMd2g",
    --         "active": true,
    --         "auto_bill": 5,
    --         "billing_status": "uptodate",
    --         "bus_phone": "",
    --         "business_type": null,
    --         "business_uuid": null,
    --         "city": "",
    --         "code": "",
    --         "country": "Canada",
    --         "currency_code": "USD",
    --         "date": "2019-04-18 09:14:53",
    --         "discountid": null,
    --         "dst": true,
    --         "duration": 12,
    --         "email": "api.freshbooks@gmail.com",
    --         "fax": "",
    --         "gst_amount": {
    --           "amount": "0.00",
    --           "code": "USD"
    --         },
    --         "heard_about_us_via": null,
    --         "id": 4236410,
    --         "info_email": "api.freshbooks@gmail.com",
    --         "ip": "62.205.194.4",
    --         "landing_url": null,
    --         "masterlock_billing": true,
    --         "migrated_to_smux_at": null,
    --         "mob_phone": "",
    --         "modern_system": true,
    --         "name": "Postman Sandbox",
    --         "num_clients": null,
    --         "num_staff": null,
    --         "payment_amount": {
    --           "amount": "0.00",
    --           "code": "USD"
    --         },
    --         "payment_frequency": 1,
    --         "province": "",
    --         "referralid": "multibiz",
    --         "referring_url": null,
    --         "salutation": null,
    --         "size_limit": null,
    --         "split_token": null,
    --         "street": "",
    --         "street2": null,
    --         "systemid": 4236410,
    --         "test_system": false,
    --         "timezone": "UTC",
    --         "timezoneid": 14,
    --         "vat_name": null,
    --         "vat_number": null
    --       }
    --     }
    --   }
    -- }

    -- Sample code for parsing the JSON response...
    -- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    DECLARE @Accountid nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Accountid OUT, 'response.result.system.accountid'
    DECLARE @Active int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Active OUT, 'response.result.system.active'
    DECLARE @Auto_bill int
    EXEC sp_OAMethod @jResp, 'IntOf', @Auto_bill OUT, 'response.result.system.auto_bill'
    DECLARE @Billing_status nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Billing_status OUT, 'response.result.system.billing_status'
    DECLARE @Bus_phone nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Bus_phone OUT, 'response.result.system.bus_phone'
    DECLARE @Business_type nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Business_type OUT, 'response.result.system.business_type'
    DECLARE @Business_uuid nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Business_uuid OUT, 'response.result.system.business_uuid'
    DECLARE @City nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @City OUT, 'response.result.system.city'
    DECLARE @Code nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Code OUT, 'response.result.system.code'
    DECLARE @Country nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Country OUT, 'response.result.system.country'
    DECLARE @Currency_code nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Currency_code OUT, 'response.result.system.currency_code'
    DECLARE @Date nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Date OUT, 'response.result.system.date'
    DECLARE @Discountid nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Discountid OUT, 'response.result.system.discountid'
    DECLARE @Dst int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Dst OUT, 'response.result.system.dst'
    DECLARE @Duration int
    EXEC sp_OAMethod @jResp, 'IntOf', @Duration OUT, 'response.result.system.duration'
    DECLARE @v_Email nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Email OUT, 'response.result.system.email'
    DECLARE @Fax nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Fax OUT, 'response.result.system.fax'
    DECLARE @Amount nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Amount OUT, 'response.result.system.gst_amount.amount'
    DECLARE @Gst_amountCode nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Gst_amountCode OUT, 'response.result.system.gst_amount.code'
    DECLARE @Heard_about_us_via nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Heard_about_us_via OUT, 'response.result.system.heard_about_us_via'
    DECLARE @Id int
    EXEC sp_OAMethod @jResp, 'IntOf', @Id OUT, 'response.result.system.id'
    DECLARE @Info_email nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Info_email OUT, 'response.result.system.info_email'
    DECLARE @Ip nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Ip OUT, 'response.result.system.ip'
    DECLARE @Landing_url nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Landing_url OUT, 'response.result.system.landing_url'
    DECLARE @Masterlock_billing int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Masterlock_billing OUT, 'response.result.system.masterlock_billing'
    DECLARE @Migrated_to_smux_at nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Migrated_to_smux_at OUT, 'response.result.system.migrated_to_smux_at'
    DECLARE @Mob_phone nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Mob_phone OUT, 'response.result.system.mob_phone'
    DECLARE @Modern_system int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Modern_system OUT, 'response.result.system.modern_system'
    DECLARE @Name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'response.result.system.name'
    DECLARE @Num_clients nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Num_clients OUT, 'response.result.system.num_clients'
    DECLARE @Num_staff nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Num_staff OUT, 'response.result.system.num_staff'
    DECLARE @Payment_amountAmount nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Payment_amountAmount OUT, 'response.result.system.payment_amount.amount'
    DECLARE @Payment_amountCode nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Payment_amountCode OUT, 'response.result.system.payment_amount.code'
    DECLARE @Payment_frequency int
    EXEC sp_OAMethod @jResp, 'IntOf', @Payment_frequency OUT, 'response.result.system.payment_frequency'
    DECLARE @Province nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Province OUT, 'response.result.system.province'
    DECLARE @Referralid nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Referralid OUT, 'response.result.system.referralid'
    DECLARE @Referring_url nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Referring_url OUT, 'response.result.system.referring_url'
    DECLARE @Salutation nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Salutation OUT, 'response.result.system.salutation'
    DECLARE @Size_limit nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Size_limit OUT, 'response.result.system.size_limit'
    DECLARE @Split_token nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Split_token OUT, 'response.result.system.split_token'
    DECLARE @Street nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Street OUT, 'response.result.system.street'
    DECLARE @Street2 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Street2 OUT, 'response.result.system.street2'
    DECLARE @Systemid int
    EXEC sp_OAMethod @jResp, 'IntOf', @Systemid OUT, 'response.result.system.systemid'
    DECLARE @Test_system int
    EXEC sp_OAMethod @jResp, 'BoolOf', @Test_system OUT, 'response.result.system.test_system'
    DECLARE @Timezone nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Timezone OUT, 'response.result.system.timezone'
    DECLARE @Timezoneid int
    EXEC sp_OAMethod @jResp, 'IntOf', @Timezoneid OUT, 'response.result.system.timezoneid'
    DECLARE @Vat_name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Vat_name OUT, 'response.result.system.vat_name'
    DECLARE @Vat_number nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Vat_number OUT, 'response.result.system.vat_number'

    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}}/systems/systems/{{businessId}}

Postman Collection Item JSON

{
  "name": "Get System ",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json",
        "type": "text"
      }
    ],
    "url": {
      "raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/systems/systems/{{businessId}}",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "accounting",
        "account",
        "{{accountId}}",
        "systems",
        "systems",
        "{{businessId}}"
      ]
    },
    "description": "The value of `<id>` here is only meaningful if a user has access to multiple systems. See the Identity Model for more information."
  },
  "response": [
    {
      "name": "Get System ",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json",
            "type": "text"
          }
        ],
        "url": {
          "raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/systems/systems/{{businessId}}",
          "protocol": "https",
          "host": [
            "api",
            "freshbooks",
            "com"
          ],
          "path": [
            "accounting",
            "account",
            "{{accountId}}",
            "systems",
            "systems",
            "{{businessId}}"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "nginx"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "X-NewRelic-App-Data",
          "value": "PxQBWV5TCBABVlVSAwEOVlcTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4DFVdfRgFPCkNFR0gXSEVHBwsQWEMbSxZdVRYeA0kJTwFZC1VXAgRZXlANAgRQUVYEHRpXSBNUVlBfBwAFAQlUDw8GVwFUG01XAF8RAWs="
        },
        {
          "key": "Access-Control-Allow-Origin",
          "value": "*"
        },
        {
          "key": "Expires",
          "value": "Tue, 24 Apr 2018 18:38:32 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, 24 Apr 2019 18:38:32 GMT"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "X-Served-By",
          "value": "cache-mdw17369-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            \"system\": {\n                \"accountid\": \"wkMd2g\",\n                \"active\": true,\n                \"auto_bill\": 5,\n                \"billing_status\": \"uptodate\",\n                \"bus_phone\": \"\",\n                \"business_type\": null,\n                \"business_uuid\": null,\n                \"city\": \"\",\n                \"code\": \"\",\n                \"country\": \"Canada\",\n                \"currency_code\": \"USD\",\n                \"date\": \"2019-04-18 09:14:53\",\n                \"discountid\": null,\n                \"dst\": true,\n                \"duration\": 12,\n                \"email\": \"api.freshbooks@gmail.com\",\n                \"fax\": \"\",\n                \"gst_amount\": {\n                    \"amount\": \"0.00\",\n                    \"code\": \"USD\"\n                },\n                \"heard_about_us_via\": null,\n                \"id\": 4236410,\n                \"info_email\": \"api.freshbooks@gmail.com\",\n                \"ip\": \"62.205.194.4\",\n                \"landing_url\": null,\n                \"masterlock_billing\": true,\n                \"migrated_to_smux_at\": null,\n                \"mob_phone\": \"\",\n                \"modern_system\": true,\n                \"name\": \"Postman Sandbox\",\n                \"num_clients\": null,\n                \"num_staff\": null,\n                \"payment_amount\": {\n                    \"amount\": \"0.00\",\n                    \"code\": \"USD\"\n                },\n                \"payment_frequency\": 1,\n                \"province\": \"\",\n                \"referralid\": \"multibiz\",\n                \"referring_url\": null,\n                \"salutation\": null,\n                \"size_limit\": null,\n                \"split_token\": null,\n                \"street\": \"\",\n                \"street2\": null,\n                \"systemid\": 4236410,\n                \"test_system\": false,\n                \"timezone\": \"UTC\",\n                \"timezoneid\": 14,\n                \"vat_name\": null,\n                \"vat_number\": null\n            }\n        }\n    }\n}"
    }
  ]
}