I am just developing an sharepoint application in mobile by using javascript, But dont know how to start. Is there any api in javascript(jquery) to authenticate in sharepoint and get user details.
Thanks in advance.
I am just developing an sharepoint application in mobile by using javascript, But dont know how to start. Is there any api in javascript(jquery) to authenticate in sharepoint and get user details.
Thanks in advance.
For developing web applications in SharePoint 2013 and Online you have 2 main options for querying data from lists, libraries or users details, The Client Object Model and the SharePoint REST API.
Here is an example of updating list data using the Client object model
ClientContext context = new ClientContext("http://SiteUrl");
List announcementsList = context.Web.Lists.GetByTitle("Announcements");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem newItem = announcementsList.AddItem(itemCreateInfo);
newItem["Title"] = "My New Item!";
newItem["Body"] = "Hello World!";
newItem.Update();
context.ExecuteQuery();
Another option, which is preferred is to use the REST API to query endpoints. There are a number of APIs you can query in SharePoint, the most useful will be the Search API or the Social API, User Profile API, etc...
Here is an example endpoint you could query to retrieve JSON data, you can put it in the browser or post to the url to see what is returned.
http://<siteCollection>/<site>/_api/social.feed/my/feed/post
Here is an example of getting user profile data for the current user in SharePoint
$(document).ready(function(){
// Ensure the SP.UserProfiles.js file is loaded
SP.SOD.executeOrDelayUntilScriptLoaded(loadUserData, 'SP.UserProfiles.js');
});
var userProfileProperties;
function loadUserData(){
var clientContext = new SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
//Get properties of the current user
userProfileProperties = peopleManager.getMyProperties()
clientContext.load(userProfileProperties);
clientContext.executeQueryAsync(onSuccess, onFail);
}
function onSuccess() {
console.log(userProfileProperties.get_displayName());
}
function onFail(sender, args) {
console.log("Error: " + args.get_message());
}