Hi!
I have a piece of javascript code embedded on a confluence page which intends to retrieve results from a third party API. Whenever I execute the javascript code with the call to the RESTfull API I get the following error message:
This Confluence page is hosted on a server owned by my company but I don't have admin access to the server. Does anyone know how I can solve this CORS issue? Below the code I'm using:
<!DOCTYPE html>
<html>
<button onclick="AccountBalance()">Get Balance</button>
<script>
'use strict'
function AccountBalance() {
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "Basic xpto");
var raw = JSON.stringify({
"testcaseId": "123456",
"database": "kpi",
"table": "Main"
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
credentials: 'include',
redirect: 'follow'
};
fetch('https://api.thirdparty.com/endpoint', requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
}
</script>
</html>
Thanks!
BR
I found this thread that may assist. Link: https://community.atlassian.com/t5/Confluence-questions/Access-to-API-Rest-blocked-by-CORS/qaq-p/1230614
If you still have issues open a support ticket with atlassian.
Regards
Hi @Fabian Lim
I think the issue described on that thread (and the recommended solution), does not apply to my problem since I don't have admin access to the confluence server.
I have access to the confluence web pages where I can edit these web pages with some built-in forms available on confluence (HTML code, SQL query, etc) but I dont see how I can "Add the header via Tomcat by adding the following to <confluence-install>/confluence/WEB-INF/web.xml:
<!-- Tomcat built in CORS implementation --> <filter> <filter-name>CorsFilter</filter-name> <filter-class>org.apache.catalina.filters.CorsFilter</filter-class> </filter> <filter-mapping> <filter-name>CorsFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- End of built in CORS implementation -->
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Want to leave your mark on Confluence? One winner will have their whiteboard design added into Confluence for all users to access! This is your chance to showcase your creativity, help others, and gain recognition in the Confluence community.
Share your template today!Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.