Question

Is there any place I can find "detailed" API documentation of Spaces?

I tried to find the API to delete at a folder(i know it is more of a virtual folder) level. I couldn’t find it in documentation. But I managed to inspect the api requests of the Spaces dashboard and figure out folder level delete is supported and the api details. Is there any documentation available other than this


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.

Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
October 17, 2017
Accepted Answer

The API that the Spaces dashboard calls is an internal implementation detail. It’s how our Ember front end talks to our backend. Under the hood, it is still accessing the same S3-compatible API from the linked docs.

A “folder” is actually just a “key” with a zero sized “object.” Items inside the folder have the folder key as a prefix to their own key. For example, here is a listing of objects in a Space with a folder named foo containing a file named bar:

$ aws s3api --endpoint-url https://nyc3.digitaloceanspaces.com --profile do list-objects --bucket my-bucket
{
    "Contents": [
        {
            "LastModified": "2017-10-17T17:50:50.840Z", 
            "ETag": "\"d41d8cd98f00b204e9800998ecf8427e\"", 
            "StorageClass": "STANDARD", 
            "Key": "foo/", 
            "Owner": {
                "DisplayName": "681451698", 
                "ID": "681451698"
            }, 
            "Size": 0
        }, 
        {
            "LastModified": "2017-10-17T17:56:08.583Z", 
            "ETag": "\"8cf8463b34caa8ac871a52d5dd7ad1ef\"", 
            "StorageClass": "STANDARD", 
            "Key": "foo/bar", 
            "Owner": {
                "DisplayName": "681451698", 
                "ID": "681451698"
            }, 
            "Size": 2
        }
    ]
}

The API does not support recursively deleting files per se. On the backend, we list all objects with that prefix and then delete them. You can achieve this same result by including a prefix query parameter when calling the API to list the contents of a Space. Here’s a quick Python example:

import boto3

session = boto3.session.Session()
client = session.client('s3',
                        region_name='nyc3',
                        endpoint_url='https://nyc3.digitaloceanspaces.com',
                        aws_access_key_id='ACCESSKEY',
                        aws_secret_access_key='SECRETKEY')


resp = client.list_objects(Bucket='my-bucket', Prefix='foo/')
objects_to_delete = []
for obj in resp['Contents']:
     objects_to_delete.append({'Key': obj['Key']})

response = client.delete_objects(Bucket='my-bucket',
                                 Delete={
                                     'Objects': objects_to_delete
                                 })

print("Deleted: {0}".format(response['Deleted']))

Hope that helps!

Try DigitalOcean for free

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

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

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.