Sharepoint angulr REST API update file item userd field property
Hi All,
I'm working on a project using SharePoint with angular to upload files to document library, for now every thins is working fine and good but when updating the related item fields I was using JSOM its work but it increase the version # of the file which is
not acceptable to the client I found a solution to update the fields using REST without increasing the version # but the problem am facing now updating a user field it does not take the value it go to the success function but the field not set
here's my code
$scope.updateMetadataNoVersion=function(fileUrl) {
var fld=$scope.SelectedFolder.replace(_spPageContextInfo.siteAbsoluteUrl, "");
var restSource ="";
if(fld.replace("lists/DepartmentDocuments","")=="")
restSource = currentWeb.get_url() + "/_api/web/lists/getbytitle('DepartmentDocuments')/rootfolder/files/getbyurl(url='" + fileUrl + "')/listitemallfields/validateupdatelistitem";
else
restSource = currentWeb.get_url() + "/_api/web/getfolderbyserverrelativeurl('"+fld+"')/files/getbyurl(url='" + fileUrl + "')/listitemallfields/validateupdatelistitem";
var dfd = $.Deferred();
$.ajax(
'url': restSource,
'method': 'POST',
'data': JSON.stringify({
'formValues': [
'__metadata': { 'type': 'SP.ListItemFormUpdateValue' },
'FieldName': 'ShareWith',
'FieldValue': '24'
'bNewDocumentUpdate': true,
'checkInComment': ''
'headers': {
'accept': 'application/json;odata=verbose',
'content-type': 'application/json;odata=verbose',
'X-RequestDigest': $('#__REQUESTDIGEST').val()
'success': function (data) {
var d = data;
dfd.resolve(d);
'error': function (err) {
dfd.reject(err);
console.log(err);
return dfd.promise;
any help please im search about this since 3 days with no success
Thanx in advance
khatib7
Yes, your correct. The validateupdatelistitem method does not work with Lookup values. You will have to use the standard way of updating the list item via REST but it will increment the version. I agree with you that many customers want to upload files and
set data without creating 2 versions. This is how SharePoint upload works. However, the only way to do this with REST is to use the validateupdatelistitem method.
You can make a request for this to be added to SharePoint at User Voice:
http://officespdev.uservoice.com/
Blog | SharePoint Field Notes Dev Tools |
SPFastDeploy | SPRemoteAPIExplorer
Similar Messages
-
I have an app that can successfully get a list of a folders content. However, by default the list is limited to 200 entries. I luckily ran into this limit when getting the list on a folder that contained 226 entries and realized I needed to then request
a list of the next items but it wasn't obvious from the REST API document how to do that. I tried sending the skipToken query parameter and setting it to 0 initially and incrementing each time I sent the request but always got the same 200 items back. So,
how do I get the list of files and folders beyond the initial list?In SP2013 the skiptoken query parameter does not work with list items. You can look at the link below which discusses using the "__next" parameter.
http://stackoverflow.com/questions/18964936/using-skip-with-the-sharepoint-2013-rest-api
Blog | SharePoint Field Notes Dev Tools |
SPFastDeploy | SPRemoteAPIExplorer -
Im using CloverETL to connec to SharePoint using REST API.
my team is trying to get the List items in SharePoint using REST api. we are using the CloverETL tool using the REST api URL of the list and the credentials in SharePoint which has full control. Below is the rest command that we used.
/_api/web/lists/getbytitle('title of list')/items
when viewing this URL on the same Internet explorer with a user log on to sharepoint the XML of the list is successfully showing. but when we try to load it on the CloverETL tool using the same SharePoint credentials it says access is denied. Also when viewing
the URL to a browser with no other SharePoint sites open it also says access is denied.how is the webapp configured, as far as authentication?
Scott Brickey
MCTS, MCPD, MCITP
www.sbrickey.com
Strategic Data Systems - for all your SharePoint needs -
Sharepoint 2013 REST API calls with JASONP support
We are working on sharepoint online integration with PHP Based application. We need to provide REST API call which supports JSONP.
So is it possible to create new REST API Endpoints in Sharepoint online APP? Please sugggest right direction.Hi,
In Office 365 (aka SharePoint Online), you can simply consume the SharePoint data through REST API or WS call,but cannot create your own endpoint.
By default you can get the JSON response from the Office 365 REST API,its upto you to use the JSONP on your client compatibility not on SharePoint online REST API.
Sometime before I tried, It didn't work for me.
If you develop the AppModel, SPRequestor.js does the same job(overcome the Cross domain restriction) the what JSONP does.
Murugesa Pandian| MCPD | MCTS |SharePoint 2010 -
REST API Update blog post discussion
Discuss the
REST API Update blog post.Asymmetric keys stored in Key Vault are not intended for bulk data encryption. They are to be used as master keys. For bulk data encryption recommended method is to use an AES key and then WRAP this AES key with the RSA key stored in the key vault. Then
Store the WRAPPED AES key and the URI to the key in Key Vault as metadata with the encrypted data.
Depending on the scenario one could use a chain of keys that end in an asymmetric key in the Key Vault. It's difficult to recommend a solution without knowing your specific scenario. There can be several things to consider and many trade-off of different
approaches.
Reach out to the Key Vault Team via azurekeyvault at microsoft dot com if you want to discuss more.
Thanks,
Amit [ambapat@MSFT] -
SharePoint 2010 Rest API: How to add attachment to a list item via ListData.svc
Hi
I have set up a project using the REST API in c# Visual Studio 2010.
I have added a service reference to the URL //site/_vti_bin/listdata.svc/
I can query the list and get back data, but I can't retrieve the attachments.
I can write data to the list, but I can't add attachments.
Are there any examples of how to add or retrieve attachments using the REST API services.
Thanks
MikeHi,
If you want to work with list attachments using REST API, here are some links will show how to do this using Javascript:
http://msdn.microsoft.com/en-us/library/office/dn292553.aspx#FileAttachments
http://chuvash.eu/2013/02/20/rest-api-add-a-plain-text-file-as-an-attachment-to-a-list-item/
http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2013/06/27/how-to-get-list-item-attachments-using-rest-and-javascript-in-sharepoint-2013.aspx
Best regards
Patrick Liang
TechNet Community Support -
I am trying to invoke the SharePoint Rest Api using HTML page. I have included the Access Control Allow Origin to the web.config file. I am getting Readty State 4 and
Status Success but still I am getting the below error.
Refused to execute script from 'http://<server>/_api//web/lists?callback=jQuery172045857910416089_1430217181282&_=1430217363882' because its MIME
type ('application/atom+xml') is not executable, and strict MIME type checking is enabled.
<script>
$(document).ready(function () {
$("#KMPDiscussions").click(function () {
//$.support.cors = true;
$.ajax({
url: "http://<server>/_api//web/lists",
dataType: "jsonp",
type: "GET",
method: "GET",
contentType: "application/javascript",
headers: {
"content-type":
"application/json;odata=verbose",
"accept": "application/json;odata=verbose",
success: function onSuccess(data) {
alert("Inside Alert");
error: function onError(data){
alert("Error: "
+ data);
</script>
It always hits the error on callback.
Is there any other way that I can invoke SharePoint Rest Api from a Cross Domain. Please Help.Hi Chris,
Thanks for the reply,Here iam using different files to be uploaded in library.
please find the below snapshot of json response and ULS logs.
12/22/2013 18:31:15.02 w3wp.exe (0x3338) 0x401C SharePoint Foundation Files
abq2i High Could not get DocumentContent row: 0x80004005. 79f7629c-4694-c026-
3349-2049178ee919
12/22/2013 18:31:15.02 w3wp.exe (0x3338) 0x401C SharePoint Foundation Files
aiv4w Medium Spent 0 ms to bind -1 byte file stream 79f7629c-4694-c026-3349-
2049178ee919
12/22/2013 18:31:15.02 w3wp.exe (0x3338) 0x401C SharePoint Foundation Files
aise3 Medium Failure when fetching document. 0x80070012 79f7629c-4694-c026-
3349-2049178ee919
12/22/2013 18:31:15.39 w3wp.exe (0x3338) 0x0D4C SharePoint Foundation
Database ab1a9 High Failed to get document content data.
System.ComponentModel.Win32Exception (0x80004005): Cannot complete this function at
Microsoft.SharePoint.SPSqlClient.GetDocumentContentRow(Int32 rowOrd, Object
ospFileStmMgr, SPDocumentBindRequest& dbreq, SPDocumentBindResults& dbres)
79f7629c-76ab-c026-3349-2c9132b13e9a
12/22/2013 18:31:15.39 w3wp.exe (0x3338) 0x4184 SharePoint Foundation
Database ab1a9 High Failed to get document content data.
System.ComponentModel.Win32Exception (0x80004005): Cannot complete this function at
Microsoft.SharePoint.SPSqlClient.GetDocumentContentRow(Int32 rowOrd, Object
ospFileStmMgr, SPDocumentBindRequest& dbreq, SPDocumentBindResults& dbres)
79f7629c-76ab-c026-3349-281167b6cd09
Thanks again,
Naresh. -
POST to SharePoint Online REST API - 405 Method Not Allowed
Good afternoon,
I am writing C# with the intention of uploading a file to a document library using the REST API.
The code must run on an on-premise machine and the target SharePoint site is in SharePoint Online (Office 365 E-plan). It has to handle large files, so CSOM is not an option.
I have successfully tested a few different "get" messages, so I believe the authentication part is working. However, so far I have no such luck with POST.
In fiddler, my most recent attempt looks like this (I redacted the parts in <> because I'm not sure if they are sensitive somehow):
POST http://org.sharepoint.com/sites/site/_api/web/GetFolderByServerRelativeUrl('Documents')/Files/add(url='test2.txt',overwrite=true) HTTP/1.1
Accept: application/json;odata=verbose
X-RequestDigest: <digest value>,15 Jan 2014 17:48:49 -0000
BinaryStringRequestBody: true
Host: org.sharepoint.com
Content-Length: 6
Expect: 100-continue
stuff!
Seems like it should work, but the result is "301 Moved Permanently." This request is immediately followed by this one:
GET https://org.sharepoint.com/sites/site/_api/web/GetFolderByServerRelativeUrl('Documents')/Files/add(url='test2.txt',overwrite=true) HTTP/1.1
Accept: application/json;odata=verbose
X-RequestDigest: <formdigest>,15 Jan 2014 18:01:51 -0000
BinaryStringRequestBody: true
Host: org.sharepoint.com
Cookie: FedAuth=<cookiestuff>; rtFA=<cookiestuff>
Response:
HTTP/1.1 405 Method Not Allowed
Cache-Control: private, max-age=0
Transfer-Encoding: chunked
Content-Type: application/json;odata=verbose;charset=utf-8
Expires: Tue, 31 Dec 2013 18:01:52 GMT
Last-Modified: Wed, 15 Jan 2014 18:01:52 GMT
Server: Microsoft-IIS/7.5
X-SharePointHealthScore: 0
X-SP-SERVERSTATE: ReadOnly=0
SPClientServiceRequestDuration: 25
X-AspNet-Version: 4.0.30319
SPRequestGuid: dd936a9c-f4fc-a05d-27e1-2c948f0eb575
request-id: dd936a9c-f4fc-a05d-27e1-2c948f0eb575
X-FRAME-OPTIONS: SAMEORIGIN
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 16.0.0.2308
X-Content-Type-Options: nosniff
X-MS-InvokeApp: 1; RequireReadOnly
P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
Date: Wed, 15 Jan 2014 18:01:51 GMT
128
{"error":{"code":"-1, Microsoft.SharePoint.Client.ClientServiceException","message":{"lang":"en-US","value":"The HTTP method 'GET' cannot be used to access the resource 'Add'. The operation type of the resource is specified as 'Default'. Please use correct HTTP method to invoke the resource."}}}
0
So it looks to me as if my request is being redirected to the same address but with a "GET" method rather than "POST," resulting in the 405 Method Not Allowed error because "add" needs POST.
I appreciate any insight you can offer.Mkay, perhaps I should rephrase:
I want to synchronize a SharePoint Online library with a local file share. There are a large quantity of files, and many of them are large (actually it's all too large to fit in one SharePoint Online site collection due to the 100gb limit, but I'll
deal with that separately).
The approach I was working on here was to create a C# method basically like this: UploadFile(File, Destination, username, password). I would use this method in the script component of an SSIS package which would run on a server and push the files
up to SPO, but right now I'm just testing it as a console application.
I got the CSOM methods working, but obviously that won't work because the files are too large. Above is what's happening with the REST version.
Can anyone see what's wrong with my REST calls - why is it being redirected as a GET request? Is this even possible? -
SharePoint 2013 REST API with C# - Mapping HTTP verbs to data operations - Requesting FormDigest
SharePoint REST interface maps HTTP verbs to data operations. Endpoints that represent
Read operations map to HTTP
GET commands. Endpoints that represent update operations map to HTTP
POST commands, and endpoints that represent update or insert operations map to HTTP
PUT commands (Ref:
How to: Complete basic operations using SharePoint 2013 REST endpoints).
Is this mapping of HTTP verbs to CRUD operations a design paradigm or whether there are other technical reasons to this mapping
Is is possible to use a GET command for say an update operation or a POST for say a read operation.If so, what consideration make the choice of either usage
In the code snippet below FormDigest is requested as POST, why not use GET here?
private static string GetFormDigest(string webUrl)
//Validate input
if (String.IsNullOrEmpty(webUrl) || String.IsNullOrWhiteSpace(webUrl))
return String.Empty;
//Create REST Request
Uri uri = new Uri(webUrl + "/_api/contextinfo");
HttpWebRequest restRequest = (HttpWebRequest)WebRequest.Create(uri);
restRequest.Credentials = CredentialCache.DefaultCredentials;
restRequest.Method = "POST";
restRequest.ContentLength = 0;
//Retrieve Response
HttpWebResponse restResponse = (HttpWebResponse)restRequest.GetResponse();
XDocument atomDoc = XDocument.Load(restResponse.GetResponseStream());
XNamespace d = "http://schemas.microsoft.com/ado/2007/08/dataservices";
//Extract Form Digest
return atomDoc.Descendants(d + "FormDigestValue").First().Value;
Thanks - AbhishekMany SharePoint REST api methods use parameters. It is much more efficient to post parameters than use query string variables. Many times complex types are sent and these require json notation objects posted in the body. In the case of "_api/contextinfo,
it is recommended to use POST rather than a GET when using sensitive data. GET responses can be cached. Since you are getting a security token back in that call it is recommended to use a POST.
http://blog.teamtreehouse.com/the-definitive-guide-to-get-vs-post
Blog | SharePoint Field Notes Dev Tools |
SPFastDeploy | SPRemoteAPIExplorer -
HTTP 403 while using SharePoint Online REST API anonymously
Hey Team,
While using REST API to get list items (SharePoint Online) anonymously, I am getting HTTP 403 error:
Request: http://server/site/_api/web/lists('guid')/items?$select=Title,Products/Name&$expand=Products/Name
Response: HTTP 403 : System.UnauthorizedAccessException : Access denied. You do not have permission to perform this action or access this resource.
Authenticated users do not face this issue. The list has anonymous access (View) enabled. Anonymous users can access the lists without facing any issue.
I am not sure and could not able to find any link that says anonymous users can't use REST API to get SPListItems. Any input in this regard will be highly appreciated.
Regards,
Sanjay
Either you love IT or leave ITHi,
From this documentation from MSDN about
Reading data with REST, “Note that you cannot obtain an access token from code that is running on a browser client. You must obtain the access token from code that is running
on a server”, it will only allow the authenticated users who has an access token to access the REST API.
The two links below will provide more information about authentication in SharePoint 2013:
http://msdn.microsoft.com/en-us/library/fp142382.aspx
http://msdn.microsoft.com/en-us/library/jj687470.aspx
Thanks
Patrick Liang
Forum Support
Please remember to mark the replies as answers if they
help and unmark them if they provide no help. If you have feedback for TechNet
Subscriber Support, contact [email protected]
Patrick Liang
TechNet Community Support -
Sharepoint break REST API connection (anonymous), possible bug in sharepoint
Hello, I have following problem when I test Rest API using fiddler :
As i see, server just close connection and does not return any status code at all. I expect to see at least 401 or 500 exception. Is that SharePoint
bug, or this is expected behavior of the SharePoint? (according HTTP protocol & according SharePoint Rest API )
Web application settings and site collection settings:Hi,
Can you access the site from browser?
If you can, would you mind providing more details about how you execute your request? Anonymous or with credential?
How about setting the “Anonymous Access” to “Anonymous users can access Entire Web site”? It would allow anonymous users access the site.
Feel free to reply if the issue still exists.
Best regards
Patrick Liang
TechNet Community Support -
SharePoint 2010 REST API, User SiteColumn not coming
When Create User sitecolumn from front end(using default SharePoint Setting area) and then fetch list through REST API then it comes parfactly but
When I create User sitecolumn's xml from Visual Studio and then add that sitecolumn in contenttype and then in list and then fact list through REST API then it does come in api xml.Hi Manish<o:p></o:p>
<o:p></o:p>
I can understand your issue, but not sure what could be the reason behind this behavior. To help you resolve the issue, we will need troubleshooting to be done at your end. I would request you
to open a support ticket with Microsoft to help us resolve your issue as quickly as possible.
For more information about Microsoft Support please read the article http://support.microsoft.com/gp/proffaq/en-gb
<o:p></o:p>
Thanks,
Bharat Rathod, <u1:p></u1:p><o:p></o:p>
Microsoft Online Community Support<u1:p></u1:p><o:p></o:p> -
CSOM/REST API not returning Resource Custom Fields
Can anyone verify that you can access resource custom fields using CSOM or the REST API? I'm finding that even though I have 6 fields that aren't visible. Anyone have any ideas?
I determined that the custom fields need to be set first before they are returned by the API. Is it even possible to set a custom field on a ProjectResource or EnterpriseResource using CSOM or JSOM?
-
SharePoint 2013 Rest Api - How to get List Items
Can anyone let me know why the below method fails? I am not getting where i am making mistake. Please help
function getListItems(term) {
var caml = "<View><Query><Where><BeginsWith><FieldRef Name=Title/><Value Type='Text'>" + term + "</Value></BeginsWith></Where></Query></View>";
var requestData = { "query": { "__metadata": { "type": "SP.CamlQuery" }, "ViewXml": caml } };
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/getbytitle('SampleList')/Getitems",
method: "POST",
data:requestData,
headers: {
"accept": "application/json; odata=verbose",
"content-type": "application/json; odata=verbose"
success: function (data) {
$("#countItem").html("Pass");
error: function (data) {
$("#countItem").html("Fail");
Below is the responseText (log)
"{\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.ClientServiceException\",\"message\":{\"lang\":\"en-US\",\"value\":\"The HTTP method \'GET\' cannot be used to access
the resource \'GetItems\'. The operation type of the resource is specified as \'Default\'. Please use correct HTTP method to invoke the resource.\"}}}"
NavaneethFinally executed successfully using below code. The learning is we need to use type:"POST" instead of method:"POST"
function getListItems(term) {
var urltest = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/lists/getByTitle('SampleList')/getitems(<Query><Where><BeginsWith><FieldRef">query=@v1)?@v1={\"ViewXml\":\"<View><Query><Where><BeginsWith><FieldRef
Name='Title'/><Value Type='Text'>" + term + "</Value></BeginsWith></Where></Query><RowLimit>1</RowLimit></View>\"}";
$.ajax({
url: urltest,
type: "POST",
headers: {
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"Accept": "application/json; odata=verbose",
"Content-Type": "application/json; odata=verbose"
contentType: 'application/json',
success: function (data) {
if (data.d.results.length != 1) {
$("#countItem").html("Pass");
$("#" + term).parent().parent().prop('disabled', true);
$("#" + term).removeAttr("onclick");
$("#" + term).css('cursor', 'default');
$("#" + term).parent().unbind("mouseenter mouseleave");
error: function (data) {
$("#countItem").html(urltest);
Navaneeth -
SharePoint 2013 Rest API - How to get the item count with startsWith
Hi All,
I am using the below url to get the item count for specfied startsWith. For example I want to know how many items are there in the list which starts with "A". When i hit the below url in the address bar i am getting HTTP not found.
siteURL/sites/Apps/SharePointApp3/_vti_bin/listdata.svc/SampleList/items?$filter=startsWith(Title,’A’)
Navaneethwhat
is SharePointApp3.
here.
it is a webpart.
this will not work on webpart\apps
Also I am not sure if it will work with specific SampleList
Try
siteURL/sites/Apps/SharePointApp3/SampleList/_vti_bin/listdata.svc/Keywords?$filter=substringof('r',Title)
If this helped you resolve your issue, please mark it Answered
Maybe you are looking for
-
Set Text of Container to HTML not working
I have a div tag named "theAnswer" on a page. When the user clicks the "Submit" button, I want some text to appear inside the div that has HTML formatting. The HTML code for the text I want to appear is below: You are correct! We are committed to co
-
2012 Dynamic Event Registration Array of Controls
In upgrading to LV2012, I have discoverd what may be a bug, or at least an incompatability between 2011 and 2012 with respect dynamic event registration of an array of controls as opposed to individual control references. This bit of code worked in 2
-
I'm working on a file and when I publish the output window pops up with the number '20' in it. Anyone know what this means? Thanks, Gary
-
Netcfg v2.1.0 release candidate 1
This release is pretty much 2.1.0 unless I broke something badly. Barring any problems, I'll probably rename it and release it as 2.1.0 next week once I've updated the documentation. Then I can start on 2.2. The changelog can be found on Gitweb - It'
-
Hi anyone had probs getting on e-bay? I can access all other sites like FT, facebook, BBC etc etc but when I try to go to e-bay the phone goes into a spasm, like its trying to connect but can't. Any ideas? It fine if I then go to bookmarks or another