Check User type is customer or guest in Rest Webapi Magento 2.

Check Current user type using programmatically with Rest Web API. It’s used when you interact with the Webapi in Magento 2.

The difference between Customer and Guest user type is resource access. Customer User type has anonymous or self permission are allowed where later one access only Resources with anonymous permission.

Magento store the constant user type value in Magento\Authorization\Model\UserContextInterface.

namespace Jesadiya\CustomerGuestUserType\Model;

use Magento\Authorization\Model\UserContextInterface;

class CustomerGuestUserAPI
     * @var UserContextInterface
    private $userContextType;

    public function __construct(
        UserContextInterface $userContextType
    ) {
        $this->userContextType = $userContextType;

     * Return specific user type
     * @return int|null
    public function getCustomerOrGuestUserType(): ?int
        $userType = $this->userContextType->getUserType();
        return $userType;

The given Approach is useful for getting a customer type in Web API management. while you are working for the third party API and need to find out Customer Related information.

echo $userType = $this->getCustomerOrGuestUserType();

Verify List of User type based on the output integer value,

    const USER_TYPE_ADMIN = 2;
    const USER_TYPE_CUSTOMER = 3;
    const USER_TYPE_GUEST = 4;