Skip to content

Latest commit

 

History

History
129 lines (95 loc) · 8.97 KB

README.md

File metadata and controls

129 lines (95 loc) · 8.97 KB

Advertisements

(Advertisements)

Overview

Available Operations

  • List - List Campaigns
  • Get - Get Campaign

List

List active advertisement campaigns for a benefit.

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Advertisements.List(ctx, "<value>", nil, nil, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.AdvertisementCampaignListResource != nil {
        for {
            // handle items

            res, err = res.Next()

            if err != nil {
                // handle error
            }

            if res == nil {
                break
            }
        }
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
benefitID string ✔️ N/A
page *int64 Page number, defaults to 1.
limit *int64 Size of a page, defaults to 10. Maximum is 100.
sorting []components.AdvertisementSortProperty Sorting criterion. Several criteria can be used simultaneously and will be applied in order. Add a minus sign - before the criteria name to sort by descending order.
opts []operations.Option The options for this request.

Response

*operations.AdvertisementsListResponse, error

Errors

Error Type Status Code Content Type
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*

Get

Get an advertisement campaign by ID.

Example Usage

package main

import(
	"context"
	"os"
	polargo "github.com/polarsource/polar-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := polargo.New(
        polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
    )

    res, err := s.Advertisements.Get(ctx, "<value>")
    if err != nil {
        log.Fatal(err)
    }
    if res.AdvertisementCampaign != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
id string ✔️ The advertisement campaign ID.
opts []operations.Option The options for this request.

Response

*operations.AdvertisementsGetResponse, error

Errors

Error Type Status Code Content Type
apierrors.ResourceNotFound 404 application/json
apierrors.HTTPValidationError 422 application/json
apierrors.APIError 4XX, 5XX */*