1

When creating a client via the API, how do we assign the Client+ role to them and assign them to a project? I've created a script which redirects users to projects based on their email address.

The client is created, but I believe can only be assigned the role of Client (no client+ role exists). The additional client plus permissions come from custom permission: manage tasks, from what I can see in the database.

When I include this permission, the client is never created.

This is my code to create client:

    $payload = [
        "type" => "Client",
        "first_name" => $first_name,
        "last_name" => $last_name,
        "email" => $email,
        "password" => $this->rand_string(15),
        "company_id" => $company,
    ];

    $result = $this->client->post("/users", $payload);
    $result_json = $result->getJson();
    $client_id = @$result_json['single']['id'];

    $payload = [
        "id" => $project,
        "members" => array(
            $client_id
        ),
    ];
    $result = $this->client->post("/projects", $payload);

The client gets created, although without the right permissions, and the client is never added to the project (which means they can't make a task against it).

Ilija
  • 4,105
  • 4
  • 32
  • 46
adamk
  • 370
  • 4
  • 13

1 Answers1

0

Client+ is a regular Client instance, with extra permissions. These extra permissions are set using custom permissions property. Note that this works only if Client+ is enabled in Add-Ons section of the app.

Apparently, POST-ing to /users API breaks, but you can use regular invitation route and POST on /users/invite API end-point with this payload:

$payload = [
    "role" => "Client",
    "custom_permissions" => ["can_manage_tasks"],
    "email_addresses" => [$email],
    "company_id" => $company_id,
    "project_ids" : [1, 2, 3],
];

to invite users with Client+ permissions.

Ilija
  • 4,105
  • 4
  • 32
  • 46
  • No luck. JSON response is null. Client doesn't get created. – adamk Sep 14 '16 at 06:22
  • any other suggestions? – adamk Sep 16 '16 at 09:24
  • Corrected the example. – Ilija Sep 16 '16 at 21:53
  • Still no good with "custom_permissions" => ["can_manage_tasks"], Otherwise works without it to the /users/invite path. – adamk Sep 17 '16 at 00:38
  • Now it appears the emails to the address created discussions, not tickets (assuming because the Client+ role isn't available). – adamk Sep 17 '16 at 00:41
  • Double check and make sure that you have Client+ add-on enabled. I copy-pasted payload that frontend sends to the backend. It needs to work. – Ilija Sep 20 '16 at 14:07
  • Without this, it will create a normal client. however it won't create a Client+. "custom_permissions" => ["can_manage_tasks"], – adamk Nov 06 '16 at 02:28
  • Have also confirmed Client+ is enabled. – adamk Nov 06 '16 at 02:32
  • The response back is: private 'raw_response' => string '' (length=0) private 'is_json' => null private 'json_loaded' => boolean false private 'json' => null – adamk Nov 06 '16 at 02:33
  • Having to resort to " $sql = "UPDATE users SET raw_additional_properties='a:1:{s:18:\"custom_permissions\";a:1:{i:0;s:16:\"can_manage_tasks\";}}' WHERE id=$userID"; "as a work around. – adamk Nov 06 '16 at 03:07