3

I'm putting together a test app on O365, it calls data from the UK police, cos its interesting.

I am using the SP.WebRequestInfo

The Code is correct, I make other calls to the same service fine, but this call returns more data than the others and the nature of the API means I cant trim it down further.

http://data.police.uk/api/crimes-street/all-crime?lat=52.629729&lng=-1.131592&date=2013-01

the error returned is a "403 The Size of response from the remote endpoint exceeds configured ......"

The API is anonymous, the 403 is not on the remote end it SharePoint

So there is a setting, somewhere.

There must be a way to change this configured value.

Does anyone know how to set it in 365. ? Does anyone know how to set it on-prem. ?


 getStreetCrime: function ($scope) {
        //an example call, passing in preset co-ords and date
        //In another area this gives an error "403 the response is too big (or similar)" which
        //Sucks, I don't know how to alter the response size limits.
        var deferred = $q.defer();
        var context = SP.ClientContext.get_current();
        var request = new SP.WebRequestInfo();
        request.set_url(
            "http://data.police.uk/api/crimes-street/all-crime?lat=52.6143247&lng=-1.6677285&date=2013-01"
            );
        request.set_method("GET");

        // We need the response formatted as JSON.
        request.set_headers({ "Accept": "application/json;odata=verbose" });
        var response = SP.WebProxy.invoke(context, request);

        context.executeQueryAsync(
            function () {

                var data = [];

                if (response.get_statusCode() == 200) {

                    data = JSON.parse(response.get_body());
                    var dataMap = $.map(data, function (item) {
                        return {
                            Category: item.category,
                            Street: item.location.street.name,
                            Lat: item.location.latitude,
                            Long: item.location.longitude
                        };
                    });

                    $scope.$apply(deferred.resolve(dataMap));
                }
                else {
                    $scope.$apply(deferred.reject(response.get_statusCode() ));
                }
            },
            function () {
                $scope.$apply(deferred.reject(response.get_statusCode() ));
            }
       );

        return deferred.promise;
    }
1

According to How to: Query a remote service using the web proxy in SharePoint 2013 the response’s size of web proxy requests must not be larger than 200 KB otherwise the error: The size of the response from the remote endpoint exceeds the configured limit will occur.

Solution

Utilize another JS library to perform REST query from a remote service, for example:

var getStreetCrime =  function () {
    var url = "http://data.police.uk/api/crimes-street/all-crime?lat=52.6143247&lng=-1.6677285&date=2013-01";
    return $.getJSON(url,function( data ) {
            var dataMap = $.map(data, function (item) {
                return {
                            Category: item.category,
                            Street: item.location.street.name,
                            Lat: item.location.latitude,
                            Long: item.location.longitude
                        };
             });
    });
}


//Usage    
getStreetCrime(null).then(function(data){
   console.log(data); 
});
  • 2
    That's the correct answer they locked it down. Its changeable for on-prem (bit of a hack though). But not for O365. Also the reason to USE SPWebProxy in the first place is CORS so any other library method isn't going to work unless its JSONP. t.co/Ro3rsIxPeP - thanks to @1wisegeek for this one – BinaryJam Oct 16 '14 at 13:33

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.