Access Unity Cloud Build API through WebGL build

Hello,

I’m working on a small app that accesses Unity Cloud Build’s API to access information about our organization’s applications. This works in the Editor but when I attempt to run it as a WebGL project (either through Unity Cloud Build’s play functionality or hosted on our own servers), it is not able to access the API - I get this response:

Access to XMLHttpRequest at ‘[API URL]’ from origin ‘[MY SERVER URL]’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: The ‘Access-Control-Allow-Origin’ header has a value ‘https://build.cloud.unity3d.com’ that is not equal to the supplied origin.

Checking the response headers for the CORS preflight OPTION request in a browser, shows the “access-control-allow-origin” header with a value of “https://build.cloud.unity3d.com”. When done through Postman, I get a value of “*” (wildcard) which from what I’ve read indicates it should work from any domain.

Should it be doable to access Unity’s Cloud Build API through a WebGL build? Is there something that I’m missing that would allow this to work? Or is the issue on Unity’s server side?

Thanks!

I’ve managed to get the URL to work by passing the URL into a CORS proxy (see this StackOverflow answer) to get around the issue but I feel like this isn’t really a good solution.

1 Like