cURL
To add an image to a region with cURL, call:
# Transfer an Existing Image
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
-d '{"type":"transfer","region":"nyc2"}' \
"https://api.digitalocean.com/v2/images/7938269/actions"
# Convert an Image into a Snapshot
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
-d '{"type":"convert"}' \
"https://api.digitalocean.com/v2/images/7938291/actions"
Go
Go developers can use Godo,
the official DigitalOcean V2 API client for Go. To add an image to a region with Godo, use the
following code:
import (
"context"
"os"
"github.com/digitalocean/godo"
)
func main() {
token := os.Getenv("DIGITALOCEAN_TOKEN")
client := godo.NewFromToken(token)
ctx := context.TODO()
// Transfer an existing image
transferRequest := &godo.ActionRequest{
"type": "transfer",
"region": "nyc2",
}
# Transfer an Image
transfer, _, err := client.ImageActions.Transfer(ctx, 7938269, transferRequest)
# Convert an Image to a Snapshot
# client.image_actions.convert(image_id: 7938269)
}
Ruby
Ruby developers can use DropletKit,
the official DigitalOcean V2 API client for Ruby. To add an image to a region with DropletKit, use the
following code:
require 'droplet_kit'
token = ENV['DIGITALOCEAN_TOKEN']
client = DropletKit::Client.new(access_token: token)
# Transfer an Image
client.image_actions.transfer(image_id: 7938269, region: 'nyc2')
# Convert an Image to a Snapshot
# client.image_actions.convert(image_id: 7938269)
Python
import os
from pydo import Client
client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
req = {
"type": "convert"
}
resp = client.image_actions.post(image_id=342341, body=req)