Skip to main content

Go SDK

The official TurboDocx SDK for Go applications. Build document generation and digital signature workflows with idiomatic Go patterns, context support, and comprehensive error handling. Available as github.com/TurboDocx/SDK/packages/go-sdk.

Installation

go get github.com/TurboDocx/SDK/packages/go-sdk

Requirements

  • Go 1.21+

Configuration

package main

import (
"os"

turbodocx "github.com/TurboDocx/SDK/packages/go-sdk"
)

func main() {
// Create a new client
client, err := turbodocx.NewClient(
os.Getenv("TURBODOCX_API_KEY"),
os.Getenv("TURBODOCX_ORG_ID"),
)
if err != nil {
log.Fatal(err)
}

// Or with custom configuration
client, err := turbodocx.NewClientWithConfig(turbodocx.ClientConfig{
APIKey: os.Getenv("TURBODOCX_API_KEY"),
OrgID: os.Getenv("TURBODOCX_ORG_ID"),
BaseURL: "https://api.turbodocx.com", // Optional custom base URL
})
}

Environment Variables

export TURBODOCX_API_KEY=your_api_key_here
export TURBODOCX_ORG_ID=your_org_id_here

Quick Start

Send a Document for Signature

package main

import (
"context"
"encoding/json"
"fmt"
"log"
"os"

turbodocx "github.com/TurboDocx/SDK/packages/go-sdk"
)

func main() {
client, err := turbodocx.NewClient(
os.Getenv("TURBODOCX_API_KEY"),
os.Getenv("TURBODOCX_ORG_ID"),
)
if err != nil {
log.Fatal(err)
}

ctx := context.Background()

result, err := client.TurboSign.SendSignature(ctx, &turbodocx.SendSignatureRequest{
FileLink: "https://example.com/contract.pdf",
DocumentName: "Service Agreement",
SenderName: "Acme Corp",
SenderEmail: "contracts@acme.com",
Recipients: []turbodocx.Recipient{
{Name: "Alice Smith", Email: "alice@example.com", SigningOrder: 1},
{Name: "Bob Johnson", Email: "bob@example.com", SigningOrder: 2},
},
Fields: []turbodocx.Field{
// Alice's signature
{Type: "signature", Page: 1, X: 100, Y: 650, Width: 200, Height: 50, RecipientEmail: "alice@example.com"},
{Type: "date", Page: 1, X: 320, Y: 650, Width: 100, Height: 30, RecipientEmail: "alice@example.com"},
// Bob's signature
{Type: "signature", Page: 1, X: 100, Y: 720, Width: 200, Height: 50, RecipientEmail: "bob@example.com"},
{Type: "date", Page: 1, X: 320, Y: 720, Width: 100, Height: 30, RecipientEmail: "bob@example.com"},
},
})
if err != nil {
log.Fatal(err)
}

b, _ := json.MarshalIndent(result, "", " "); fmt.Println("Result:", string(b))
}

Using Template-Based Fields

result, err := client.TurboSign.SendSignature(ctx, &turbodocx.SendSignatureRequest{
FileLink: "https://example.com/contract-with-placeholders.pdf",
Recipients: []turbodocx.Recipient{
{Name: "Alice Smith", Email: "alice@example.com", SigningOrder: 1},
},
Fields: []turbodocx.Field{
{
Type: "signature",
RecipientEmail: "alice@example.com",
Template: &turbodocx.TemplateAnchor{
Anchor: "{SIGNATURE_ALICE}",
Placement: "replace",
Size: &turbodocx.Size{Width: 200, Height: 50},
},
},
{
Type: "date",
RecipientEmail: "alice@example.com",
Template: &turbodocx.TemplateAnchor{
Anchor: "{DATE_ALICE}",
Placement: "replace",
Size: &turbodocx.Size{Width: 100, Height: 30},
},
},
},
})
Template Anchors Required

Important: The document file must contain the anchor text (e.g., {SIGNATURE_ALICE}, {DATE_ALICE}) that you reference in your fields. If the anchors don't exist in the document, the API will return an error.


File Input Methods

The SDK supports multiple ways to provide your document:

1. File Upload ([]byte)

Upload a document directly from file bytes:

pdfBytes, err := os.ReadFile("/path/to/document.pdf")
if err != nil {
log.Fatal(err)
}

result, err := client.TurboSign.SendSignature(ctx, &turbodocx.SendSignatureRequest{
File: pdfBytes,
Recipients: []turbodocx.Recipient{
{Name: "John Doe", Email: "john@example.com", SigningOrder: 1},
},
Fields: []turbodocx.Field{
{Type: "signature", Page: 1, X: 100, Y: 500, Width: 200, Height: 50, RecipientEmail: "john@example.com"},
},
})

2. File URL

Provide a publicly accessible URL to your document:

result, err := client.TurboSign.SendSignature(ctx, &turbodocx.SendSignatureRequest{
FileLink: "https://example.com/documents/contract.pdf",
Recipients: []turbodocx.Recipient{
{Name: "John Doe", Email: "john@example.com", SigningOrder: 1},
},
Fields: []turbodocx.Field{
{Type: "signature", Page: 1, X: 100, Y: 500, Width: 200, Height: 50, RecipientEmail: "john@example.com"},
},
})
When to use FileLink

Use FileLink when your documents are already hosted on cloud storage (S3, Google Cloud Storage, etc.). This is more efficient than downloading and re-uploading files.

3. TurboDocx Deliverable ID

Use a document generated by TurboDocx document generation:

result, err := client.TurboSign.SendSignature(ctx, &turbodocx.SendSignatureRequest{
DeliverableID: "deliverable-uuid-from-turbodocx",
Recipients: []turbodocx.Recipient{
{Name: "John Doe", Email: "john@example.com", SigningOrder: 1},
},
Fields: []turbodocx.Field{
{Type: "signature", Page: 1, X: 100, Y: 500, Width: 200, Height: 50, RecipientEmail: "john@example.com"},
},
})
Integration with TurboDocx

DeliverableID references documents generated using TurboDocx's document generation API. This creates a seamless workflow: generate → sign.

4. TurboDocx Template ID

Use a pre-configured TurboDocx template:

result, err := client.TurboSign.SendSignature(ctx, &turbodocx.SendSignatureRequest{
TemplateID: "template-uuid-from-turbodocx",
Recipients: []turbodocx.Recipient{
{Name: "John Doe", Email: "john@example.com", SigningOrder: 1},
},
Fields: []turbodocx.Field{
{Type: "signature", Page: 1, X: 100, Y: 500, Width: 200, Height: 50, RecipientEmail: "john@example.com"},
},
})
Integration with TurboDocx

TemplateID references pre-configured TurboSign templates created in the TurboDocx dashboard. These templates come with built-in anchors and field positioning, making it easy to reuse signature workflows across multiple documents.


API Reference

Configure

Create a new TurboDocx client.

// Simple initialization
client, err := turbodocx.NewClient(apiKey, orgID string)

// With custom configuration
client, err := turbodocx.NewClientWithConfig(turbodocx.ClientConfig{
APIKey: "your-api-key",
OrgID: "your-org-id",
BaseURL: "https://api.turbodocx.com", // Optional
})
API Credentials Required

Both APIKey and OrgID parameters are required for all API requests. To get your credentials, follow the Get Your Credentials steps from the SDKs main page.

Prepare for review

Upload a document for preview without sending emails.

result, err := client.TurboSign.CreateSignatureReviewLink(ctx, &turbodocx.CreateSignatureReviewLinkRequest{
FileLink: "https://example.com/document.pdf",
DocumentName: "Contract Draft",
Recipients: []turbodocx.Recipient{
{Name: "John Doe", Email: "john@example.com", SigningOrder: 1},
},
Fields: []turbodocx.Field{
{Type: "signature", Page: 1, X: 100, Y: 500, Width: 200, Height: 50, RecipientEmail: "john@example.com"},
},
})

b, _ := json.MarshalIndent(result, "", " "); fmt.Println("Result:", string(b))

Prepare for signing

Upload a document and immediately send signature requests.

result, err := client.TurboSign.SendSignature(ctx, &turbodocx.SendSignatureRequest{
FileLink: "https://example.com/document.pdf",
DocumentName: "Service Agreement",
SenderName: "Your Company",
SenderEmail: "sender@company.com",
Recipients: []turbodocx.Recipient{
{Name: "Recipient Name", Email: "recipient@example.com", SigningOrder: 1},
},
Fields: []turbodocx.Field{
{Type: "signature", Page: 1, X: 100, Y: 500, Width: 200, Height: 50, RecipientEmail: "recipient@example.com"},
},
})

Get status

Check the status of a document.

status, err := client.TurboSign.GetStatus(ctx, "document-uuid")
if err != nil {
log.Fatal(err)
}

b, _ := json.MarshalIndent(status, "", " "); fmt.Println("Result:", string(b))

Download document

Download the completed signed document.

pdfData, err := client.TurboSign.Download(ctx, "document-uuid")
if err != nil {
log.Fatal(err)
}

// Save to file
err = os.WriteFile("signed-contract.pdf", pdfData, 0644)
if err != nil {
log.Fatal(err)
}

Get audit trail

Retrieve the audit trail for a document.

auditTrail, err := client.TurboSign.GetAuditTrail(ctx, "document-uuid")
if err != nil {
log.Fatal(err)
}

b, _ := json.MarshalIndent(auditTrail, "", " "); fmt.Println("Result:", string(b))

Void

Cancel/void a signature request.

result, err := client.TurboSign.VoidDocument(ctx, "document-uuid", "Contract terms changed")

Resend

Resend signature request emails.

// Resend to specific recipients
result, err := client.TurboSign.ResendEmail(ctx, "document-uuid", []string{"recipient-uuid-1", "recipient-uuid-2"})

Error Handling

The SDK provides typed errors for different error scenarios:

Error Types

Error TypeStatus CodeDescription
TurboDocxErrorvariesBase error type for all API errors
AuthenticationError401Invalid or missing API key
ValidationError400Invalid request parameters
NotFoundError404Resource not found
RateLimitError429Too many requests
NetworkError-Network connectivity issues

Error Properties

PropertyTypeDescription
MessagestringHuman-readable error message
StatusCodeintHTTP status code
CodestringError code (if available)

Example

import (
"errors"

turbodocx "github.com/TurboDocx/SDK/packages/go-sdk"
)

result, err := client.TurboSign.SendSignature(ctx, request)
if err != nil {
// Check for specific error types
var authErr *turbodocx.AuthenticationError
var validationErr *turbodocx.ValidationError
var notFoundErr *turbodocx.NotFoundError
var rateLimitErr *turbodocx.RateLimitError
var networkErr *turbodocx.NetworkError

switch {
case errors.As(err, &authErr):
log.Printf("Authentication failed: %s", authErr.Message)
case errors.As(err, &validationErr):
log.Printf("Validation error: %s", validationErr.Message)
case errors.As(err, &notFoundErr):
log.Printf("Not found: %s", notFoundErr.Message)
case errors.As(err, &rateLimitErr):
log.Printf("Rate limited: %s", rateLimitErr.Message)
case errors.As(err, &networkErr):
log.Printf("Network error: %s", networkErr.Message)
default:
// Base TurboDocxError or unexpected error
var turboErr *turbodocx.TurboDocxError
if errors.As(err, &turboErr) {
log.Printf("API error [%d]: %s", turboErr.StatusCode, turboErr.Message)
} else {
log.Fatal(err)
}
}
}

Types

Signature Field Types

The Type field accepts the following string values:

TypeDescription
"signature"Signature field
"initials"Initials field
"text"Text input field
"date"Date field
"checkbox"Checkbox field
"full_name"Full name field
"first_name"First name field
"last_name"Last name field
"email"Email field
"title"Title field
"company"Company field

Recipient

PropertyTypeRequiredDescription
NamestringYesRecipient's full name
EmailstringYesRecipient's email address
SigningOrderintYesOrder in which recipient should sign (1, 2, 3...)

Field

PropertyTypeRequiredDescription
TypestringYesField type (see table above)
RecipientEmailstringYesEmail of the recipient who fills this field
PageintNo*Page number (1-indexed)
XintNo*X coordinate in pixels
YintNo*Y coordinate in pixels
WidthintNo*Field width in pixels
HeightintNo*Field height in pixels
DefaultValuestringNoPre-filled value
IsMultilineboolNoEnable multiline for text fields
IsReadonlyboolNoMake field read-only
RequiredboolNoMake field required
BackgroundColorstringNoBackground color
Template*TemplateAnchorNoTemplate anchor configuration

*Required when not using template anchors

Template Configuration

When using Template instead of coordinates:

PropertyTypeRequiredDescription
AnchorstringYesText to find in document (e.g., "{SIGNATURE}")
PlacementstringYesPosition relative to anchor: "replace", "before", "after", "above", "below"
Size*SizeYesSize with Width and Height
Offset*PointNoOffset with X and Y
CaseSensitiveboolNoCase-sensitive anchor search
UseRegexboolNoUse regex for anchor search

Request Parameters

Both CreateSignatureReviewLinkRequest and SendSignatureRequest accept:

PropertyTypeRequiredDescription
File[]byteConditionalFile content as bytes
FileLinkstringConditionalURL to document
DeliverableIDstringConditionalTurboDocx deliverable ID
TemplateIDstringConditionalTurboDocx template ID
Recipients[]RecipientYesList of recipients
Fields[]FieldYesList of fields
DocumentNamestringNoDocument display name
DocumentDescriptionstringNoDocument description
SenderNamestringNoSender's name
SenderEmailstringNoSender's email
CCEmails[]stringNoCC email addresses
File Source (Conditional)

Exactly one file source is required: File, FileLink, DeliverableID, or TemplateID.


Additional Documentation

For detailed information about advanced configuration and API concepts, see:

Core API References


Resources