2

I'm trying to insert new record to a SharePoint 2013 online (Office 365) list, which I created, using https://github.com/vgrem/phpSPO

From the description it looks straight forward to add new record, but I get following error:

'A type named 'SP.Data.pizzaListItem' could not be resolved by the model. When a model is available, each type name must resolve to a valid type.'

Code that gives the error is:

 $itemProperties = array(
        "__metadata"=> array("type"=> "SP.Data.pizzaListItem")
        , 'Title' => 'u_'.$rand
         ,       'Location' => 'L_'.$rand
        , 'Type' => 'Adult'
        , 'Food' => 'Special'
        );
 var_dump($itemProperties);
 $taskItem = $list->addItem($itemProperties);

I am starting working with SharePoint lists and I tried to find out what what that error means on the net, but couldn't find anything useful. Can someone point me in the right direction?

1 Answer 1

1

I believe it occurs since the Entity Type that you've specified via $itemProperties['__metadata']['type'] is ignored since in the previous version of library it was not supported to specify Entity Type explicitly (it was generated from List title).

So, you could grab the latest version from GitHub repository, it contains some fixes including the ability to specify the entity type explicitly.

Examples

Specify Entity Type explicitly:

$list = $client->getList($listTitle);
$itemProperties = array('Title' => 'Order Approval', 'Body' => 'Order approval task','__metadata' => array('type' => 'SP.Data.TasksListItem'));
$item = $list->addItem($itemProperties);

Omit Entity Type, it will be generated automatically based on List title:

$list = $client->getList($listTitle);
$itemProperties = array('Title' => 'Order Approval', 'Body' => 'Order approval task');
$item = $list->addItem($itemProperties);

Disclaimer: I'm the author of this library


Update

The error:

A type named 'SP.Data.XXXXXListItem' could not be resolved by the model

usually occurs when type name does not correspond to the actual entity type name.

How to determine Entity Type name

The following REST request returns Entity Type name:

GET https://<site>/_api/lists/getbytitle('<list title>')?$select=ListItemEntityTypeFullName 
1
  • Hi, i still get the same error, no matter i set __metadata item or not.
    – Kupe3
    Oct 7, 2014 at 5:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.