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


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.

3 Answers 3


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.


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)

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:

  .then(function (response) {
    console.log('List Id: ' + response.body.d.Id);
    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
    Commented Jul 17, 2017 at 12:37

Your Answer

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

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