Create a client only needs firstName, email and phone. Every client must belong to a team, and it can also have an agent. If you don’t choose them, Estactics does.

A team is one level of your organization’s hierarchy, such as Sales or Team A. An agent is the user who owns the client.

The flow

Start at the top and stop at the first Yes.

POST /clients/create Did you send assignedToUserId? Yes Agent That user Team The team you sent, otherwise that agent's team No Did you send a campaignCode? Yes Agent The campaign's default agent, if it has one Team The team you sent, otherwise the campaign's team No Did you send assignedToHierarchyId? Yes Agent None Team The team you sent No Can the API key's user only see clients assigned to them? No hierarchy data access, not the owner, and on the client's brand Yes Agent The API key's user Team The API key's user's team No Agent None Team The API key's user's team If no team can be found The request fails with a 400 error

What each request gets

Each row applies only if the rows above it don’t.

You send Agent Team
assignedToUserId That user The team you sent, otherwise that agent’s team
campaignCode The campaign’s default agent, if it has one The team you sent, otherwise the campaign’s team
assignedToHierarchyId None The team you sent
None of these, and the API key’s user can only see clients assigned to them and is on the client’s brand The API key’s user The API key’s user’s team
None of these, with any other API key None The API key’s user’s team

If the agent you send has no team, the client goes to the API key’s user’s team.

When the API key’s user becomes the agent

A user without hierarchy data access can only see clients assigned to them. When such a user’s API key creates a client with no agent, campaign or team, the client is assigned to them so they can see it.

This doesn’t apply to the organization owner, who can see every client. It also needs the user to be on the client’s brand. If they aren’t, the client has no agent and they won’t see it.

Which brand the client gets

  1. With a campaignCode and no assignedToUserId, the client gets the campaign’s brand, even if you send brandId.
  2. Otherwise it gets the brandId you sent.
  3. If you sent neither, it gets your organization’s main brand.

Who can see the client

  • The organization owner.
  • The client’s agent.
  • Users with hierarchy data access who are on the client’s brand, when their team, or the team set as its data scope, is at or above the client’s team. When a client has an agent, the agent’s team counts as the client’s team.

Existing clients

This flow only applies to new clients. A returning client keeps their team and agent, even when you set throwErrorOnClientExists to false.

The agent of a new client gets an email about it, whichever way they were chosen.

Errors

Status When
400 No team can be found, because neither the agent nor the API key’s user has one
400 assignedToHierarchyId isn’t a team in your organization
400 brandId isn’t in your organization, or the API key’s user isn’t on it and isn’t the owner
400 The agent, including a campaign’s default agent, isn’t on the client’s brand
404 campaignCode doesn’t exist in your organization
404 assignedToUserId doesn’t exist