Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit c9f8126

Browse files
andrewbesskeharper
andauthored
ISSUE-7985: The topics for the "Company User" mutations have been cre… (#8104)
* ISSUE-7985: The topics for the "Company User" mutations have been created * ISSUE-7985: The fixes by reviewer recommendations * ISSUE-7985: The fixes by reviewer recommendations * ISSUE-7985: The fixes by reviewer recommendations * Update create-company-user.md * Update create-company-user.md Co-authored-by: Kevin Harper <[email protected]>
1 parent 374c63f commit c9f8126

File tree

4 files changed

+451
-0
lines changed

4 files changed

+451
-0
lines changed

src/_data/toc/graphql.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ pages:
223223
edition: b2b-only
224224
exclude_versions: ["2.3"]
225225

226+
- label: createCompanyUser mutation
227+
url: /graphql/mutations/create-company-user.html
228+
edition: b2b-only
229+
exclude_versions: ["2.3"]
230+
226231
- label: createCustomer mutation
227232
url: /graphql/mutations/create-customer.html
228233

@@ -265,6 +270,11 @@ pages:
265270
edition: b2b-only
266271
exclude_versions: ["2.3"]
267272

273+
- label: deleteCompanyUser mutation
274+
url: /graphql/mutations/delete-company-user.html
275+
edition: b2b-only
276+
exclude_versions: ["2.3"]
277+
268278
- label: deleteCustomerAddress mutation
269279
url: /graphql/mutations/delete-customer-address.html
270280

@@ -392,6 +402,11 @@ pages:
392402
edition: b2b-only
393403
exclude_versions: ["2.3"]
394404

405+
- label: updateCompanyUser mutation
406+
url: /graphql/mutations/update-company-user.html
407+
edition: b2b-only
408+
exclude_versions: ["2.3"]
409+
395410
- label: updateCustomer mutation
396411
url: /graphql/mutations/update-customer.html
397412

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
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+
The `createCompanyUser` mutation allows an existing company user who is assigned a role that contains the `Magento_Company::users_edit` permission to create a new company user. The specified email address determines how Magento processes the request.
10+
11+
- If the email address is unique for the website, Magento immediately creates the company user.
12+
13+
- If the email address belongs to a customer who is not a company user, Magento sends an invitation to join the company organization to the customer. When the customer accepts the invitation, Magento adds the customer to the company organization.
14+
15+
- If the email address belongs to a customer who is part of any company organization, Magento returns the error "A customer with the same email already assigned to company".
16+
17+
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.
18+
19+
You can get the `target_id` and the `role_id` with the [`company`]({{page.baseurl}}/graphql/queries/company.html) query.
20+
21+
## Syntax
22+
23+
```graphql
24+
mutation {
25+
createCompanyUser(
26+
input: CompanyUserCreateInput!
27+
) {
28+
CreateCompanyUserOutput
29+
}
30+
}
31+
```
32+
33+
## Example usage
34+
35+
### Create a company user (minimal payload)
36+
37+
The following example shows the minimal payload to add a company user. Because a `target_id` is not specified, Magento places the new company user at the top node of the company structure.
38+
39+
**Request:**
40+
41+
```graphql
42+
mutation {
43+
createCompanyUser(
44+
input: {
45+
46+
firstname: "John"
47+
lastname: "Doe"
48+
job_title: "User"
49+
role_id: "MQ=="
50+
status: ACTIVE
51+
telephone: "1234567890"
52+
}
53+
) {
54+
user {
55+
created_at
56+
email
57+
}
58+
}
59+
}
60+
```
61+
62+
**Response:**
63+
64+
```json
65+
{
66+
"data": {
67+
"createCompanyUser": {
68+
"user": {
69+
"created_at": "2020-10-15 23:33:49",
70+
"email": "[email protected]"
71+
}
72+
}
73+
}
74+
}
75+
```
76+
77+
### Create a company user in a specific location in the company structure
78+
79+
This example creates a new company user of the parent company team specified in the `target_id` field.
80+
81+
**Request:**
82+
83+
```graphql
84+
mutation {
85+
createCompanyUser(
86+
input: {
87+
88+
firstname: "Jane"
89+
lastname: "Doe3"
90+
job_title: "User"
91+
role_id: "NTc="
92+
status: ACTIVE
93+
telephone: "1234567890"
94+
target_id: "OA=="
95+
}
96+
) {
97+
user {
98+
created_at
99+
email
100+
firstname
101+
lastname
102+
job_title
103+
role {
104+
id
105+
name
106+
}
107+
team {
108+
id
109+
name
110+
structure_id
111+
}
112+
status
113+
telephone
114+
}
115+
}
116+
}
117+
```
118+
119+
**Response:**
120+
121+
```json
122+
{
123+
"data": {
124+
"createCompanyUser": {
125+
"user": {
126+
"created_at": "2020-10-15 23:39:11",
127+
"email": "[email protected]",
128+
"firstname": "Jane",
129+
"lastname": "Doe",
130+
"job_title": "User",
131+
"role": {
132+
"id": "NTc=",
133+
"name": "Default User"
134+
},
135+
"team": {
136+
"id": "MQ==",
137+
"name": "Test Team",
138+
"structure_id": "Mg=="
139+
},
140+
"status": "ACTIVE",
141+
"telephone": "1234567890"
142+
}
143+
}
144+
}
145+
}
146+
```
147+
148+
## Input attributes
149+
150+
The `CompanyUserCreateInput` input object defines the company user data.
151+
152+
### CompanyUserCreateInput attributes {#CompanyUserCreateInput}
153+
154+
The `CompanyUserCreateInput` object contains the following attributes:
155+
156+
Attribute | Data Type | Description
157+
--- | --- | ---
158+
`email` | String! | The company user's email address
159+
`firstname` | String! | The company user's first name
160+
`job_title` | String! | The company user's job title or function
161+
`lastname` | String! | The company user's last name
162+
`role_id` | ID! | The role ID to assign to the company user
163+
`status` | CompanyUserStatusEnum! | Indicates whether the company user is ACTIVE or INACTIVE
164+
`target_id` | ID | The ID of a node within a company's structure. This ID will be the parent of the created company user
165+
`telephone` | String! | The company user's phone number
166+
167+
## Output attributes
168+
169+
The `CreateCompanyUserOutput` output object contains the following attribute:
170+
171+
Attribute | Data Type | Description
172+
--- | --- | ---
173+
`user` | Customer! | Contains company user data
174+
175+
### Customer attributes {#Customer}
176+
177+
{% include graphql/customer-output-24.md %}
178+
179+
## Errors
180+
181+
Error | Description
182+
--- | ---
183+
`Invitation was sent to an existing customer, they will be added to your organization once they accept the invitation.` | The email provided in the `input`.`email` argument belongs to an existing customer. Magento will send an invitation to this customer. When the customer accepts the invitation, the customer will be assigned to the company.
184+
`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 been assigned to the company.
185+
`"Email" is not a valid email address.` | The value provided in the `input`.`email` argument has an invalid format.
186+
`Field "createCompanyUser" argument "input" requires type String!, found xxx.` | The value specified in the one of the `input` arguments has an invalid type.
187+
`Field "xxx" is not defined by type CompanyUserCreateInput.` | The `input`.`xxx` argument is undefined.
188+
`Required parameters are missing: xxx` | The `input`.`xxx` argument was omitted or contains an empty value.
189+
`No such entity with roleId = xxx` | The company role with ID `xxx` doesn't exist.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
group: graphql
3+
title: deleteCompanyUser mutation
4+
contributor_name: Atwix
5+
contributor_link: https://www.atwix.com/
6+
b2b_only: true
7+
---
8+
9+
Use the `deleteCompanyUser` mutation to deactivate the specified company user.
10+
11+
You can get the user ID with the [`company`]({{page.baseurl}}/graphql/queries/company.html) query.
12+
13+
## Syntax
14+
15+
```graphql
16+
mutation {
17+
deleteCompanyUser(
18+
id: ID!
19+
) {
20+
DeleteCompanyUserOutput
21+
}
22+
}
23+
```
24+
25+
## Example usage
26+
27+
The following example deactivates the user specified in the `id` attribute.
28+
29+
**Request:**
30+
31+
```graphql
32+
mutation {
33+
deleteCompanyUser(
34+
id: "Mg=="
35+
) {
36+
success
37+
}
38+
}
39+
```
40+
41+
**Response:**
42+
43+
```json
44+
{
45+
"data": {
46+
"deleteCompanyUser": {
47+
"success": true
48+
}
49+
}
50+
}
51+
```
52+
53+
## Input attributes
54+
55+
The `deleteCompanyUser` mutation requires the following input:
56+
57+
Attribute | Data Type | Description
58+
--- | --- | ---
59+
`id` | ID! | The encoded user ID to deactivate
60+
61+
## Output attributes
62+
63+
The `deleteCompanyUser` mutation returns a Boolean value that indicates whether the operation was successful.
64+
65+
Attribute | Data Type | Description
66+
--- | --- | ---
67+
`success` | Boolean! | A value of `true` indicates the company user has been deactivated successfully, otherwise a value returns `false`
68+
69+
## Errors
70+
71+
Error | Description
72+
--- | ---
73+
`You do not have authorization to perform this action.` | The user with the ID provided in the `input`.`id` argument is not available to your company, or you do not have the necessary permissions to perform this operation.
74+
`You cannot delete yourself.` | You must specify a company user other than yourself.
75+
`A customer with the same email address already exists in an associated website` | The email provided in the `input`.`email` argument belongs to another user.
76+
`The user XXX is the company admin and cannot be set to inactive. You must set another user as the company admin first.` | The company owner cannot be deactivated. You must set another user as the company admin first.

0 commit comments

Comments
 (0)