Go for Exporting Data from Rossum API

This Go code shows how to download XML data captured in a given Rossum queue for the previous calendar day.

This Go code shows how to download XML data captured in a given queue for the previous calendar day – as part of the regular export routine. Update the parameters at the beginning based on your scenario.

The export API is more powerful - you can filter by different criteria or download the data e.g. as a JSON instead - see the full docs.

package main
import (
    "bytes"
    "encoding/json"
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
    "time"
)
type LoginResponse struct {
    Key string `json:"key"`
}
func main() {
    username := "[email protected]"
    password := "secret_password"
    queueId := "12345"
    
    authToken := authorize(username, password)
    result := export_today(queueId, authToken)
    log.Println(result)
}
func authorize(username string, password string) string {
    credentials := map[string]interface{}{
        "username": username,
        "password": password,
    }
    credentialsBytes, err := json.Marshal(credentials)
    if err != nil {
        log.Fatalln(err)
    }
    response, err := http.Post(
        "https://example.rossum.app/api/v1/auth/login",
        "application/json",
        bytes.NewBuffer(credentialsBytes))
    if err != nil {
        log.Fatalln(err)
    }
    loginResponse := LoginResponse{}
    json.NewDecoder(response.Body).Decode(&loginResponse)
    return loginResponse.Key
}
func export_today(queueId string, authToken string) string {
    today := time.Now()
    yesterday := today.AddDate(0,0,-1)
    
    dateStart := yesterday.Format("2006-01-02")
    dateEnd := today.Format("2006-01-02")
    
    return export(queueId, dateStart, dateEnd, authToken)
}
func export(queueId string, dateStart string, dateEnd string, authToken string) string {
    url := fmt.Sprintf("https://example.rossum.app/api/v1/queues/%s/export?format=xml&page_size=100&page=1&exported_at_after=%s&exported_at_before=%s",
                      queueId, dateStart, dateEnd)
    
    req, err := http.NewRequest("GET", url, nil)
    if err != nil {
        log.Fatalln(err)
    }
    req.Header.Set("Authorization", fmt.Sprintf("token %s", authToken))
    client := &http.Client{}
    response, err := client.Do(req)
    if err != nil {
        log.Fatalln(err)
    }
    body, err := ioutil.ReadAll(response.Body)
    if err != nil {
        log.Fatalln(err)
    }
    return string(body)
}

This example will export at most 100 documents. To export more documents, you need to modify the code download multiple pages one by one, until it reaches the page count (or it can simply stop when an empty set of results is finally downloaded).