Question

Request header for the create droplette API -- How to assign it to a Project in your account

I’m attempting to create an instance with an API but getting it assigned to a specific project i cannot do. The closest I came is here: https://docs.digitalocean.com/reference/api/api-reference/#operation/databases_create_cluster:~:text=the database cluster.-,project_id,-string <uuid Basically it looks like I need a reference to the project in the Request body headers but when I look for that I’m having no such luck… I tried project:, project_id: but no luck

The only way i can see is to make the target project the default…which makes any new instance created via API be assigned to it…but then any instance i create would only be assigned to that. Kind of at a loss here

def create_do_droplette():
    droplet = digitalocean.Droplet(token=API_DIGITALO_TOKEN,
                                name='Test1',
                                region='nyc1', # New York 1
                                image='ubuntu-20-04-x64', # Ubuntu 20.04 x64
                                size_slug='s-1vcpu-1gb',  # 1GB RAM, 1 vCPU
                                tags='TestTag',
                                backups=True,
                                project_id="Test") # don't know about this here <<<<<<<<<<<<<<<
    return droplet.create()

Submit an answer


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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
March 2, 2023
Accepted Answer

Hi there,

I believe that you could create your Droplet first and then make a second API call to attach the newly created Droplet to the project.

For example:

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
  -d '{"resources": ["do:droplet:1", "do:floatingip:192.168.99.100"]}' \
  "https://api.digitalocean.com/v2/projects/4e1bfbc3-dc3e-41f2-a18f-1b4d7ba71679/resources"

For more information here is a reference to the API documentation:

https://docs.digitalocean.com/reference/api/api-reference/#operation/projects_assign_resources

The API documentation URL that you’ve shared is for database clusters rather than Droplets.

Hope that this helps!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel