Reputation: 43
I'm getting this error while calling the API for getting list Data using PostMan
https://hostname.sharepoint.com/sites/random_site/_api/web/lists(guid'be7ca91-2715-4b86-8299-7925f99b7536')/items
for above request below is the response
{
"odata.error": {
"code": "-2147467259, Microsoft.SharePoint.SPException",
"message": {
"lang": "en-US",
"value": "Cannot complete this action.\n\nPlease try again."
}
}
}
Meanwhile i'm getting data for the same list while calling on ConnectPnPOnline using terminal as i have atached below for reference
meanwhile for refrence i'm also attaching some of the list metadata details below
{
"odata.metadata": "https://domian.sharepoint.com/sites/random_site/_api/$metadata#SP.ApiData.Lists/@Element",
"odata.type": "SP.List",
"odata.id": "https://domain.sharepoint.com/sites/random_site/_api/Web/Lists(guid'be7ca91-2715-4b86-8299-7925f99b7536')",
"odata.etag": "\"4\"",
"odata.editLink": "Web/Lists(guid'be7ca91-2715-4b86-8299-7925f99b7536')",
"AllowContentTypes": true,
"BaseTemplate": 1331,
"BaseType": 0,
"ContentTypesEnabled": true,
"CrawlNonDefaultViews": false,
"Created": "2022-11-16T11:10:40Z",
"CurrentChangeToken": {
"StringValue": "1;3;be7ca91-2715-4b86-8299-7925f99b7536;638513631004800000;297591295"
},
"DefaultContentApprovalWorkflowId": "00000000-0000-0000-0000-000000000000",
"DefaultItemOpenUseListSetting": false,
"Description": "",
"Direction": "none",
"DisableCommenting": false,
"DisableGridEditing": false,
"DocumentTemplateUrl": null,
"DraftVersionVisibility": 0,
"EnableAttachments": true,
"EnableFolderCreation": true,
"EnableMinorVersions": false,
"EnableModeration": false,
"EnableRequestSignOff": true,
"EnableVersioning": false,
"EntityTypeName": "Model_x0020_Usage",
"ExemptFromBlockDownloadOfNonViewableFiles": false,
"FileSavePostProcessingEnabled": false,
"ForceCheckout": false,
"HasExternalDataSource": false,
"Hidden": false,
"Id": "be7ca91-2715-4b86-8299-7925f99b7536",
"ImagePath": {
"DecodedUrl": "/_layouts/15/images/itgen.gif?rev=47"
},
"ImageUrl": "/_layouts/15/images/itgen.gif?rev=47",
"DefaultSensitivityLabelForLibrary": "",
"SensitivityLabelToEncryptOnDownloadForLibrary": null,
"IrmEnabled": false,
"IrmExpire": false,
"IrmReject": false,
"IsApplicationList": false,
"IsCatalog": false,
"IsPrivate": false,
"ItemCount": 4,
"LastItemDeletedDate": "2024-05-15T05:46:28Z",
"LastItemModifiedDate": "2024-05-15T05:46:28Z",
"LastItemUserModifiedDate": "2024-05-15T05:46:28Z",
"ListExperienceOptions": 0,
"ListItemEntityTypeFullName": "SP.Data.Model_x0020_UsageItem",
"MajorVersionLimit": 0,
"MajorWithMinorVersionsLimit": 0,
"MultipleDataList": false,
"NoCrawl": false,
"ParentWebPath": {
"DecodedUrl": "/sites/random_site"
},
"ParentWebUrl": "/sites/random_site",
"ParserDisabled": false,
"ServerTemplateCanCreateFolders": true,
"TemplateFeatureId": "",
"Title": "Model Usage"
}
I'm expecting to get the list items by calling the microsoft rest api for sharepoint. But it is returning the error 500.
I got the results when i added the query in a discriptive manner and got the result but this doesn't look good and seems a but messy but the below one gave the result atleast?: https://hostname.sharepoint.com/sites/random_site/_api/web/lists(guid'be7ca91-2715-4b86-8299-7925f99b7536')/items$select=FirstUniqueAncestorSecurableObject,RoleAssignments,AttachmentFiles,ContentType,GetDlpPolicyTip,FieldValuesAsHtml,FieldValuesAsText,FieldValuesForEdit,File,Folder,LikedByInformation,ParentList,Properties,Versions,FileSystemObjectType,Id,ServerRedirectedEmbedUri,ServerRedirectedEmbedUrl,ContentTypeId,Title,ComplianceAssetId,OData__ColorTag,ID,Modified,Created,AuthorId,EditorId,OData__UIVersionString,Attachments,GUID,FileRef,FileDirRef,FileLeafRef,UniqueId,EncodedAbsUrl
the below api is returning 200 as response: https://hostname.sharepoint.com/sites/random_site/_api/web/lists(guid'be7ca91-2715-4b86-8299-7925f99b7536')/items
Do u have any better solution or i have to send the query in this very messy format?
Upvotes: 0
Views: 366
Reputation: 16064
I generate access token like below via Postman:
https://login.microsoftonline.com/TenantID/oauth2/v2.0/token
client_id:ClientID
scope:https://tenant.sharepoint.com/.default
grant_type:authorization_code
code:code
redirect_uri:https://jwt.ms
client_secret:ClientSecret
I created a list in SharePoint:
To List Items Data, modify the query like below:
https://tenant.sharepoint.com/sites/testrukk/_api/web/lists/GetByTitle('ruklist')/items?$select=Id,Title,GUID
Accept: "application/json;odata=verbose"
When tried in PowerShell I got the same results:
Get-PnPListItem -List "ruklist"
Reference:
Working with lists and list items with REST | Microsoft
Upvotes: 0