Documentation
¶
Overview ¶
Package info wraps SiteHost's /api/* endpoints. The endpoint exposed today is api/get_info.json (Get), which returns the authenticated client's client_id, contact_id, and the list of modules and roles their key has access to.
Bootstrap pattern ¶
api/get_info.json returns the authenticated client's client_id. Consumers who do not yet know their client_id — for example a freshly-issued super-user key being wired into a tool — can use NewClientWithDiscovery to obtain a fully-configured *api.Client from just the API key.
For sub-account targeting from a super-user key, prefer api.New(apiKey, subAccountClientID, opts...) directly: discovery resolves to the super-user's own client_id, which is not the sub-account's id and would scope subsequent calls to the wrong account.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewClientWithDiscovery ¶ added in v0.7.0
func NewClientWithDiscovery(ctx context.Context, apiKey string, opts ...api.ClientOpt) (*api.Client, error)
NewClientWithDiscovery returns a new *api.Client given just an API key, by calling api/get_info.json to discover the authenticated client's client_id.
Use this when the caller does not yet know the client_id — for example a tool bootstrapping against a freshly-issued key. Use api.New(apiKey, clientID, opts...) directly if the client_id is known, including when targeting a sub-account from a super-user key (discovery resolves to the super-user's own id, which is not the sub-account's id).
opts are forwarded to the returned client unchanged; if api.SetBaseURL is supplied it also applies to the discovery call. The placeholder "0" used internally for the bootstrap satisfies NewRequest's empty-check; api/get_info.json authenticates against the apikey alone and does not validate the client_id query parameter.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Service to work with API Jobs.
func (*Client) Get ¶
func (s *Client) Get(ctx context.Context) (response GetResponse, err error)
Get retrieves information about the current user's account using the "api/get_info.json" API endpoint. It creates a new HTTP GET request with the client's API key and sends it using the HTTP client. The function returns a GetResponse struct containing the API response data and an error if one occurred during the request.
type GetResponse ¶
type GetResponse struct {
Return struct {
ClientID string `json:"client_id"`
ContactID string `json:"contact_id"`
Modules []string `json:"modules"`
Roles []string `json:"roles"`
} `json:"return"`
Msg string `json:"msg"`
Status bool `json:"status"`
}
GetResponse represents a result of a get API Info call.