my code to create a category is the following:

private function createCategory($name='',$parentId=2,$active=true,$description='',$metaTitle='',$metaKeywords='',$metaDescription='') 
        $metaTitle = $name;
    $categoryRepository = $this->categoryRepository;
    $category = $this->categoryFactory->create();
        'description' => $description,
        'meta_title' => $metaTitle,
        'meta_keywords' => $metaKeywords,
        'meta_description' => $metaDescription,


    return $category->getId();


this error came up: [Magento\Framework\Exception\AlreadyExistsException]

URL Key for specified store already exists

Any solution for this?

Can't expect this to happen when importing data.

PD: Thanks for your time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.