Chilkat Online Tools

SQL Server / New FreshBooks / Invite Team Member to Project(s)

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.

    -- {
    --   "capacity": "manager",
    --   "to_email": "yourteammemberemail@freshbooks.com",
    --   "invitable_id": 123,
    --   "invitable_type": "business",
    --   "groups": [
    --     {
    --       "group_id": 6360979,
    --       "capacity": "manager"
    --     },
    --     {
    --       "group_id": 6360987,
    --       "capacity": "manager"
    --     },
    --     {
    --       "group_id": 6360952,
    --       "capacity": "manager"
    --     }
    --   ]
    -- }

    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, 'capacity', 'manager'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'to_email', 'yourteammemberemail@freshbooks.com'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'invitable_id', 123
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'invitable_type', 'business'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'groups[0].group_id', 6360979
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'groups[0].capacity', 'manager'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'groups[1].group_id', 6360987
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'groups[1].capacity', 'manager'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'groups[2].group_id', 6360952
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'groups[2].capacity', 'manager'

    -- 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 @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://api.freshbooks.com/auth/api/v1/users/invitation', '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

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json


END
GO

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
	"capacity": "manager",
    "to_email": "yourteammemberemail@freshbooks.com",
    "invitable_id": {{businessid}},
    "invitable_type": "business",
    "groups": [
        {
            "group_id": 6360979,
            "capacity": "manager"
        },
        {
            "group_id": 6360987,
            "capacity": "manager"
        },
        {
            "group_id": 6360952,
            "capacity": "manager"
        }
    ]
}'
https://api.freshbooks.com/auth/api/v1/users/invitation

Postman Collection Item JSON

{
  "name": "Invite Team Member to Project(s)",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "type": "text",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n\t\"capacity\": \"manager\",\n    \"to_email\": \"yourteammemberemail@freshbooks.com\",\n    \"invitable_id\": {{businessid}},\n    \"invitable_type\": \"business\",\n    \"groups\": [\n        {\n            \"group_id\": 6360979,\n            \"capacity\": \"manager\"\n        },\n        {\n            \"group_id\": 6360987,\n            \"capacity\": \"manager\"\n        },\n        {\n            \"group_id\": 6360952,\n            \"capacity\": \"manager\"\n        }\n    ]\n}"
    },
    "url": {
      "raw": "https://api.freshbooks.com/auth/api/v1/users/invitation",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "auth",
        "api",
        "v1",
        "users",
        "invitation"
      ]
    }
  },
  "response": [
  ]
}