Skip to main content

Overview

The siat.New() function creates and initializes a new instance of the SIAT services client. This is the entry point for interacting with all SIAT API services including operations, synchronization, codes, and sales.

Function Signature

func New(baseUrl string, httpClient *http.Client) (*siatServices, error)

Parameters

baseUrl
string
required
The base URL of the SIAT service. Use the appropriate URL for your environment:
  • Testing: https://pilotosiatservicios.impuestos.gob.bo
  • Production: https://siatservicios.impuestos.gob.bo
The URL cannot be empty or whitespace-only.
httpClient
*http.Client
default:"nil"
Optional HTTP client for making requests. If nil, a default client with a 15-second timeout is used.Provide a custom client to configure:
  • Custom timeouts
  • Proxy settings
  • TLS configuration
  • Connection pooling

Return Values

*siatServices
struct
A pointer to the initialized SIAT services client with access to all service modules.
error
error
An error if initialization fails (e.g., empty base URL or service initialization error).

Available Services

The returned siatServices struct provides access to four main service modules:
Operaciones
*SiatOperacionesService
Service for managing operations like punto de venta (point of sale) and eventos significativos (significant events).See the Operaciones Service reference for details.
Sincronizacion
*SiatSincronizacionService
Service for synchronizing data from SIAT including activities, parametric tables, and product/service catalogs.See the Sincronizacion Service reference for details.
Codigos
*SiatCodigosService
Service for managing codes like CUIS (Sistema Integrado Único), CUFD (Código Único de Factura Diaria), and NIT verification.See the Codigos Service reference for details.
CompraVenta
*SiatCompraVentaService
Service for invoice operations including reception, cancellation, and building invoices.See the Compra Venta Service reference for details.

Examples

Basic Initialization

Initialize the client with default settings for the testing environment:
package main

import (
    "fmt"
    "log"
    
    "github.com/ron86i/go-siat"
)

func main() {
    // Initialize with default HTTP client
    client, err := siat.New("https://pilotosiatservicios.impuestos.gob.bo", nil)
    if err != nil {
        log.Fatalf("Failed to initialize SIAT client: %v", err)
    }
    
    // Access services
    fmt.Println("Client initialized successfully")
    fmt.Printf("Operaciones service: %v\n", client.Operaciones)
    fmt.Printf("Codigos service: %v\n", client.Codigos)
}

Custom HTTP Client

Configure a custom HTTP client with specific timeout and transport settings:
package main

import (
    "log"
    "net/http"
    "time"
    
    "github.com/ron86i/go-siat"
)

func main() {
    // Create custom HTTP client with 30-second timeout
    httpClient := &http.Client{
        Timeout: 30 * time.Second,
        Transport: &http.Transport{
            MaxIdleConns:        100,
            MaxIdleConnsPerHost: 10,
            IdleConnTimeout:     90 * time.Second,
        },
    }
    
    // Initialize with custom client
    client, err := siat.New(
        "https://pilotosiatservicios.impuestos.gob.bo",
        httpClient,
    )
    if err != nil {
        log.Fatalf("Failed to initialize SIAT client: %v", err)
    }
    
    // Use the client
    _ = client
}

Production Environment

Initialize the client for production use:
package main

import (
    "log"
    "net/http"
    "time"
    
    "github.com/ron86i/go-siat"
)

func main() {
    // Production URL
    productionURL := "https://siatservicios.impuestos.gob.bo"
    
    // Configure for production with longer timeout
    httpClient := &http.Client{
        Timeout: 60 * time.Second,
    }
    
    client, err := siat.New(productionURL, httpClient)
    if err != nil {
        log.Fatalf("Failed to initialize production client: %v", err)
    }
    
    // Ready for production use
    _ = client
}

Error Handling

Handle initialization errors properly:
package main

import (
    "fmt"
    "log"
    
    "github.com/ron86i/go-siat"
)

func initializeClient(baseURL string) (*siat.SiatServices, error) {
    client, err := siat.New(baseURL, nil)
    if err != nil {
        return nil, fmt.Errorf("client initialization failed: %w", err)
    }
    return client, nil
}

func main() {
    // This will fail - empty URL
    _, err := initializeClient("")
    if err != nil {
        log.Printf("Expected error: %v\n", err)
    }
    
    // This will succeed
    client, err := initializeClient("https://pilotosiatservicios.impuestos.gob.bo")
    if err != nil {
        log.Fatal(err)
    }
    
    fmt.Println("Client initialized:", client != nil)
}

Notes

  • The base URL is trimmed of leading/trailing whitespace before validation
  • If no HTTP client is provided, a default client with a 15-second timeout is created automatically
  • All service modules (Operaciones, Sincronizacion, Codigos, CompraVenta) are initialized during client creation
  • If any service fails to initialize, the entire client initialization fails and returns an error
  • The client is thread-safe and can be reused across goroutines

Codigos Service

Manage CUIS, CUFD, and NIT verification

Sincronizacion Service

Sync activities and parametric data

Operaciones Service

Manage punto de venta and events

Compra Venta Service

Handle invoice operations

Build docs developers (and LLMs) love