Skip to main content

Go SDK

The official d3-go-client package provides a high‑level interface to the D3 Business API.

Installation

go get github.com/d3/d3-go-client

Quick start

package main

import (
    "fmt"
    "github.com/d3/d3-go-client"
)

func main() {
    // Initialize the client
    client, err := d3.NewClient(d3.Config{
        APIKey:  "your-api-key-here",
        BaseURL: "https://api.dragdropdo.com", // Optional, defaults to https://api.dragdropdo.com
        Timeout: 30 * time.Second,     // Optional, defaults to 30s
    })
    if err != nil {
        panic(err)
    }

    // Upload a file
    uploadResult, err := client.UploadFile(d3.UploadFileOptions{
        File:     "/path/to/document.pdf",
        FileName: "document.pdf",
        MimeType: "application/pdf",
    })
    if err != nil {
        panic(err)
    }

    fmt.Printf("File key: %s\n", uploadResult.FileKey)
}

Initialization

NewClient(config Config) (*Client, error)
Config:
  • APIKey (required) – your D3 API key.
  • BaseURL (optional) – API base URL, default: https://api.dragdropdo.com.
  • Timeout (optional) – request timeout, default: 30 * time.Second.
  • Headers (optional) – additional headers to send with every request.

File upload

UploadFile(options UploadFileOptions) (*UploadResponse, error)
Options:
  • File (required) – file path string.
  • FileName (required) – original file name.
  • MimeType (optional) – MIME type (auto‑detected if omitted).
  • Parts (optional) – number of upload parts (auto‑calculated).
  • OnProgress (optional) – progress callback.
Example:
result, err := client.UploadFile(d3.UploadFileOptions{
    File:     "/path/to/file.pdf",
    FileName: "document.pdf",
    MimeType: "application/pdf",
    OnProgress: func(progress d3.UploadProgress) {
        fmt.Printf("Upload: %d%%\n", progress.Percentage)
    },
})

Supported operations

CheckSupportedOperation(options SupportedOperationOptions) (*SupportedOperationResponse, error)
Options:
  • Ext (required) – file extension (e.g. pdf, jpg).
  • Action (optional) – specific action (convert, compress, …).
  • Parameters (optional) – parameters to validate (e.g. map[string]interface{}{"convert_to": "png"}).
Examples:
// Get available actions for PDF
actions, _ := client.CheckSupportedOperation(d3.SupportedOperationOptions{
    Ext: "pdf",
})
fmt.Println(actions.AvailableActions)

// Check if convert to PNG is supported
supported, _ := client.CheckSupportedOperation(d3.SupportedOperationOptions{
    Ext:    "pdf",
    Action: "convert",
    Parameters: map[string]interface{}{
        "convert_to": "png",
    },
})
fmt.Printf("Supported: %t\n", supported.Supported)

Create operations

CreateOperation(options OperationOptions) (*OperationResponse, error)
Options:
  • Action (required) – "convert" | "compress" | "merge" | "zip" | "share" | "lock" | "unlock" | "reset_password".
  • FileKeys (required) – array of file keys from upload.
  • Parameters (optional) – action‑specific parameters.
  • Notes (optional) – user metadata.
Examples:
// Convert PDF to PNG
client.CreateOperation(d3.OperationOptions{
    Action:   "convert",
    FileKeys: []string{uploadResult.FileKey},
    Parameters: map[string]interface{}{
        "convert_to": "png",
    },
    Notes: map[string]string{"userId": "user-123"},
})

// Compress
client.CreateOperation(d3.OperationOptions{
    Action:   "compress",
    FileKeys: []string{uploadResult.FileKey},
    Parameters: map[string]interface{}{
        "compression_value": "recommended",
    },
})

Convenience helpers

The client exposes shorthand helpers:
client.Convert(fileKeys, convertTo, notes)
client.Compress(fileKeys, compressionValue, notes)
client.Merge(fileKeys, notes)
client.Zip(fileKeys, notes)
client.Share(fileKeys, notes)
client.LockPdf(fileKeys, password, notes)
client.UnlockPdf(fileKeys, password, notes)
client.ResetPdfPassword(fileKeys, oldPassword, newPassword, notes)

Status & polling

GetStatus(options StatusOptions) (*StatusResponse, error)
PollStatus(options PollStatusOptions) (*StatusResponse, error)
Examples:
// Single status fetch
status, _ := client.GetStatus(d3.StatusOptions{
    MainTaskID: "task-123",
})

// Poll until completion
finalStatus, _ := client.PollStatus(d3.PollStatusOptions{
    StatusOptions: d3.StatusOptions{
        MainTaskID: "task-123",
    },
    Interval: 2 * time.Second,
    Timeout:  5 * time.Minute,
    OnUpdate: func(status d3.StatusResponse) {
        fmt.Printf("Status: %s\n", status.OperationStatus)
    },
})

Complete workflow example

package main

import (
    "fmt"
    "os"
    "time"
    "github.com/d3/d3-go-client"
)

func main() {
    client, err := d3.NewClient(d3.Config{
        APIKey:  os.Getenv("D3_API_KEY"),
        BaseURL: "https://api.dragdropdo.com",
    })
    if err != nil {
        panic(err)
    }

    // 1. Upload
    uploadResult, err := client.UploadFile(d3.UploadFileOptions{
        File:     "./document.pdf",
        FileName: "document.pdf",
    })
    if err != nil {
        panic(err)
    }

    // 2. Check support
    supported, err := client.CheckSupportedOperation(d3.SupportedOperationOptions{
        Ext:    "pdf",
        Action: "convert",
        Parameters: map[string]interface{}{
            "convert_to": "png",
        },
    })
    if err != nil {
        panic(err)
    }
    if !supported.Supported {
        panic("Convert to PNG is not supported")
    }

    // 3. Create operation
    operation, err := client.Convert(
        []string{uploadResult.FileKey},
        "png",
        map[string]string{"userId": "user-123", "source": "api"},
    )
    if err != nil {
        panic(err)
    }

    // 4. Poll
    status, err := client.PollStatus(d3.PollStatusOptions{
        StatusOptions: d3.StatusOptions{
            MainTaskID: operation.MainTaskID,
        },
        Interval: 2 * time.Second,
    })
    if err != nil {
        panic(err)
    }

    if status.OperationStatus == "completed" {
        for _, file := range status.FilesData {
            fmt.Printf("Download: %s\n", file.DownloadLink)
        }
    }
}