Add header to all connect API requests

How can I force window.AP.request to always add header x-atlassian-force-account-id: true to every request that I make from the plugin? I tried to override XMLHttpRequest’s send method but with no luck.

XMLHttpRequest.prototype.realSend = XMLHttpRequest.prototype.send;
var newSend = function(vData) {
    this.setRequestHeader('x-atlassian-force-account-id', true);
    this.realSend(vData);
};
XMLHttpRequest.prototype.send = newSend;

The x-atlassian-force-account-id header should only work with Jira REST APIs (not Connect APIs). Try adding gdpr:true in the api migrations field in your app descriptor to opt in to the new behavior with Atlassian Connect.

Thanks for quick response. I already did what you said. But what I am asking is, how to add this header to every call to Jira REST API that is called using Atlassian Connect (window.AP.request).

I think the header would have to be specified on each request:

AP.request({
  "url": "/somPath",
  "type": "GET",
  "headers": "{'x-atlassian-force-account-id', true}",
  "cache": false
});
1 Like

I understand, thanks @dmorrow