How to deal with rate limits for REST API calls in Confluence Cloud?

In our developer instance, we frequently run into a rate limit error:

Too many connections! The tunnel session ‘ts_1iBCo7ybm87qriNcOVxphBK3rue’ has violated the rate-limit policy of 20 connections per minute by initiating 30 connections in the last 60 seconds. Please decrease your inbound connection volume or upgrade to a paid plan for additional capacity.

20 connections per minute doesn’t seem very much, since we already need 5-6 rest API calls for each embedded macro (see the context information about the macro below). So 4 embeddings would already trigger the rate limit on page load.

Is this limit lower for developer instances of confluence cloud (http://go.atlassian.com/cloud-dev)?

And how to deal with this? Do we need to try the requests until all have finished successfully? However, this would result in a really odd user-experience where macros load awfully slow (~4 embeddings per minute?!).

Also, I’m not sure how to workaround the error page about the rate limit that is shown as soon as the rate limit is hit?

More context information about the dynamic macro

The macro embeds an SVG attachment in a Confluence Page and also provides buttons to open an editor (if the user has write access to the page) in order to edit the embedding and eventually update the attachment.

  1. REQUEST macro body (to read some macro settings, e.g. whether to display a title for the embedding).
  2. REQUEST restrictions (to identify whether the user can edit the embedded diagram or only view it as embedding and show the appropriate buttons).
    More requests are necessary to check the current user against the page restrictions
    1. GET current user id (AP.user.getCurrentUser… guess this is a REST API call that counts against the limit?)
    2. If the page has group restrictions, we need to inspect them as well
      => REQUEST group memberships of the current user and compare with the page restrictions
  3. REQUEST attachments on the confluence page and filter them for the related attachment file
  4. REQUEST the actual attachment data (i.e. download the given URL from the attachment data ‘data._links.download’)
    => This yields an SVG that is embedded as image in the dynamic macro.

This looks like an ngrok.io error, not confluence. Your use case may require upgrading to a paid ngrok plan.

3 Likes

Good Catch!

This seems to be the case, since we just tried to use a private listing for testing, where we couldn’t reproduce it yet.

ngrok is recommended in the getting started (https://developer.atlassian.com/cloud/jira/platform/getting-started/) as tunnel. Do you happen to know any other alternative that is easy to use for Confluence Cloud development?

IMO a paid ngrok plan is totally worth it, but Connect (at least ACE) used to recommend using localtunnel instead. I’m not sure why it was switched or whether localtunnel is still usable, but maybe it will do what you need.

1 Like

Thanks for your help, I’ll give it a try!

1 Like

ngrok was introduced in ACE in 2016: https://bitbucket.org/atlassian/atlassian-connect-express/pull-requests/86/replace-local-tunnel/commits

‘Reverting’ the changeset in ACE 5.x (now register-jira-conf.js) with localtunnel seems to work.

Not sure why it was replaced with ngrok to begin with. Are there security concerns due to the credentials?

1 Like