B2B for Adobe Commerce only. Learn more.

createCompanyUser mutation

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.

  • If the email address is unique for the website, Magento immediately creates the company user.

  • 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.

  • 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”.

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.

You can get the target_id and the role_id with the company query.

Syntax

1
2
3
4
5
6
7
mutation {
    createCompanyUser(
        input: CompanyUserCreateInput!
    ) {
        CreateCompanyUserOutput
    }
}

Example usage

Create a company user (minimal payload)

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.

Request:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
mutation {
  createCompanyUser(
    input: {
      email: "john.doe@example.com"
      firstname: "John"
      lastname: "Doe"
      job_title: "User"
      role_id: "MQ=="
      status: ACTIVE
      telephone: "1234567890"
    }
  ) {
    user {
      created_at
      email
    }
  }
}

Response:

1
2
3
4
5
6
7
8
9
10
{
  "data": {
    "createCompanyUser": {
      "user": {
        "created_at": "2020-10-15 23:33:49",
        "email": "john.doe@example.com"
      }
    }
  }
}

Create a company user in a specific location in the company structure

This example creates a new company user of the parent company team specified in the target_id field.

Request:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
mutation {
  createCompanyUser(
    input: {
      email: "jane.doe3@example.com"
      firstname: "Jane"
      lastname: "Doe3"
      job_title: "User"
      role_id: "NTc="
      status: ACTIVE
      telephone: "1234567890"
      target_id: "OA=="
    }
  ) {
    user {
      created_at
      email
      firstname
      lastname
      job_title
      role {
        id
        name
      }
      team {
        id
        name
        structure_id
      }
      status
      telephone
    }
  }
}

Response:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
  "data": {
    "createCompanyUser": {
      "user": {
        "created_at": "2020-10-15 23:39:11",
        "email": "jane.doe@example.com",
        "firstname": "Jane",
        "lastname": "Doe",
        "job_title": "User",
        "role": {
          "id": "NTc=",
          "name": "Default User"
        },
        "team": {
          "id": "MQ==",
          "name": "Test Team",
          "structure_id": "Mg=="
        },
        "status": "ACTIVE",
        "telephone": "1234567890"
      }
    }
  }
}

Input attributes

The CompanyUserCreateInput input object defines the company user data.

CompanyUserCreateInput attributes

The CompanyUserCreateInput object contains the following attributes:

Attribute Data Type Description
email String! The company user’s email address
firstname String! The company user’s first name
job_title String! The company user’s job title or function
lastname String! The company user’s last name
role_id ID! The role ID to assign to the company user
status CompanyUserStatusEnum! Indicates whether the company user is ACTIVE or INACTIVE
target_id ID The ID of a node within a company’s structure. This ID will be the parent of the created company user
telephone String! The company user’s phone number

Output attributes

The CreateCompanyUserOutput output object contains the following attribute:

Attribute Data Type Description
user Customer! Contains company user data

Customer attributes

Attribute Data Type Description
addresses CustomerAddress An array containing the customer’s shipping and billing addresses
allow_remote_shopping_assistance Boolean! Indicates whether the customer has enabled remote shopping assistance
compare_list CompareList The contents of the customer’s comparison list
created_at String Timestamp indicating when the account was created
date_of_birth String The customer’s date of birth. In keeping with current security and privacy best practices, be sure you are aware of any potential legal and security risks associated with the storage of customers’ full date of birth (month, day, year) along with other personal identifiers, such as full name, before collecting or processing such data.
default_billing String The ID assigned to the billing address
default_shipping String The ID assigned to the shipping address
dob String Deprecated. Use date_of_birth instead. The customer’s date of birth
email String The customer’s email address
firstname String The customer’s first name
gender Int The customer’s gender (Male - 1, Female - 2)
group_id Int Deprecated. This attribute is not applicable for GraphQL. The group assigned to the user. Default values are 0 (Not logged in), 1 (General), 2 (Wholesale), and 3 (Retailer)
id Int Deprecated. This attribute is not applicable for GraphQL. The ID assigned to the customer
is_subscribed Boolean Indicates whether the customer is subscribed to the company’s newsletter
lastname String The customer’s family name
middlename String The customer’s middle name
orders(filter CustomerOrdersFilterInput, currentPage = 1 Int, pageSize = 20 Int) [CustomerOrders] A list of the customer’s placed orders
prefix String An honorific, such as Dr., Mr., or Mrs.
return(uid: ID!) Return Gets details about the specified return request
returns(pageSize: Int = 20 currentPage: Int = 1) Returns Information about the customer’s return requests
reviews(pageSize: Int = 20 currentPage: Int = 1) ProductReviews! The list of reviews of the product
reward_points [RewardPoints] Details about the customer’s reward points
suffix String A value such as Sr., Jr., or III
taxvat String The customer’s Tax/VAT number (for corporate customers)
wishlist Wishlist! Deprecated. Use wishlist_v2 instead. Contains the contents of the customer’s wish lists
wishlist_v2(id ID!) [Wishlist]! Retrieve the specified wish list identified by the unique ID for a Wishlist object

For B2B, company administrators and users can have the following attributes.

Attribute Data Type Description
job_title String The job title for a B2B company user
requisition_lists (pageSize = 20 Int, currentPage = 1 Int, filter RequisitionListFilterInput) RequisitionLists Contains the customer’s requisition lists
role CompanyRole The role name and permissions assigned to the company user
status CompanyUserStatusEnum Indicates whether the company user is ACTIVE or INACTIVE
team CompanyTeam The team the company user is assigned to
telephone String The phone number of the company user

Errors

Error Description
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.
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.
"Email" is not a valid email address. The value provided in the input.email argument has an invalid format.
Field "createCompanyUser" argument "input" requires type String!, found xxx. The value specified in the one of the input arguments has an invalid type.
Field "xxx" is not defined by type CompanyUserCreateInput. The input.xxx argument is undefined.
Required parameters are missing: xxx The input.xxx argument was omitted or contains an empty value.
No such entity with roleId = xxx The company role with ID xxx doesn’t exist.