Jigar KarangiyaJigar Karangiya

How to Check Email Availability for Company, User & Admin in Magento 2 B2B using GraphQL

JK
Jigar Karangiya
· 2 min read
How to Check Email Availability for Company, User & Admin in Magento 2 B2B using GraphQL

In Magento 2 B2B (Business-to-Business) environments, ensuring email uniqueness is essential when registering a company, assigning company users, or creating admin roles. Magento provides GraphQL queries to validate email availability for each use case.

In this tutorial, we’ll explore the following GraphQL queries:

  • isCompanyEmailAvailable
  • isCompanyUserEmailAvailable
  • isCompanyAdminEmailAvailable

All queries require a valid customer token and return a boolean value indicating whether the given email is available for the requested action.


Prerequisite: Generate Customer Token

Before using any of these queries, you need to generate a customer token via GraphQL:

graphql
mutation {
  generateCustomerToken(
    email: "johndoe@example.com"
    password: "CustomerPassword123"
  ) {
    token
  }
}

Use this token as the Authorization header for the upcoming queries:

text
Authorization: Bearer <customer-token>

Check Email Availability for Company Registration

Query: isCompanyEmailAvailable

This query checks if the provided email can be used to register a new company. It returns false if the email already belongs to an existing company or customer.

Syntax

graphql
query{
  isCompanyEmailAvailable(email: "roni_cost@example.com"){
    is_email_available
  }
}

Result

json
{
  "data": {
    "isCompanyEmailAvailable": {
      "is_email_available": true
    }
  }
}

Check Email Availability for Company User

Query: isCompanyUserEmailAvailable

Use this query to check whether an email can be used to add a new user to a company. It returns false if the email already belongs to a customer or company admin.

Syntax

graphql
{
  isCompanyUserEmailAvailable(email: "roni_cost@example.com") {
    is_email_available
  }
}

Output

json
{
  "data": {
    "isCompanyUserEmailAvailable": {
      "is_email_available": false
    }
  }
}

Check Email Availability for Company Admin

Query: isCompanyAdminEmailAvailable

This query checks if the given email is available to be used as a Company Administrator. Returns false if it already belongs to a customer or another company admin.

Syntax

graphql
query {
  isCompanyAdminEmailAvailable(email: "roni_cost@example.com") {
    is_email_available
  }
}

Output

json
{
  "data": {
    "isCompanyAdminEmailAvailable": {
      "is_email_available": false
    }
  }
}

With these GraphQL queries, validating email availability for different roles in Magento 2 B2B becomes straightforward and efficient. Whether you’re registering a company, assigning users, or setting up admins — you can ensure data integrity and avoid conflicts right from the frontend.

You may also like,

How to Create a Customer Account Using Magento 2 GraphQL

How to Check Email Availability in Magento 2 Using GraphQL (2.4.7+)

How to Generate a Customer Token Using Magento 2 GraphQL


Resources

https://developer.adobe.com/commerce/webapi/graphql/schema/b2b/company/queries/is-company-email-available

https://developer.adobe.com/commerce/webapi/graphql/schema/b2b/company/queries/is-company-admin-email-available/

https://developer.adobe.com/commerce/webapi/graphql/schema/b2b/company/queries/is-company-user-email-available/

Written by Jigar Karangiya, Adobe Commerce & Magento 2 developer.

More about me

Related posts