batch

package
v0.0.0-...-d789bda Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 12 Imported by: 0

README

Batch APIs

Generic object create, object update, object upsert and object archive.

Documentation Reference

Object Create Update Upsert Delete
Carts Create Carts Update Carts Upsert Carts -
Commerce Payments Create Commerce Payments Update Commerce Payments Upsert Commerce Payments Archive Commerce Payments
Communications Create Communications Update Communications Upsert Communications Archive Communications
Companies Create Companies Update Companies Upsert Companies Archive Companies
Contacts Create Contacts Update Contacts Upsert Contacts Archive Contacts
Courses Create Courses Update Courses Upsert Courses Archive Courses
Custom Objects Create Custom Objects Update Custom Objects Upsert Custom Objects Archive Custom Objects
Deal Splits - - Create/Replace Deal Splits -
Deals Create Deals Update Deals Upsert Deals Archive Deals
Discounts Create Discounts Update Discounts Upsert Discounts Archive Discounts
Fees Create Fees Update Fees Upsert Fees Archive Fees
Goal Targets Create Goal Targets Update Goal Targets Upsert Goal Targets Archive Goal Targets
Invoices Create Invoices Update Invoices Upsert Invoices Archive Invoices
Leads Create Leads Update Leads - Archive Leads
Line Items Create Line Items Update Line Items - Archive Line Items
Listings Create Listings Update Listings Upsert Listings Archive Listings
Orders Create Orders Update Orders - Archive Orders
Partner Clients - Update Partner Clients - -
Partner Services - Update Partner Services - -
Products Create Products Update Products Upsert Products Archive Products
Quotes Create Quotes Update Quotes Upsert Quotes Archive Quotes
Services Create Services Update Services Upsert Services Archive Services
Taxes Create Taxes Update Taxes Upsert Taxes Archive Taxes
Tickets Create Tickets Update Tickets Upsert Tickets Archive Tickets

Implementation not supported

Create appointments - requires path parameter objectType.

Create associations - requires path parameters fromObjectType and toObjectType.

Creating object properties depends on the objectType the properties are created within.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	Client *common.JSONHTTPClient
	// contains filtered or unexported fields
}

Adapter handles batched record operations (create/update) against HubSpot's REST API. It abstracts API endpoint construction, versioning, and JSON response processing specific to the HubSpot Batch feature.

func NewAdapter

func NewAdapter(hubspotCRMClient *common.HTTPClient, moduleInfo *providers.ModuleInfo) *Adapter

NewAdapter creates a new batch Adapter configured to work with Hubspot's APIs.

func (*Adapter) BatchWrite

func (a *Adapter) BatchWrite(ctx context.Context, params *common.BatchWriteParam) (*common.BatchWriteResult, error)

BatchWrite performs a HubSpot batch create or update request.

The request body always includes an "inputs" array of record payloads, and the response contains a "results" array aligned by index.

HubSpot may return 400 (Bad Request) or 409 (Conflict) when record-level validation fails — these are treated as soft issues (non-fatal responses) and are parsed into a structured BatchWriteResult rather than raised as errors.

AllOrNone Policy

For batch creates, the allOrNone policy is controlled via objectWriteTraceId:

  • When allOrNone is false (default), objectWriteTraceId is included to enable partial success.
  • When allOrNone is true, objectWriteTraceId is omitted, causing HubSpot to fail the entire batch if any record fails.

Reference: https://developers.hubspot.com/docs/api-reference/error-handling

For batch updates, HubSpot always allows partial success and does not support allOrNone behavior. The API returns 200 for full success or 207 Multi-Status when some records fail. This is a HubSpot API limitation.

Reference: https://developers.hubspot.com/changelog/simplifying-batch-update-response-codes-for-crm-v3-apis

type Issue

type Issue any

Issue represents a single HubSpot error entry. Its structure varies by error type, but typically includes "message" and "context" fields.

type IssueResponse

type IssueResponse struct {
	Status        string  `json:"status,omitempty"`
	Message       string  `json:"message,omitempty"`
	CorrelationId string  `json:"correlationId,omitempty"`
	Errors        []Issue `json:"errors,omitempty"`
	Category      string  `json:"category,omitempty"`
}

IssueResponse models HubSpot's structured error response for 4xx cases.

type Payload

type Payload struct {
	Items []PayloadItem `json:"inputs"`
}

Payload represents the HubSpot batch request body.

type PayloadItem

type PayloadItem struct {
	ID                 string        `json:"id,omitempty"`
	Properties         common.Record `json:"properties"`
	Associations       any           `json:"associations,omitempty"`
	ObjectWriteTraceId string        `json:"objectWriteTraceId,omitempty"` //nolint:tagliatelle
}

PayloadItem represents a single item in the API payload. Hubspot's payload is identical to what client supplies to the connector. This is an alias.

func NewPayloadItem

func NewPayloadItem(record common.Record, associations any) (*PayloadItem, error)

type Response

type Response struct {
	CompletedAt time.Time      `json:"completedAt"`
	Status      string         `json:"status"`
	StartedAt   time.Time      `json:"startedAt"`
	Results     []ResponseItem `json:"results"`
	Errors      []Issue        `json:"errors"`
}

Response models a HubSpot batch success response.

func (Response) GetItemsMap

func (r Response) GetItemsMap() map[string]*ResponseItem

type ResponseItem

type ResponseItem struct {
	ID         string    `json:"id"`
	Properties any       `json:"properties"`
	CreatedAt  time.Time `json:"createdAt"`
	UpdatedAt  time.Time `json:"updatedAt"`
	Archived   bool      `json:"archived"`
	URL        string    `json:"url"`
}

func (ResponseItem) ToWriteResult

func (i ResponseItem) ToWriteResult() (*common.WriteResult, error)

Jump to

Keyboard shortcuts

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