boxopensdk

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 0 Imported by: 0

README

Box Open SDK for Go

box-open-sdk (Go)

Go Reference

An open source, community-built Box API client for Go — typed models for the whole Box surface, one manager per API area behind a single Client, and a net/http runtime with retry, exponential backoff, Retry-After handling, and automatic token refresh. Standard library only; no third-party dependencies.

Not affiliated with, authorized, or endorsed by Box, Inc. "Box" is a trademark of Box, Inc. This is an independent, generated client.

Install

go get github.com/unofficialbox/box-open-go-sdk@latest

Quickstart

Authenticate, look up the current user, create a folder, upload a file, extract its fields with Box AI, tag it with metadata, and query for it — end to end:

package main

import (
	"context"
	"fmt"
	"log"
	"strings"

	"github.com/unofficialbox/box-open-go-sdk/auth"
	"github.com/unofficialbox/box-open-go-sdk/client"
	"github.com/unofficialbox/box-open-go-sdk/schemas"
)

func main() {
	ctx := context.Background()

	// Client Credentials Grant (server-to-server); developer token, OAuth, and
	// JWT are also supported — see docs/auth.md.
	c := client.NewClient(auth.ClientCredentials(auth.CCGConfig{
		ClientID:     "CLIENT_ID",
		ClientSecret: "CLIENT_SECRET",
		EnterpriseID: "ENTERPRISE_ID",
	}))

	// The current user.
	me, err := c.Users.GetMe(ctx, nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("authenticated as", me.Id)

	// Create a folder at the account root ("0").
	folder, err := c.Folders.Create(ctx, &schemas.FolderCreateRequest{
		Name:   "Invoices",
		Parent: schemas.AttributesParent{Id: "0"},
	}, nil)
	if err != nil {
		log.Fatal(err)
	}

	// Upload a file into it.
	uploaded, err := c.Uploads.UploadFile(ctx, &schemas.FileContentCreateRequest{
		Attributes: schemas.PostFileContentAttributes{
			Name:   "invoice.pdf",
			Parent: schemas.AttributesParent{Id: folder.Id},
		},
		File: strings.NewReader("<file bytes>"),
	}, nil)
	if err != nil {
		log.Fatal(err)
	}
	fileID := uploaded.Entries[0].Id

	// Extract fields from the file with Box AI.
	answer, err := c.Ai.Extract(ctx, &schemas.AiExtract{
		Prompt: "Extract the invoice number and total amount.",
		Items:  []schemas.AiItemBase{{Id: fileID, Type: schemas.AiCitationTypeFile}},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)

	// Attach that metadata to the file (an enterprise template).
	if _, err := c.FileMetadata.CreateFileMetadata(ctx, fileID,
		schemas.GetFileIdMetadataIdIdScopeEnterprise, "invoiceData",
		map[string]any{"invoiceNumber": "INV-0042", "total": 1250}); err != nil {
		log.Fatal(err)
	}

	// Query for files carrying that metadata.
	results, err := c.Search.QueryByMetadata(ctx, &schemas.MetadataQuery{
		From:             "enterprise_0.invoiceData",
		AncestorFolderId: folder.Id,
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(results)
}

Authentication

Box's four auth flows all live in the auth package — developer token, client credentials (CCG), OAuth 2.0 (with a pluggable refresh-token store), and JWT (server auth). See docs/auth.md.

Documentation

API reference on pkg.go.dev; the docs/ tree carries the per-manager reference — a call snippet for every method — and the authentication, pagination, and errors guides.

License

MIT. Generated by box-gantry.

Documentation

Overview

Package boxopensdk is the module root for the Box Open SDK for Go: an open source, community-built client for the Box API, generated from the Box OpenAPI specification.

This package is documentation only and exports nothing. The SDK lives in its subpackages:

A first call:

c := client.NewClient(auth.ClientCredentials(auth.CCGConfig{
	ClientID:     "CLIENT_ID",
	ClientSecret: "CLIENT_SECRET",
	EnterpriseID: "ENTERPRISE_ID",
}))
me, err := c.Users.GetMe(context.Background(), nil)

See the README for an end-to-end Quickstart, and docs/ for a reference page per manager with an example on every method.

Not affiliated with, authorized, or endorsed by Box, Inc. "Box" is a trademark of Box, Inc. This is an independent, generated client.

Directories

Path Synopsis
Package-level auth: the four Box auth flows, each a gantryruntime.TokenSource passed to New.
Package-level auth: the four Box auth flows, each a gantryruntime.TokenSource passed to New.
Package buildinfo records the provenance of this generated SDK (NF-7): the engine version and the fingerprint of the Box OpenAPI specs it was generated from.
Package buildinfo records the provenance of this generated SDK (NF-7): the engine version and the fingerprint of the Box OpenAPI specs it was generated from.
Code generated by box-gantry 0.1.0.
Code generated by box-gantry 0.1.0.
Package gantryruntime is the hand-written runtime the generated Box SDK ships against (TR-Go.7).
Package gantryruntime is the hand-written runtime the generated Box SDK ships against (TR-Go.7).
Code generated by box-gantry 0.1.0.
Code generated by box-gantry 0.1.0.
Code generated by box-gantry 0.1.0 (spec ee7d55aedefe2fa0) for Box API 2024.0.
Code generated by box-gantry 0.1.0 (spec ee7d55aedefe2fa0) for Box API 2024.0.
Code generated by box-gantry.
Code generated by box-gantry.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL