|
| 1 | +--- |
| 2 | +group: graphql |
| 3 | +title: createCompanyUser mutation |
| 4 | +contributor_name: Atwix |
| 5 | +contributor_link: https://www.atwix.com/ |
| 6 | +b2b_only: true |
| 7 | +--- |
| 8 | + |
| 9 | +Use the `createCompanyUser` mutation to create a new company user or add a user from the existing customer for your company. |
| 10 | + |
| 11 | +The `target_id` input attribute allows you to specify which node in the company structure will be the parent node of the company user. If you do not specify a value, the user will be assigned to the top-level (root) node of the company structure. |
| 12 | + |
| 13 | +You can get the `target_id` and the `role_id` with the [`company`]({{page.baseurl}}/graphql/queries/company.html) query. |
| 14 | + |
| 15 | +## Syntax |
| 16 | + |
| 17 | +```graphql |
| 18 | +mutation { |
| 19 | + createCompanyUser( |
| 20 | + input: CompanyUserCreateInput! |
| 21 | + ) { |
| 22 | + CreateCompanyUserOutput |
| 23 | + } |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | +## Example usage |
| 28 | + |
| 29 | +The following example shows the minimal payload for adding a new customer to a customer's company. |
| 30 | + |
| 31 | +**Request:** |
| 32 | + |
| 33 | +```graphql |
| 34 | +mutation { |
| 35 | + createCompanyUser( |
| 36 | + input: { |
| 37 | + |
| 38 | + firstname: "John" |
| 39 | + lastname: "Doe" |
| 40 | + job_title: "User" |
| 41 | + role_id: "MQ==" |
| 42 | + status: ACTIVE |
| 43 | + telephone: "1234567890" |
| 44 | + } |
| 45 | + ) { |
| 46 | + user { |
| 47 | + created_at |
| 48 | + email |
| 49 | + } |
| 50 | + } |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +**Response:** |
| 55 | + |
| 56 | +```json |
| 57 | +{ |
| 58 | + "data": { |
| 59 | + "createCompanyUser": { |
| 60 | + "user": { |
| 61 | + "created_at": "2020-10-15 23:33:49", |
| 62 | + |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +This example creates a new company user of the parent company team specified in the `target_id` field. |
| 70 | + |
| 71 | +**Request:** |
| 72 | + |
| 73 | +```graphql |
| 74 | +mutation { |
| 75 | + createCompanyUser( |
| 76 | + input: { |
| 77 | + |
| 78 | + firstname: "Jane" |
| 79 | + lastname: "Doe3" |
| 80 | + job_title: "User" |
| 81 | + role_id: "NTc=" |
| 82 | + status: ACTIVE |
| 83 | + telephone: "1234567890" |
| 84 | + target_id: "OA==" |
| 85 | + } |
| 86 | + ) { |
| 87 | + user { |
| 88 | + created_at |
| 89 | + email |
| 90 | + firstname |
| 91 | + lastname |
| 92 | + job_title |
| 93 | + role { |
| 94 | + id |
| 95 | + name |
| 96 | + } |
| 97 | + team { |
| 98 | + id |
| 99 | + name |
| 100 | + structure_id |
| 101 | + } |
| 102 | + status |
| 103 | + telephone |
| 104 | + } |
| 105 | + } |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +**Response:** |
| 110 | + |
| 111 | +```json |
| 112 | +{ |
| 113 | + "data": { |
| 114 | + "createCompanyUser": { |
| 115 | + "user": { |
| 116 | + "created_at": "2020-10-15 23:39:11", |
| 117 | + |
| 118 | + "firstname": "Jane", |
| 119 | + "lastname": "Doe", |
| 120 | + "job_title": "User", |
| 121 | + "role": { |
| 122 | + "id": "NTc=", |
| 123 | + "name": "Default User" |
| 124 | + }, |
| 125 | + "team": { |
| 126 | + "id": "MQ==", |
| 127 | + "name": "Test Team", |
| 128 | + "structure_id": "Mg==" |
| 129 | + }, |
| 130 | + "status": "ACTIVE", |
| 131 | + "telephone": "1234567890" |
| 132 | + } |
| 133 | + } |
| 134 | + } |
| 135 | +} |
| 136 | +``` |
| 137 | + |
| 138 | +## Input attributes |
| 139 | + |
| 140 | +The `CompanyUserCreateInput` input object defines the company user data. |
| 141 | + |
| 142 | +### CompanyUserCreateInput attributes {#CompanyUserCreateInput} |
| 143 | + |
| 144 | +The `CompanyUserCreateInput` object contains the following attributes: |
| 145 | + |
| 146 | +Attribute | Data Type | Description |
| 147 | +--- | --- | --- |
| 148 | +`email` | String! | Company user's email address |
| 149 | +`firstname` | String! | Company user's first name |
| 150 | +`lastname` | String! | Company user's last name |
| 151 | +`job_title` | String! | Company user's job title |
| 152 | +`role_id` | ID! | Company user's role ID |
| 153 | +`status` | CompanyUserStatusEnum! | Indicates whether the company user is ACTIVE or INACTIVE |
| 154 | +`telephone` | String! | Company user's phone number |
| 155 | +`target_id` | ID | The ID of a node within a company's structure. This ID will be the parent of the created company user |
| 156 | + |
| 157 | +## Output attributes |
| 158 | + |
| 159 | +The `CreateCompanyUserOutput` output object contains the following attribute: |
| 160 | + |
| 161 | +Attribute | Data Type | Description |
| 162 | +--- | --- | --- |
| 163 | +`user` | Customer! | Contains company user data |
| 164 | + |
| 165 | +### Customer attributes {#Customer} |
| 166 | + |
| 167 | +{% include graphql/customer-output-24.md %} |
| 168 | + |
| 169 | +## Errors |
| 170 | + |
| 171 | +Error | Description |
| 172 | +--- | --- |
| 173 | +`Invitation was sent to an existing customer, they will be added to your organization once they accept the invitation.` | The customer with email provided in the `input`.`email` argument belongs to an existing customer. The invitation was sent to an existing customer. The customer will assign to the company after accepting the invitation. |
| 174 | +`A customer with the same email already assigned to company.` | The email provided in the `input`.`email` argument belongs to an existing customer and the customer has already assigned to the company. |
| 175 | +`"Email" is not a valid email address.` | The value provided in the `input`.`email` argument has an invalid format. |
| 176 | +`Field "createCompanyUser" argument "input" requires type String!, found xxx.` | The value specified in the one of the `input` arguments has an invalid type. |
| 177 | +`Field "xxx" is not defined by type CompanyUserCreateInput.` | The `input`.`xxx` argument is undefined. |
| 178 | +`Required parameters are missing: xxx` | The `input`.`xxx` argument was omitted or contains an empty value. |
| 179 | +`No such entity with roleId = xxx` | The company role with ID `xxx` doesn't exist. |
0 commit comments