Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateClientSecret(keyID, teamID, clientID string, privateKey *ecdsa.PrivateKey, now time.Time, ...) (string, error)
- func MaxPageLimit(spec EndpointSpec) int
- func RemoveAllCredentials() error
- func RemoveCredentials(name string) error
- func SetDefaultCredentials(name string) error
- func ShouldBypassKeychain() bool
- func StoreCredentials(name string, credentials Credentials) error
- func StoreCredentialsConfig(name string, credentials Credentials) error
- func StoreCredentialsConfigAt(name string, credentials Credentials, path string) error
- func ValidateAdAccountID(value string) error
- func ValidateOrgID(value string) error
- type APIError
- type APIErrorDetail
- type APIVersion
- type BodyKind
- type Client
- func (c *Client) AccessToken(ctx context.Context) (string, error)
- func (c *Client) Do(ctx context.Context, spec EndpointSpec, pathParams map[string]string, ...) (RawResponse, error)
- func (c *Client) LastRateLimit() RateLimit
- func (c *Client) PaginateAll(ctx context.Context, spec EndpointSpec, pathParams map[string]string, ...) (RawResponse, error)
- func (c *Client) Request(ctx context.Context, method, path string, query url.Values, ...) (RawResponse, error)
- func (c *Client) RequestForVersion(ctx context.Context, version APIVersion, method, path string, query url.Values, ...) (RawResponse, error)
- func (c *Client) UploadPlatformAsset(ctx context.Context, file *os.File, fileSize int64, ...) (RawResponse, error)
- type ClientOption
- type ContextKind
- type Credentials
- type EndpointSpec
- type PageDetail
- type ParamSpec
- type ParamType
- type RateLimit
- type RawResponse
- type StoredCredential
Constants ¶
const ( // BaseURL is the Apple Ads Campaign Management API v5 base URL. BaseURL = "https://api.searchads.apple.com/api/" // PlatformBaseURL is the Apple Ads Platform API v1 base URL. PlatformBaseURL = "https://api.ads.apple.com/v1/" )
const MaxPlatformPaginationPages = 1000
MaxPlatformPaginationPages bounds how many pages any Apple Ads paginator fetches for a single logical query. Servers that keep returning full pages without a total count would otherwise loop forever.
Variables ¶
var ErrDefaultCredentialsNotFound = errors.New("default credentials not found")
ErrDefaultCredentialsNotFound reports that no default Apple Ads credential is stored in the keychain or configuration.
Functions ¶
func GenerateClientSecret ¶
func GenerateClientSecret(keyID, teamID, clientID string, privateKey *ecdsa.PrivateKey, now time.Time, lifetime time.Duration) (string, error)
GenerateClientSecret creates an Apple Ads OAuth client secret JWT.
func MaxPageLimit ¶
func MaxPageLimit(spec EndpointSpec) int
MaxPageLimit returns the endpoint-specific maximum page size.
func RemoveAllCredentials ¶
func RemoveAllCredentials() error
RemoveAllCredentials removes all Apple Ads credentials.
func RemoveCredentials ¶
RemoveCredentials removes one Apple Ads credential.
func SetDefaultCredentials ¶
SetDefaultCredentials switches the default Apple Ads profile.
func ShouldBypassKeychain ¶
func ShouldBypassKeychain() bool
ShouldBypassKeychain reports whether Apple Ads keychain usage is disabled.
func StoreCredentials ¶
func StoreCredentials(name string, credentials Credentials) error
StoreCredentials stores Apple Ads credentials in keychain when available.
func StoreCredentialsConfig ¶
func StoreCredentialsConfig(name string, credentials Credentials) error
StoreCredentialsConfig stores Apple Ads credentials in the active config file.
func StoreCredentialsConfigAt ¶
func StoreCredentialsConfigAt(name string, credentials Credentials, path string) error
StoreCredentialsConfigAt stores Apple Ads credentials in a specific config file.
func ValidateAdAccountID ¶ added in v1.260816.0
ValidateAdAccountID rejects values that cannot safely be placed in the Apple Ads ad-account context header.
func ValidateOrgID ¶ added in v1.260816.0
ValidateOrgID rejects values that cannot safely be placed in the legacy Apple Ads organization context header.
Types ¶
type APIError ¶
type APIError struct {
StatusCode int
Field string
Message string
MessageCode string
Detail string
Version APIVersion
Code string
Details []APIErrorDetail
RateLimit RateLimit
}
APIError describes an Apple Ads API error response.
func (*APIError) HTTPStatusCode ¶ added in v1.260713.0
type APIErrorDetail ¶ added in v1.260816.0
type APIErrorDetail struct {
Code string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
Info map[string]any `json:"info,omitempty"`
}
APIErrorDetail describes one Apple Ads Platform API error detail.
type APIVersion ¶ added in v1.260816.0
type APIVersion string
APIVersion identifies an Apple Ads API transport contract.
const ( APIVersionCampaignV5 APIVersion = "campaign-v5" APIVersionPlatformV1 APIVersion = "platform-v1" )
type BodyKind ¶
type BodyKind string
BodyKind describes the JSON body shape accepted by an Apple Ads endpoint.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an Apple Ads Campaign Management API client.
func NewClient ¶
func NewClient(credentials Credentials, opts ...ClientOption) (*Client, error)
NewClient constructs an Apple Ads API client.
func (*Client) AccessToken ¶
AccessToken returns a bearer token for diagnostics and auth token commands.
func (*Client) Do ¶
func (c *Client) Do(ctx context.Context, spec EndpointSpec, pathParams map[string]string, query url.Values, body json.RawMessage) (RawResponse, error)
Do executes a documented Apple Ads endpoint.
func (*Client) LastRateLimit ¶ added in v1.260816.0
LastRateLimit returns the rate-limit metadata from the most recent Platform API response.
func (*Client) PaginateAll ¶
func (c *Client) PaginateAll(ctx context.Context, spec EndpointSpec, pathParams map[string]string, query url.Values, startOffset, pageSize int, body json.RawMessage) (RawResponse, error)
PaginateAll fetches all pages for an offset-paginated endpoint.
func (*Client) Request ¶
func (c *Client) Request(ctx context.Context, method, path string, query url.Values, body json.RawMessage, requiresOrg bool) (RawResponse, error)
Request executes an Apple Ads API request for a relative v5 path.
func (*Client) RequestForVersion ¶ added in v1.260816.0
func (c *Client) RequestForVersion(ctx context.Context, version APIVersion, method, path string, query url.Values, body json.RawMessage, contextKind ContextKind) (RawResponse, error)
RequestForVersion executes an Apple Ads request against an explicit API version.
func (*Client) UploadPlatformAsset ¶ added in v1.260816.0
func (c *Client) UploadPlatformAsset(ctx context.Context, file *os.File, fileSize int64, fileName, contentType, brandID string) (RawResponse, error)
UploadPlatformAsset uploads one already-open image to the Platform API v1. The caller owns file and must keep it open until this method returns.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures a Client.
func WithBaseURL ¶
func WithBaseURL(baseURL string) ClientOption
WithBaseURL configures the Apple Ads API base URL.
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient configures the HTTP client.
func WithNow ¶
func WithNow(now func() time.Time) ClientOption
WithNow configures the clock used by token caching.
func WithPlatformBaseURL ¶ added in v1.260816.0
func WithPlatformBaseURL(baseURL string) ClientOption
WithPlatformBaseURL configures the Apple Ads Platform API v1 base URL.
func WithTokenURL ¶
func WithTokenURL(tokenURL string) ClientOption
WithTokenURL configures the OAuth token URL.
type ContextKind ¶ added in v1.260816.0
type ContextKind uint8
ContextKind identifies the X-AP-Context behavior for a request.
const ( ContextNone ContextKind = iota ContextOrg ContextAdAccount ContextAdAccountOptional )
type Credentials ¶
type Credentials struct {
ClientID string
TeamID string
KeyID string
PrivateKeyPath string
PrivateKeyPEM string
AccessToken string
OrgID string
AdAccountID string
Profile string
}
Credentials contains resolved Apple Ads authentication inputs.
func GetCredentialsWithSource ¶
func GetCredentialsWithSource(profile string) (Credentials, string, error)
GetCredentialsWithSource resolves Apple Ads credentials by profile.
type EndpointSpec ¶
type EndpointSpec struct {
Name string
Method string
Path string
Version APIVersion
Context ContextKind
CommandPath []string
BodyKind BodyKind
BodyOptional bool
// CLIRequiresBody records a client-side requirement that is stricter than
// the SDK/OpenAPI request contract. Apple accepts an empty selector body on
// some query endpoints, but the Platform API requires a selector filter for
// the keyword queries exposed by asc.
CLIRequiresBody bool
BodyType string
BodyHint string
BodyFileExample string
// BodyExample is a minimal valid request payload rendered in command help
// so callers can start from a working body instead of external schema docs.
BodyExample string
ResponseType string
RequiresOrg bool
RequiresConfirm bool
ConfirmBodyField string
// RiskConfirm separates potential spend, billing, delivery, targeting, or
// access impact acknowledgement from destructive confirmation. A body
// field/value pair can exempt a documented safe payload from the
// acknowledgement. When RiskConfirmAllowedBodyFields is set, every field
// in the safe payload object must be listed before acknowledgement can be
// skipped.
RiskConfirm bool
RiskConfirmBodyField string
RiskConfirmBodyValue string
RiskConfirmAllowedBodyFields []string
RetrySafe bool
PathParams []ParamSpec
QueryParams []ParamSpec
SupportsPaginate bool
DefaultListAlias bool
}
EndpointSpec is the single source of truth for the Apple Ads command and client surface.
func EndpointByCommandPath ¶
func EndpointByCommandPath(path ...string) (EndpointSpec, bool)
EndpointByCommandPath returns a spec by command path.
func EndpointSpecs ¶
func EndpointSpecs() []EndpointSpec
EndpointSpecs returns the current Apple Ads Campaign Management API v5 surface.
func PlatformEndpointByCommandPath ¶ added in v1.260816.0
func PlatformEndpointByCommandPath(path ...string) (EndpointSpec, bool)
PlatformEndpointByCommandPath returns a Platform API v1 spec by command path.
func PlatformEndpointSpecs ¶ added in v1.260816.0
func PlatformEndpointSpecs() []EndpointSpec
PlatformEndpointSpecs returns the implemented Apple Ads Platform API v1 resource surface.
type PageDetail ¶
type PageDetail struct {
ItemsPerPage int `json:"itemsPerPage"`
StartIndex int `json:"startIndex"`
TotalResults int `json:"totalResults"`
}
PageDetail is the Apple Ads offset pagination envelope.
type ParamSpec ¶
type ParamSpec struct {
Name string
Flag string
Aliases []string
Type ParamType
Required bool
Repeated bool
ContextValue bool
Max int
Allowed []string
Description string
Default int
}
ParamSpec describes a documented Apple Ads path or query parameter.
type ParamType ¶
type ParamType string
ParamType describes the primitive type of a path or query parameter.
type RateLimit ¶ added in v1.260816.0
type RateLimit struct {
Limit string `json:"limit,omitempty"`
Remaining string `json:"remaining,omitempty"`
Reset string `json:"reset,omitempty"`
}
RateLimit preserves the Apple Ads Platform API rate-limit response headers.
type RawResponse ¶
type RawResponse json.RawMessage
RawResponse preserves the Apple Ads response envelope.
func (RawResponse) MarshalJSON ¶
func (r RawResponse) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
type StoredCredential ¶
type StoredCredential struct {
Credentials
Name string
IsDefault bool
Source string
SourcePath string
}
StoredCredential is an Apple Ads credential with storage metadata.
func ListCredentials ¶
func ListCredentials() ([]StoredCredential, error)
ListCredentials lists Apple Ads credentials.