3

I have a Office 365 Organizational SharePoint Online Account. I want to Add Few Tasks in one of the list programmatically.

I saw options of using JavaScript API or hitting the REST URL's

https://company.sharepoint.com/sites/ABC/_api/web/lists/getbytitle('Tasks')/items

When I tried to access the lists using the URL above using a REST Client (While I was signed in to SharePoint in the browser), I was able to successfully access the API. I provided following things in the header

Accept, Content Type and X-RequestDigest

Now, I want to access the same programmatically from PHP or JavaScript or in worst case Java.

My Question is how do I authenticate before accessing the API's.

I also tried to authenticate (REST Call using Client - Not logged in the browser) using this URL - https://login.microsoftonline.com/extSTS.srf and passing the XML body with username and password.

But, it returned me with following error

Direct login to WLID is not allowed for this federated namespace

Please guide me on how to Authenticate using Organizational Credentials to access SharePoint REST API.

I cannot use Visual Studio or C# anywhere. ONLY PHP, JavaScript or worst case -- Java.

Thanks in Advance.

1

I found one API for this. Its a wrapper for SharePoint Online REST/ODATA API. I haven't tried this but it seems pretty promising. You can get the API from Github.

Note: I am not the author of this API, also I haven't tried this API.

0

Outside of the browser you should be using OAuth to authorize your application to access SharePoint on behalf of a user. The normal flow involves sending the user to the authorization endpoint where they authenticate and return with a code which you provide to the token endpoint in order to acquire the actual OAuth access token which you can then use for making your REST calls. Unfortunately the execution of this flow turns out to be a rather arduous process when not using Visual Studio and the CLR (e.g. C#, VB etc.) and is too complicated to answer completely here but I will give you some of the basics.

  1. You will need to register an application in Azure Active Directory (AAD) in order to obtain a Client ID and Client Secret (Manually register your app with Azure AD so it can access Office 365 APIs)
  2. Fetch an auth code and trade it in for an access token (Authorization Code Grant Flow)
0

It's going to be tricky to authenticate via REST from PHP or Java but it's certainly possible. This the example of how you can do it using C#. You can have a look at the Authenticator.cs file and just try to rewrite it using the language of your choice.

As per, JavaScript you can have a look at the the great sp-request library. I tried it from node and it works great. I hope it will work in browsers just as well.

Create sprequest function:

var spr = require('sp-request').create(credentialOptions);

Get list by title:

spr.get('http://sp2013dev/sites/dev/_api/web/lists/GetByTitle(\'TestList\')')
  .then(function (response) {
    console.log('List Id: ' + response.body.d.Id);
  })
  .catch(function(err){
    console.log('Ohhh, something went wrong...');
  });
  • am having username and password how to for that credentialOptions key value pair ?? var spr = require('sp-request').create(credentialOptions); – Subha Jul 17 '17 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.