I had created a custom API for adding new customer in Magento 2.3. I had injected dependency injection and passed the method to create the customer account. But it gives me below error:
main.CRITICAL: Type Error occurred when creating object: MyModule\Customapi\Model\Addcustomer, Too few arguments to function MyModule\Customapi\Model\Addcustomer::__construct(), 7 passed in /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 116 and exactly 8 expected [] []
I had injected CustomerRepositoryInterface to add new customer like this:
<?php namespace MyModule\Customapi\Model; use MyModule\Customapi\Api\AddCustomerInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\Customer\Api\AccountManagementInterface; class AddCustomer implements AddCustomerInterface { protected $request; protected $storeManager; protected $dataHelper; protected $accountManagementInterface; protected $authentication; private $accountConfirmation; protected $objectManager; protected $customerRepository; protected $_customerFactory; protected $_customerInterfaceFactory; public function __construct( StoreManagerInterface $storeManager, Data $dataHelper, RequestInterface $request, AccountConfirmation $accountConfirmation = null, AccountManagementInterface $accountManagementInterface, CustomerRepositoryInterface $customerRepository, \Magento\Customer\Model\Customer $customerFactory, \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerInterfaceFactory ) { $objectManager = ObjectManager::getInstance(); $this->storeManager = $storeManager; $this->dataHelper =$dataHelper; $this->request = $request; $this->accountManagementInterface = $accountManagementInterface; $this->accountConfirmation = $accountConfirmation ?: $objectManager ->get(AccountConfirmation::class); $this->customerRepository = $customerRepository; $this->_customerFactory = $customerFactory; $this->_customerInterfaceFactory = $customerInterfaceFactory; } public function addcustomer() { ... $customer = $this->_customerInterfaceFactory->create(); ... } }