Report this

What is the reason for this report?

Unable to query droplets API - CORS error

Posted on August 19, 2019

I am trying to query the droplets on my account (https://api.digitalocean.com/v2/droplets) - I am using jquery with crossDomain set to true. This call used to work correctly, but is now returning a CORS error. I am able to use the same jquery code to call the account API with no issues, so I know that my credentials and headers are being set correctly…

Has the access to the droplets API changed?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

This should be fixed already as per the documentation here:

https://docs.digitalocean.com/reference/api/api-reference/#section/Introduction/Cross-Origin-Resource-Sharing

In order to make requests to the API from other domains, the API implements Cross Origin Resource Sharing (CORS) support.

CORS support is generally used to create AJAX requests outside of the domain that the request originated from. This is necessary to implement projects like control panels utilizing the API. This tells the browser that it can send requests to an outside domain.

However, it’s worth noting that making API requests directly from the client-side JavaScript can expose your API keys to users, which is a security risk. Your API keys can be used to perform any action, including creating and destroying droplets, so you generally want to keep them secret.

A better approach would be to create a server-side component (in Node.js, Python, Ruby, etc.) that makes the API requests to DigitalOcean. This server-side component would keep your API keys secret, and you would control access to the API through your server-side code.

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.