Error while deleting remote links via REST API

I have a section on the view issue page which slightly reworks the “Linked Issues” display. Now the problem is I need to be able to remove the links. I have successfully been able to remove regular issue links calling DELETE on “/rest/api/2/issueLink/{linkId}”, but I am having problem deleting the other link types (web links, Confluence links, etc.).

According to the documentation, there should be an option to remove remote link by calling DELETE on “rest/api/latest/issue/{issueIdOrKey}/1/remotelink/{linkId}”. Now when I call this via the REST API browser, everything works fine - it returns a 204. But, when I try to do the same from the issue view page, it returns a 404, full response:

{
    "readyState": 4,
    "responseText": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><status><status-code>404</status-code><message>null for uri: http://localhost:2990/jira/rest/api/2/issue/PROJ01-1/remoteLink/10101</message></status>",
    "responseXML": {
        "location": null
    },
    "status": 404,
    "statusText": "Not Found"
}

The URL on which I call it is exactly the same as in the REST API browser, even the headers on the request are the same, except for the cookie and the “referer” values. Both seem logical and I don’t see why they should cause problems. I am logged on an admin account and deleting the remote link through icon in the normal “Issue Links” section works fine.

I am calling the REST API through ajax in Javascript and use it on multiple other endpoints in the same widget, which all work without a problem. I have tried setting up the “contentType” and “accept” headers to match the ones produced by the REST API browser, but it didn’t have any effect.

var url = AJS.contextPath() + "/rest/api/2/issue/" + issueKey + "/remoteLink/" + linkId;
AJS.$.ajax({
    url: url,
    type: "DELETE",
    success: function(data) {
        console.log('issuelink ' + linkId + ' successfully deleted');
        //some more code
    },
    error: function(e){
        console.log('url ' + url);
        console.log('error while deleting the issuelink: ' + JSON.stringify(e, null, 2));
    }
});

Basically the problem is that the API acts as if the remote link didn’t exist when I try to delete it from the issue view, but when I try it through the REST API browser with the same link id, it works well and I don’t have a slightest idea why.