# Cannot install plugin after add data through API Resource

**URL:** <https://forum.shopware.com/t/cannot-install-plugin-after-add-data-through-api-resource/35119>\
**Category:** Programmierung\
**Created:** [8. März 2016 um 14:28 UTC](https://forum.shopware.com/t/cannot-install-plugin-after-add-data-through-api-resource/35119 "2016-03-08T14:28:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cboita](https://avatars.discourse-cdn.com/v4/letter/c/eb9ed0/32.png) [@cboita](https://forum.shopware.com/u/cboita)\
**Post date:** [8. März 2016 um 14:28 UTC](https://forum.shopware.com/t/cannot-install-plugin-after-add-data-through-api-resource/35119/1 "2016-03-08T14:28:45Z")

</div>

Hi there,

&nbsp;

I’m trying to create some PropertyGroup during installation of my plugin. I can create the data I want but I get an exception after and the plugin isn’t installed.

On my bootstrap.php I have

```
 public function install()
    {
        $this->configurePropertiesGroups();

        return array('success' => true, 'invalidateCache' => array('backend'));
    }

protected function configurePropertiesGroups()
    {
        $apiResourcePropertyGroup = new \Shopware\Components\Api\Resource\PropertyGroup();
        $apiResourcePropertyGroup->setManager($this->getEntityManager());

        
        // add Material Properties
        $this->createPropertyGroup($apiResourcePropertyGroup, 'Material', 1);
    }

    private function getEntityManager()
    {
        return Shopware()->Models();
    }

    protected function createPropertyGroup($apiResourcePropertyGroup, $name, $position)
    {

        $properties = array(
            'name' => $name,
            'position' => $position,
            'comparable' => 1,
            'sortmode' => 2
        );

        $apiResourcePropertyGroup->create($properties);

    }

```

And the exception I get is

„Unable to install, got exception: Entity has to be managed or scheduled for removal for single computation Shopware\Models\Plugin\Plugin@00000000231afc1800007f28a267451c“

After debug I check that exception happen on execution of Plugin/Namespace-\>flush($plugin).

&nbsp;

As I see this is related to EntityManager, because on \Shopware\Components\Api\Resource\PropertyGroup()-\>create() method is executed the $em-\>flush($property).

Anyone can help how to create the PropertyGroup items using API on install method and get the plugin installed without errors?

&nbsp;

Thanks

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![Heiner\_Lohaus](https://avatars.discourse-cdn.com/v4/letter/h/b5a626/32.png) [@Heiner\_Lohaus](https://forum.shopware.com/u/Heiner_Lohaus)\
**Post date:** [8. März 2016 um 15:08 UTC](https://forum.shopware.com/t/cannot-install-plugin-after-add-data-through-api-resource/35119/2 "2016-03-08T15:08:13Z")

</div>

Hello,

you can use the entity manager directly. Example:

```
$property = new \Shopware\Models\Property\Group();
$property->fromArray(properties);

$this->getEntityManager()->persist($property);
$this->getEntityManager()->flush($property);

```

Then you doesn’t&nbsp;need the API ressource&nbsp;and doesn’t get any problems with the plugin entity.

Heiner
