Domanda

I'm following this tutorial on using Excel Services REST api and trying to read a range.

If I paste the url into my browser it works and I see the range in my browser.

http:<site>/_vti_bin/ExcelRest.aspx/<library>/<file>/Model/Ranges('<range>')

But if I use jquery ajax in a content or script editor webpart, it doesn't work. First I get an authorization challenge which doesn't accept my credentials and then if I cancel that, I get a 401 unauthorized error.

$.ajax({
    url:exact_same_url_as_above,
    type:"GET",
    headers:{
        "accept": "application/json;odata=verbose",
        "content-type": "application/json;odata=verbose",
        "X-RequestDigest":$("#__REQUESTDIGEST").val()
    }
})
.done(function(data,status,xhr){
    console.log(data);  
})

I am the site collection owner and have full control over everything. I have lots of REST api code running in other locations in the site, but this is the first that uses the 2010 _vti_bin access point.

Any idea what is going on?

È stato utile?

Soluzione

Using postman to run a few tests.

When I include the headers:

    "accept": "application/json;odata=verbose",
    "content-type": "application/json;odata=verbose",

I get 401 Unauthorized like you are experiencing. Not even admins can draw blood from a turnip or json from ExcelRest.aspx

Solution:

If I remove the Content-Type entry I get a response back with the data I am looking for.

Getting the data you are looking for:

Use either the $format=ATOM or $format=HTML or $format=image URL parameters to drive the response content type.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top