Description
hspt associations list fails with a JSON unmarshal error whenever the association query returns results. Empty result sets return cleanly, making the bug deceptive — it only surfaces when there's actual data.
Steps to reproduce
hspt associations list --from-type contacts --from-id 12345 --to-type notes -o json
Expected
A JSON array of association objects.
Actual
json: cannot unmarshal number into Go struct field Association.results.toObjectId of type string
Root cause
The HubSpot CRM v4 associations API returns toObjectId as a JSON number:
{
"toObjectId": 98765,
"associationTypes": [...]
}
But the Go struct in api/associations.go declares it as string:
type Association struct {
ToObjectID string `json:"toObjectId"`
AssociationTypes []AssociationType `json:"associationTypes"`
}
encoding/json cannot unmarshal a JSON number into a Go string field, so it fails on every non-empty response.
Suggested fix
Change the field type from string to json.Number:
import "encoding/json"
type Association struct {
ToObjectID json.Number `json:"toObjectId"`
AssociationTypes []AssociationType `json:"associationTypes"`
}
json.Number accepts both JSON numbers and strings, and its .String() method returns the numeric value as a string for display. This is a one-line change with no downstream breakage.
Environment
- hubspot-cli HEAD on
main
- HubSpot CRM v4 associations API (
/crm/v4/objects/{type}/{id}/associations/{toType})
- Go 1.21+
Description
hspt associations listfails with a JSON unmarshal error whenever the association query returns results. Empty result sets return cleanly, making the bug deceptive — it only surfaces when there's actual data.Steps to reproduce
Expected
A JSON array of association objects.
Actual
Root cause
The HubSpot CRM v4 associations API returns
toObjectIdas a JSON number:{ "toObjectId": 98765, "associationTypes": [...] }But the Go struct in
api/associations.godeclares it asstring:encoding/jsoncannot unmarshal a JSON number into a Gostringfield, so it fails on every non-empty response.Suggested fix
Change the field type from
stringtojson.Number:json.Numberaccepts both JSON numbers and strings, and its.String()method returns the numeric value as a string for display. This is a one-line change with no downstream breakage.Environment
main/crm/v4/objects/{type}/{id}/associations/{toType})