Create List item Sharepoint 2010 REST with Choice column

I am trying to create one new list item in Sharepoint 2010 using REST.

Coding

var itemProperties = { 'Title': ;Raja;, //Single line String 'Expiry_x0020‌​_Date': "02/02/2016", //Date 'Permission_x0020‌​_Type': 'Add' //Choice Column };  createListItemREST('http://xyz:5000/sites/n/', 'L2', itemProperties, function(task){  console.log('Task' + task.TaskName + ' has been created');}, function(error){ console.log(JSON.stringify(error)); });  function createListItemREST(webUrl,listName, itemProperties, success, failure) {     $  .ajax({         url: webUrl + "/_vti_bin/listdata.svc/" + listName,         type: "POST",         processData: false,         contentType: "application/json;odata=verbose",         data: JSON.stringify(itemProperties),         headers: {             "Accept": "application/json;odata=verbose"         },         success: function (data) {             success(data.d);         },         error: function (data) {             failure(data.responseJSON.error);         }     }); } 

i am getting following error.

400 Bad request

{“code”:””,”message”:{“lang”:”en-US”,”value”:”Error processing request stream. The property name ‘Expiry_x0020‌​_Date’ specified for type ‘Microsoft.SharePoint.DataService.L2Item’ is not valid.”}}

Note: When trying with only Title column this coding is working.

Column Details

Title – Single Line Text

Business Justification for Access – Choice Column

Expiry Date – Date and Time

Permission Type – Choice Column

 <ViewFields xmlns="http://schemas.microsoft.com/sharepoint/soap/">       <FieldRef Name="Attachments" />       <FieldRef Name="LinkTitle" />       <FieldRef Name="Business_x0020_Justification_x00" />       <FieldRef Name="Expiry_x0020_Date" />       <FieldRef Name="Permission_x0020_Type" />  </ViewFields> 

Good practices designing a JSON REST api

I need to design a REST API that is basically a mirror of a database.

Let’s suppose we have 3 tables:

  1. Table A: ID, NAME
  2. Table B: ID, NAME, A_ID
  3. Table C: ID, NAME, B_ID

Table B has a FK to A, and B has a FK to B.

Now, let’s say we need an api to update/get elements from that database using a JSON REST api.

For Object A, a Json would be easy:

{ "id":"0001", "name":"Object A 0001" } 

A POST/PUT method to /objectA would receive that JSON as body. The GET method, /objectA/0001 will return a single object as JSON. The GET method, /objectA will return that a JSON list:

[     {     "id":"0001",     "name":"Object A 0001"     },     {     "id":"0002",     "name":"Object A 0002"     } ] 

Now, the problem come with Oject B. Let’s say we have and element in table B, with ID 1001, that points to an element with id 0001 in table A.

What is the correct representation of this link using JSON? I have two options:

1) Having a simple code that include the ID to A:

{ "id":"1001", "name":"Object B 1001", "objectAId":"0001" } 

2) Including the entire object A:

{ "id":"1001", "name":"Object B 1001", "A":{     "id":"0001",     "name":"Object A 0001"     } } 

(1) Has easier updates. I only need to send the objectAId with the Id. (2) Would need to send something like this to create/update a new element:

   {     "id":"1002",     "name":"Object B 1002",     "A":{         "id":"000X",         }     } 

But (2) would make more useful the GET method because I also receive the information about the A link object. In (1) I will only receive the code/id. And If I need more information, I would need to do a GET to show A information.

Now, for Table C/Object C. Using (1) Wouldn’t cause any problem. But If I use (2). The question is, Should I give also the content for Object B? Lets suppose we have and Object C with Id 2001 that points to the object B 1001. How should the JSON be?

Including only headers:

{ "id":"2001", "name":"Object C 2001", "B":{     "id":"1001",     "name":"Object B 1001"     } } 

Or Include the entire thing:

{ "id":"2001", "name":"Object C 2001", "B":{     "id":"1001",     "name":"Object B 1001",     "A":{         "id":"0001",         "name":"Object A 0001"         }     } } 

Im still looking what is the best way to do this. And of course. Any book/blog that talks about this would be appreciated.

REST query not able to filter by FileRef, works in on-premise but not online

I have a REST query which works as it should in SharePoint 2013 on-premise, but not in SharePoint Online.

The query is as follows (after encoding):

https://<tenant>.sharepoint.com/projects/1/_api/web/Lists(guid'37D38739-88BF-4EC4-B188-F334F88E2566')/Items?$  expand=File&$  select=FileRef,File/ServerRelativeUrl&$  filter=startswith(FileRef,%27%2Fprojects%2F1%2FShared%20documents%2Ftestfolder1%2F%27) 

If I remove the filter, I see all my files and folders in the result as expected. As soon as the filter is turned on, I get nothing. I can see from the the result when I don’t include the filter that several items have the value I am attempting to filter on. Changing the filter to FileRef eq ‘specific value’ yields no results either.

Is it not possible to use filter on this field in SharePoint online?

REST query not able to filter by FileRef, works in on-premise but not online

I have a REST query which works as it should in SharePoint 2013 on-premise, but not in SharePoint Online.

The query is as follows (after encoding):

https://<tenant>.sharepoint.com/projects/1/_api/web/Lists(guid'37D38739-88BF-4EC4-B188-F334F88E2566')/Items?$  expand=File&$  select=FileRef,File/ServerRelativeUrl&$  filter=startswith(FileRef,%27%2Fprojects%2F1%2FShared%20documents%2Ftestfolder1%2F%27) 

If I remove the filter, I see all my files and folders in the result as expected. As soon as the filter is turned on, I get nothing. I can see from the the result when I don’t include the filter that several items have the value I am attempting to filter on. Changing the filter to FileRef eq ‘specific value’ yields no results either.

Is it not possible to use filter on this field in SharePoint online?

REST query not able to filter by FileRef, works in on-premise but not online

I have a REST query which works as it should in SharePoint 2013 on-premise, but not in SharePoint Online.

The query is as follows (after encoding):

https://<tenant>.sharepoint.com/projects/1/_api/web/Lists(guid'37D38739-88BF-4EC4-B188-F334F88E2566')/Items?$  expand=File&$  select=FileRef,File/ServerRelativeUrl&$  filter=startswith(FileRef,%27%2Fprojects%2F1%2FShared%20documents%2Ftestfolder1%2F%27) 

If I remove the filter, I see all my files and folders in the result as expected. As soon as the filter is turned on, I get nothing. I can see from the the result when I don’t include the filter that several items have the value I am attempting to filter on. Changing the filter to FileRef eq ‘specific value’ yields no results either.

Is it not possible to use filter on this field in SharePoint online?

Share document to multiple users using REST api in SharePoint 2013

I am using SharePoint 2013 rest api. I want to share SharePoint document among multiple users Here is my rest endpoint

https://XXXXXX.sharepoint.com/sites/XXXX-Test-SharePoint/_api/web/Lists(%27%7BB17B74B2-6EB4-4D3E-9DD6-4CCD0202C30D%7D%27)/GetItemById(90)/ShareObject 

and passing POST data to endpoint as below

{"peoplePickerInput":[{"Key":"i:0#.f|membership|john.miller@XXXXX.com","Description":"john.miller@XXXXX.com","DisplayText":"John Miller ","EntityType":"User","ProviderDisplayName":"Tenant","ProviderName":"Tenant","IsResolved":true,"EntityData":{"IsAltSecIdPresent":false,"Title":"Partner","Email":"john.miller@XXXXX.com","MobilePhone":0,"ObjectId":"c8dd8ac6-fb06-4d59-94e0-6e525b98146d","Department":"Professional Services Americas"},"MultipleMatches":[]},{"Key":"i:0#.f|membership|david.miller@XXXXX.com","Description":"david.miller@XXXXX.com","DisplayText":"david Miller ","EntityType":"User","ProviderDisplayName":"Tenant","ProviderName":"Tenant","IsResolved":true,"EntityData":{"IsAltSecIdPresent":false,"Title":"Partner","Email":"david.miller@XXXXX.com","MobilePhone":0,"ObjectId":"c8dd8ac6-fb06-4d59-94e0-6e525b98146d","Department":"Professional Services Americas"},"MultipleMatches":[]}],"propagateAcl":true,"roleValue":"role:1073741827","sendEmail":true,"useSimplifiedRoles":true,"emailSubject":"Sharing Test","emailBody":"Shared you folder..","includeAnonymousLinkInEmail":false} 

After executing above url, i am getting below response

{"odata.error":{"code":"-1, Microsoft.Data.OData.ODataException","message":{"lang":"en-US","value":"A node of type 'StartArray' was read from the JSON reader when trying to read a value of a property; however, a 'PrimitiveValue' or 'StartObject' node was expected."}}} 

SharePoint 2013 create text file in a library via REST

I am trying to create a text file in alibrary named “testRestDocs” The dev tool console the following error message:

 _spPageContextInfo.webAbsoluteUrl + "_api/web/getfolderbyserverrelativeurl('/s/KM/box/pg/testRestDocs')/Files/add(url='" + docTitle +"',overwrite=true)"; **undefined**  $  (function () { 

bindButtonClick(); }); function bindButtonClick() { $ (“#btnSubmit”).on(“click”, function () { createDocument(); }); } function createDocument() { var docTitle = $ (“#txtDocumentTitle”).val() + “.txt”; var docContent = $ (“#txtDocumentContent”).val(); var fullUrl = _spPageContextInfo.webAbsoluteUrl + “_api/web/getfolderbyserverrelativeurl(‘/s/KM/box/pg/testRestDocs’)/Files/add(url='” + docTitle +”‘,overwrite=true)”; $ .ajax({ url: fullUrl, type: “POST”, data: docContent, headers: { “accept”: “application/json;odata=verbose”, “content-type”: “application/json;odata=verbose”, “X-RequestDigest”: $ (“#__REQUESTDIGEST”).val() }, success: onQuerySucceeded, error: onQueryFailed }); } function onQuerySucceeded() { $ (“#divResults”).html(“Document created!”); } function onQueryFailed() { alert(‘Error!’); }

rest service with digitally signed parameters

I’d like to build a rest service that will accept objects that has digital signature. This service has to support both xml and json data serialization formats. I’d like to use .Net core framework to build this service.

Controller has to check that digital signature is valid and dto properties were not modified.

This signature has to be stored (in the database) and used (if required) to verify that message was not changed while processing.

Sending flow is like below

  • client fills object with data
  • client calculates hash and sign it
  • client sends object and signature to the service
  • service calculate hash from object properties and verify signature
  • object and signature is stored in the db

The question is how to define and share hash calculation logic between service and client? Please note that client can be implemented using different framework or programming language.

UPD: Or, probably there is an alternative way to check data integrity that are sent by the client. Like Amazon has implemented.

I’ve thought that dto can have string GetHashData() method that will concatenate valuable dto properties to the string. Then hash can be calculated for this and is used to sign or to check the signature.

However having method in the dto object does not look good.

I can implement some helper class and use it in the rest service that to calculate hash for each object type. But this logic has to be implemented on the client side as well. It can make usage of the service a little bit tricky.

I know that both xml and json has digital signature, like XMLDSIG and JWS. But it makes digital signature to be dependent from the format that was used by the client to talk with service. I can not use JWS or XMLDSIG if object was deserialized and passed as parameter to the REST controller.

Wildcard Query for SharePoint Rest API

I tried using this example as search parameter “Share*” but the result return nothing.

            KeywordQuery keywordQuery = new KeywordQuery(clientContext);              keywordQuery.QueryText = SearchParameter;              keywordQuery.EnablePhonetic = true;                keywordQuery.EnableOrderingHitHighlightedProperty = true;             //keywordQuery.SummaryLength = 500;               SearchExecutor searchExecutor = new SearchExecutor(clientContext);              ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);              clientContext.ExecuteQuery(); 

Use REST API to get group SharePoint 2010

I have a group on my site – I want users to be able to add and remove themselves from this group via a button on a page. What is the URL I should be using as a parameter to retrieve the group and the group membership? All the examples I’ve seen involve the 2013 interface, which returns a 404 when I pass it the parameter.

/_api/web/sitegroups/getbyname(xxxx)  

gives me a 404.

Unfortunately I can’t wait to do this until we finish migrating to SharePoint Online.