Chilkat Online Tools

Objective-C / New FreshBooks / Invite Team Member to Project(s)

Back to Collection Items

#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoHttpResponse.h>

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

CkoHttp *http = [[CkoHttp alloc] init];
BOOL success;

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

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"capacity" value: @"manager"];
[json UpdateString: @"to_email" value: @"yourteammemberemail@freshbooks.com"];
[json UpdateInt: @"invitable_id" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"invitable_type" value: @"business"];
[json UpdateInt: @"groups[0].group_id" value: [NSNumber numberWithInt: 6360979]];
[json UpdateString: @"groups[0].capacity" value: @"manager"];
[json UpdateInt: @"groups[1].group_id" value: [NSNumber numberWithInt: 6360987]];
[json UpdateString: @"groups[1].capacity" value: @"manager"];
[json UpdateInt: @"groups[2].group_id" value: [NSNumber numberWithInt: 6360952]];
[json UpdateString: @"groups[2].capacity" value: @"manager"];

// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = @"<access_token>";
[http SetRequestHeader: @"Content-Type" value: @"application/json"];

CkoHttpResponse *resp = [http PostJson3: @"https://api.freshbooks.com/auth/api/v1/users/invitation" contentType: @"application/json" json: json];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

NSLog(@"%d",[resp.StatusCode intValue]);
NSLog(@"%@",resp.BodyStr);

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