0

If I have a site, completely independent of Microsoft (a Wordpress site), could I access data from lists on a SharePoint site using JS on the external site? For example, I can access lists with the following code in the SharePoint site:

function retrieveChemicalsListItems() {
var clientContext = new SP.ClientContext('/sites/________/');
var oList = clientContext.get_web().get_lists().getByTitle('ChemicalsTable');

var camlQuery = new SP.CamlQuery();
//<Where><Geq><FieldRef Name=\'ID\'/>' + '<Value Type=\'Number\'>1</Value></Geq></Where> <RowLimit>10</RowLimit>
camlQuery.set_viewXml('<View><Query></Query></View>');
this.collListItem = oList.getItems(camlQuery);

clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onChemicalsQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));        

}

If I just took this, with the same URL and everything, and put it on any other site, would it work just the same?

1 Answer 1

1

Do you use Sharepoint online or on premise? If you use online, go to link with tutorial for SP Online. But it's not good idea to pass login and password through js code, because everybody will see it. It's a security threat.

Or see this for onprem: link 1, link2. Also, using CSOM can help with developing application:

using (ClientContext context = new ClientContext("sp_site_url")) {
    context.Credentials = new NetworkCredential("user", "password", "domain");
    List list = context.Web.Lists.GetByTitle("MyList");
    context.Load(list);
    context.ExecuteQuery();
    // process list
}

Another way is develop your own web service which will have access to Sharepoint site and you will be able to call it with using your custom authentication.

Sign up to request clarification or add additional context in comments.

1 Comment

This looks like exactly what I need but the link they provide at the bottom for accessing local data files using Html and Chrome is invalid and I can't find a solution to this error anywhere else. EDIT: This is in reference to the first link you provided.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.