Chilkat Online Tools

unicodeC / New FreshBooks / Invite Team Member to Project(s)

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    // 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"
    //     }
    //   ]
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"capacity",L"manager");
    CkJsonObjectW_UpdateString(json,L"to_email",L"yourteammemberemail@freshbooks.com");
    CkJsonObjectW_UpdateInt(json,L"invitable_id",123);
    CkJsonObjectW_UpdateString(json,L"invitable_type",L"business");
    CkJsonObjectW_UpdateInt(json,L"groups[0].group_id",6360979);
    CkJsonObjectW_UpdateString(json,L"groups[0].capacity",L"manager");
    CkJsonObjectW_UpdateInt(json,L"groups[1].group_id",6360987);
    CkJsonObjectW_UpdateString(json,L"groups[1].capacity",L"manager");
    CkJsonObjectW_UpdateInt(json,L"groups[2].group_id",6360952);
    CkJsonObjectW_UpdateString(json,L"groups[2].capacity",L"manager");

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");
    CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");

    resp = CkHttpW_PostJson3(http,L"https://api.freshbooks.com/auth/api/v1/users/invitation",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);

    }

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": [
  ]
}