0

Runing this example. i have a list("announcement2") in sharepoint online account and I am able to read items from that list. When I trigger create item event below;

private listItemEntityTypeName: string = "SP.Data.announcement2ListItem";
..

private createItem(): void {
    this.getListItemEntityTypeName()
      .then((listItemEntityTypeName: string): Promise<Response> => {
        const body: string = JSON.stringify({
          '__metadata': {
            'type': listItemEntityTypeName
          },
          'Title': `Item CREATED`
        });
        return this.props.httpClient.post(`${this.siteUrl}/_api/web/lists/getbytitle('${this.props.listName}')/items`,
        SPHttpClientConfigurations.v1, {
          headers: {
            'Accept': 'application/json;odata=nometadata',
            'Content-type': 'application/json;odata=verbose',
            'odata-version': ''
          },
          body: body
        }); 
      })

I see this exception in console Response content:

{"odata.error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"A type named 'SP.Data.announcement2ListItem' could not be resolved by the model. When a model is available, each type name must resolve to a valid type."}}}

This looks about my "listItemEntityTypeName" property since I harcoded set it(if not set it its undefined). How can I solve this?

  • Did you try SP.Data.Announcement2ListItem (check case sensitivity)? – Sergei Sergeev Jan 23 '17 at 15:38
  • @SergeiSergeev You did it again! Thank you! please post it as answer and so I can mark it as answer! Thanks again! – TyForHelpDude Jan 23 '17 at 15:47
1

Actually getListItemEntityTypeName should return valid entity type name. You can try to investigate why it doesn't work as expected.

If you want to provide it manually you need to be careful because entity type parameter is case sensitive. So in your case it should be SP.Data.Announcement2ListItem

Your Answer

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

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