From SharePoint 2013's default.aspx page (https://somecompany-public.sharepoint.com/pages/default.aspx) I'm trying to call a RESTful json API which lives outside the SharePoint domain, but getting an error "Calls to WebProxy without an app context are not allowed."
Do I need to create an app to access the API which lives outside SharePoint?
Here is how I'm trying:
<script language="javascript">var responseDocument = undefined;
function onSuccess() {
var response = responseDocument.get_body();
alert('success ' + response);//this line gives the error in my question
}
function onError(err) {
alert(JSON.stringify(err));
}
$(function () {
var ctx = SP.ClientContext.get_current();
var request = new SP.WebRequestInfo();
request.set_url('https://api.somedomain.com/data/10001');
request.set_method("GET");
responseDocument = SP.WebProxy.invoke(ctx, request); // executes on sp server
ctx.executeQueryAsync(onSuccess, onError);
});
</script>