koltyakov / gosip

⚡️ SharePoint SDK for Go
https://go.spflow.com
MIT License
145 stars 33 forks source link

Issue in creating list item #35

Closed anurag2994 closed 4 years ago

anurag2994 commented 4 years ago

We are creating list item. During creation we are passing the same object received during Getting the list item.

But facing the below mentioned issue: unable to request api: 400 Bad Request :: {"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"Did not find the required 'results' property on the object wrapping a feed."}}}

Can you provide some insight/help regarding this?

koltyakov commented 4 years ago

Can you provide a code sample and details (what field type with what payload you're trying using)?

Sounds as if you were updating (or creating an item with) a multi lookup field and provided incorrect payload.

The lookup field in the OData payload should have Id suffix and values in a results property array.

{
  "AMultiLookupFieldId": {
    "results": [ 1, 2, 3 ]
  }
}
anurag2994 commented 4 years ago

This is the payload I am giving:

{ "AttachmentFiles": { "deferred": { "uri": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/AttachmentFiles" } }, "AuthorId": 1073741823, "BannerImageUrl": null, "CanvasContent1": null, "CheckoutUserId": null, "ComplianceAssetId": null, "ContentType": { "__deferred": { "uri": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/ContentType" } }, "ContentTypeId": "0x0101009D1CB255DA76424F860D91F20E6C411800507C2DBA8AA51A4CAE9D671EAFF2B326", "Created": "2020-07-19T07:23:27Z", "Description": null, "EditorId": 1073741823, "FieldValuesAsHtml": { "deferred": { "uri": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/FieldValuesAsHtml" } }, "FieldValuesAsText": { "Author": "1073741823,#,#,#,#", "BannerImageUrl": "", "CanvasContent1": "", "CheckoutUser": "", "ComplianceAssetId": "", "ContentTypeId": "0x0101009D1CB255DA76424F860D91F20E6C411800507C2DBA8AA51A4CAE9D671EAFF2B326", "Created": "7/19/2020 12:23 AM", "Created_x005f_x0020_x005f_Date": "7/19/2020 12:24 AM", "Description": "", "Editor": "1073741823,#SHAREPOINT\system,#,#,#", "FSObjType": "0", "FileLeafRef": "Home.aspx", "FileRef": "/sites/AnuragDocLibrary1/SitePages/Home.aspx", "FirstPublishedDate": "", "GUID": "fc22a38e-d391-4fc7-b443-2972e44e1d27", "HTML_x005f_x0020_x005f_File_x005f_x0020_x005f_Type": "", "ID": "1", "Last_x005f_x0020_x005f_Modified": "7/19/2020 12:24 AM", "LayoutWebpartsContent": "", "Modified": "7/19/2020 12:23 AM", "ODatax005f_AuthorByline": "", "OData__x005f_CopySource": "", "ODatax005f_Level": "1", "ODatax005f_ModerationStatus": "Approved", "OData__x005f_OriginalSourceItemId": "", "ODatax005f_OriginalSourceListId": "", "ODatax005f_OriginalSourceSiteId": "", "OData__x005f_OriginalSourceUrl": "", "ODatax005f_OriginalSourceWebId": "", "ODatax005f_SPSitePageFlags": "", "OData__x005f_TopicHeader": "", "ODatax005f_UIVersionString": "1.0", "ProgId": "", "PromotedState": "0", "Title": "Home", "UniqueId": "82350df1-6bd7-48c0-8da8-8bc0cea93fa0", "WikiField": "", "metadata": { "id": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/FieldValuesAsText", "type": "SP.FieldStringValues", "uri": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/FieldValuesAsText" }, "owshiddenversion": "5" }, "FieldValuesForEdit": { "deferred": { "uri": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/FieldValuesForEdit" } }, "File": { "deferred": { "uri": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/File" } }, "FileSystemObjectType": 0, "FirstPublishedDate": null, "FirstUniqueAncestorSecurableObject": { "__deferred": { "uri": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/FirstUniqueAncestorSecurableObject" } }, "Folder": { "deferred": { "uri": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/Folder" } }, "GUID": "fc22a38e-d391-4fc7-b443-2972e44e1d27", "GetDlpPolicyTip": { "deferred": { "uri": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/GetDlpPolicyTip" } }, "ID": 1, "Id": 1, "LayoutWebpartsContent": null, "LikedByInformation": { "__deferred": { "uri": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/LikedByInformation" } }, "Modified": "2020-07-19T07:23:27Z", "ODataAuthorBylineId": null, "ODataCopySource": null, "ODataOriginalSourceItemId": null, "ODataOriginalSourceListId": null, "ODataOriginalSourceSiteId": null, "ODataOriginalSourceUrl": null, "ODataOriginalSourceWebId": null, "ODataSPSitePageFlags": null, "ODataTopicHeader": null, "ODataUIVersionString": "1.0", "ParentList": { "deferred": { "uri": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/ParentList" } }, "PromotedState": 0, "Properties": { "deferred": { "uri": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/Properties" } }, "RoleAssignments": { "__deferred": { "uri": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/RoleAssignments" } }, "ServerRedirectedEmbedUri": null, "ServerRedirectedEmbedUrl": "", "Title": "Home", "Versions": { "deferred": { "uri": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/Versions" } }, "WikiField": null, "_AuthorBylineStringId": null, "__metadata": { "etag": "\"5\"", "id": "7b729d9f-2bd7-488a-aec9-7ec933129068", "type": "SP.Data.SitePagesItem", "uri": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)" } }

The code to add: ItemRep, e := list.Items().Add(listItemInBytes)

koltyakov commented 4 years ago

You shouldn't be using such payloads for item creation and updates. The payload only must contain allowed and valid properties for the operation. When getting an item, there is always nested child objects and service metadata, but it can't be sent back in the same form obviously.

anurag2994 commented 4 years ago

Similar payload is working for other item that's why I raised the issue here.

anurag2994 commented 4 years ago

In the working code the payload I used was for fields: "FieldValuesAsText": { "Author": "1073741823,#,#,#,#", "BannerImageUrl": "", "CanvasContent1": "", "CheckoutUser": "", "ComplianceAssetId": "", "ContentTypeId": "0x0101009D1CB255DA76424F860D91F20E6C411800507C2DBA8AA51A4CAE9D671EAFF2B326", "Created": "7/19/2020 12:23 AM", "Created_x005f_x0020_x005f_Date": "7/19/2020 12:24 AM", "Description": "", "Editor": "1073741823,#SHAREPOINT\system,#,#,#", "FSObjType": "0", "FileLeafRef": "Home.aspx", "FileRef": "/sites/AnuragDocLibrary1/SitePages/Home.aspx", "FirstPublishedDate": "", "GUID": "fc22a38e-d391-4fc7-b443-2972e44e1d27", "HTML_x005f_x0020_x005f_File_x005f_x0020_x005f_Type": "", "ID": "1", "Last_x005f_x0020_x005f_Modified": "7/19/2020 12:24 AM", "LayoutWebpartsContent": "", "Modified": "7/19/2020 12:23 AM", "ODatax005f_AuthorByline": "", "OData__x005f_CopySource": "", "ODatax005f_Level": "1", "ODatax005f_ModerationStatus": "Approved", "OData__x005f_OriginalSourceItemId": "", "ODatax005f_OriginalSourceListId": "", "ODatax005f_OriginalSourceSiteId": "", "OData__x005f_OriginalSourceUrl": "", "ODatax005f_OriginalSourceWebId": "", "ODatax005f_SPSitePageFlags": "", "OData__x005f_TopicHeader": "", "ODatax005f_UIVersionString": "1.0", "ProgId": "", "PromotedState": "0", "Title": "Home", "UniqueId": "82350df1-6bd7-48c0-8da8-8bc0cea93fa0", "WikiField": "", "__metadata": { "id": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/FieldValuesAsText", "type": "SP.FieldStringValues", "uri": "https://site.sharepoint.com/sites/AnuragDocLibrary1/_api/Web/Lists(guid'a3ace4bc-827e-422b-afdb-eda68aa48943')/Items(1)/FieldValuesAsText" }, "owshiddenversion": "5" }

This works fine.

Can you please help me with the allowed parameters?

koltyakov commented 4 years ago

It's better mapping the payload to a normal form, trimming everything redundant and invalid, updating only content types field values but not the service layer and read-only fields. Even if half of these are just ignored with the API it can lead to deferred issues in the future.

Can you please help me with the allowed parameters?

Ideally, the same set of fields which are allowed for editing in a UI form. Any of the service fields, IDs, API entities must be trimmed. It's not about the library, but what is applicable in the API.

anurag2994 commented 4 years ago

Okay. Thanks for your valuable input. I'll try out the method recommended by you.

koltyakov commented 4 years ago

Going to close it.

anurag2994 commented 4 years ago

Hi. I am still facing issue with trimmed properties.

The error I am getting is:

to-add-an-item-to-a-document-library-use-spfilecollection-add

koltyakov commented 4 years ago

You can't add an item in a document library. In a document library, only files and folders are allowed.

anurag2994 commented 4 years ago

Okay. But a page in sharepoint is an item. Is there a way to create a page in Gosip?

koltyakov commented 4 years ago

A page is a file obviously, not an item. A file in a document library. A file in SharePoint object model has an item.

Modern pages have their own API, which I'm not covering in gosip currently as client-side pages API is pretty unstable, IMO. It constantly has been introducing breaking changes during a year.

For modern pages, especially when it comes to sections/web parts/banner configurations/etc., the requests should be crafted manually as raw REST. Or using PnPjs or OfficeDevPnP.Core.Pages helpers. While an app is created in golang for a reason, I'd suggest checking what parts of pages API is needed and add custom methods with raw REST calls.