# Incorrect collection name when posting multiple values with API tools and Hal Json

**URL:** <https://discourse.laminas.dev/t/incorrect-collection-name-when-posting-multiple-values-with-api-tools-and-hal-json/2239>\
**Category:** API Tools\
**Created:** [April 10, 2021, 5:09pm UTC](https://discourse.laminas.dev/t/incorrect-collection-name-when-posting-multiple-values-with-api-tools-and-hal-json/2239 "2021-04-10T17:09:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vigcraig](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/vigcraig/32/819_2.png) [@vigcraig](https://discourse.laminas.dev/u/vigcraig)\
**Post date:** [April 10, 2021, 5:09pm UTC](https://discourse.laminas.dev/t/incorrect-collection-name-when-posting-multiple-values-with-api-tools-and-hal-json/2239/1 "2021-04-10T17:09:38Z")

</div>

Hi,  
I have an issue where I need to POST multiple values, but in the response, the HAL collection name has defaulted to “items”. The GET works correctly and gives the correct response.

How do I get the POST to provide the correct collection name?

Very simple example to hopefully demostrate my issue.

In the resource i have the typical fetchAll and create functions, for demo purposes I have hardcoded the values.

The fetchAll function:

```
public function fetchAll($params = [])
{
    $result = array();
    $result[0]->id= 1;
    $result[0]->name= 'name1';

    $result[1]->id= 2;
    $result[1]->name= 'name2';

    foreach($result as $row) {
        $entities[]= new WidgetsEntity($row);           
    }  
    $adapter = new ArrayAdapter($entities);       
    
    $collection = new WidgetsCollection($adapter);
    return $collection;   
    
}

```

Returns:

{  
“\_links”: {  
“self”: {  
“href”: “/demo-services/widgets?page=1”  
},  
“first”: {  
“href”: “/demo-services/widgets”  
},  
“last”: {  
“href”: “/demo-services/widgets?page=1”  
}  
},  
“\_embedded”: {  
“ **widgets** ”: [  
{  
“id”: 1,  
“name”: “name1”,  
“\_links”: {  
“self”: {  
“href”: “/demo-services/widgets/1”  
}  
}  
},  
{  
“id”: 2,  
“name”: “name2”,  
“\_links”: {  
“self”: {  
“href”: “/demo-services/widgets/2”  
}  
}  
}  
]  
},  
“page\_count”: 1,  
“page\_size”: 25,  
“total\_items”: 2,  
“page”: 1  
}

The create function, using the exact same code as the fetchAll gives the following with the “items” instead of “widgets”

```
public function create($data)
{
    $result = array();
    $result[0]->id= 1;
    $result[0]->name= 'name1';
    
    $result[1]->id= 2;
    $result[1]->name= 'name2';
    
    foreach($result as $row) {
        $entities[]= new WidgetsEntity($row);
    }
    $adapter = new ArrayAdapter($entities);
    
    $collection = new WidgetsCollection($adapter);
    return $collection;   
}

```

Returns:

{  
“\_links”: {  
“self”: {  
“href”: “/demo-services/widgets?page=1”  
},  
“first”: {  
“href”: “/demo-services/widgets”  
},  
“last”: {  
“href”: “/demo-services/widgets?page=1”  
}  
},  
“\_embedded”: {  
“ **items** ”: [  
{  
“id”: 1,  
“name”: “name1”,  
“\_links”: {  
“self”: {  
“href”: “/demo-services/widgets/1”  
}  
}  
},  
{  
“id”: 2,  
“name”: “name2”,  
“\_links”: {  
“self”: {  
“href”: “/demo-services/widgets/2”  
}  
}  
}  
]  
},  
“page\_count”: 1,  
“page\_size”: 30,  
“total\_items”: 2,  
“page”: 1  
}

Why is it doing this and how do I replace “items” with “widgets”?

Any help would be appreciated here.

---

<div class="post-metadata">

**Author:** ![vigcraig](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/vigcraig/32/819_2.png) [@vigcraig](https://discourse.laminas.dev/u/vigcraig)\
**Post date:** [April 15, 2021, 8:47pm UTC](https://discourse.laminas.dev/t/incorrect-collection-name-when-posting-multiple-values-with-api-tools-and-hal-json/2239/2 "2021-04-15T20:47:31Z")

</div>

Sorted this one myself by setting and object property to “widgets”  
Example :

```
   $adapter = new ArrayAdapter($entities);
   $collection = new \stdClass();
   $collection->widgets= new WidgetsCollection($adapter);
   return $collection;
```
