I have a simple mvc api which saves a url to SQL and retrieves it. For some people it works just fine, but some of them do not have access.

   Error: {"readyState":4,"responseText":"
    Server Error

    401 - Unauthorized: Access is denied due to invalid credentials.

    You do not have permission to view this directory or page using the credentials that you supplied.

I use the following code to call the api. I have created an html page with a input text box and uploaded it to SharePoint. I am using a content editor to display the html.

    $(document).ready(function() {

     $("#btnSubmit").click(function () { 
        var res = encodeURIComponent(document.getElementById("txtSM").value);

         if(document.getElementById("txtSM").value.length > 0){

                       url: "https://spc/api/UrlApi/AddUrl?Url=" + res,
                       method: "GET",
                       headers: { "Accept": "application/json; odata=verbose" },
                       dataType: 'json', 
                       success: function (data) {


                      error: function (error) {
                          alert("Error: "+  JSON.stringify(error));
                alert("Please enter a url in the textbox");


I am not sure now where do I have to give permission?


One of the users entered the api url directly on the browser and was able to save and able to get a response back. But when he tried via SharePoint, he got the error above again.

  • Do they users have permission on database to save the url in SQL? – Ganesh Sanap Nov 13 '18 at 19:19
  • Please read my EDIT 1 above – Burre Ifort Nov 13 '18 at 19:26
  • Try adding this header in your code ` xhrFields: { withCredentials: true },` .Also check the permission of the user on the list/library from where they are trying to fetch the data – Ankit Katiyar Nov 14 '18 at 5:34
  • They are writing to SQL table and retrieving it from there. I will give 'xhrFields a try. Let you know. – Burre Ifort Nov 14 '18 at 5:55

Your Answer

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

Browse other questions tagged or ask your own question.