### Install TTD Workflows Go SDK Source: https://context7.com/thetradedesk/ttd-workflows-go/llms.txt Command to install the TTD Workflows Go SDK using the go get command. This command fetches and installs the SDK package and its dependencies into your Go project. ```bash go get github.com/thetradedesk/ttd-workflows-go ``` -------------------------------- ### Create Campaign with Minimal Configuration using Go Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/README.md This Go example demonstrates how to create a campaign with the minimum required configuration using the ttd-workflows-go SDK. It initializes the client with server and security settings, then calls the `CreateCampaign` method with essential campaign details like name, advertiser ID, start date, and goal. Error handling and printing the created campaign ID are included. ```go package main import ( "context" "fmt" "log" "os" ttdworkflows "github.com/thetradedesk/ttd-workflows-go" "github.com/thetradedesk/ttd-workflows-go/models/components" "github.com/thetradedesk/ttd-workflows-go/types" ) func main() { ctx := context.Background() s := ttdworkflows.New( ttdworkflows.WithServer("sandbox"), ttdworkflows.WithSecurity(os.Getenv("WORKFLOWS_TTD_AUTH")), ) var seedID = "" res, err := s.Campaigns.CreateCampaign(ctx, &components.CampaignCreateWorkflowInputWithValidation{ PrimaryInput: components.CampaignCreateWorkflowPrimaryInput{ Name: "", AdvertiserID: "", SeedID: &seedID, // required, unless the advertiser has a default seed defined StartDateInUtc: types.MustNewTimeFromString("2026-07-08T10:52:56.944Z"), PrimaryChannel: components.CampaignChannelTypeDooh, PrimaryGoal: components.CampaignWorkflowROIGoalInput{ MaximizeReach: ttdworkflows.Bool(true), }, }, }) if err != nil { log.Fatal(err) } if res.CampaignPayload != nil { if idPtr := res.CampaignPayload.GetCampaign().ID; idPtr != nil { fmt.Println("Campaign ID: ", *idPtr) } else { fmt.Println("Campaign ID is nil") } } else { fmt.Println("Campaign creation failed") } } ``` -------------------------------- ### Create Ad Group Workflow Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/docs/sdks/adgroups/README.md Initiates the creation of an ad group using a workflow, with options for detailed configuration and validation. ```APIDOC ## POST /thetradedesk/ttd-workflows-go ### Description Creates a new ad group with specified workflow configurations, including targeting, frequency, and flight details. Supports validation of input before creation. ### Method POST ### Endpoint /thetradedesk/ttd-workflows-go ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * **ctx** (context.Context) - Required - The context to use for the request. * **request** (components.AdGroupCreateWorkflowInputWithValidation) - Required - The request object containing ad group configuration. * **opts** ([]operations.Option) - Optional - Options for the request. ### Request Example ```json { "IsUseClicksAsConversionsEnabled": false, "IsUseSecondaryConversionsEnabled": false, "NielsenTrackingAttributes": { "EnhancedReportingOption": "Site", "Gender": "Male", "StartAge": "TwentyFive", "EndAge": "Seventeen", "Countries": [ "", "", "" ] }, "NewFrequencyConfigs": [ { "CounterName": null, "FrequencyCap": 375286, "FrequencyGoal": 534735, "ResetIntervalInMinutes": 788122 } ], "Flights": [ { "AllocationType": "Maximum", "BudgetInAdvertiserCurrency": 4070.96, "BudgetInImpressions": 901477, "DailyTargetInAdvertiserCurrency": 5847.35, "DailyTargetInImpressions": 257517, "CampaignFlightID": 874887 } ] } ``` ### Response #### Success Response (200) * **AdGroupPayload** (components.AdGroupWorkflowResponse) - The created ad group workflow details. * **Error** (error) - If an error occurred during the process. #### Response Example ```json { "AdGroupPayload": { "Id": "123e4567-e89b-12d3-a456-426614174000", "Name": "Example Ad Group", "AdvertiserId": "advertiser-123", "CampaignId": "campaign-456", "Status": "Active", "Targeting": {}, "Pacing": {}, "Bidding": {}, "CreateDateTime": "2023-10-27T10:00:00Z", "LastUpdateDateTime": "2023-10-27T10:00:00Z" } } ``` ``` -------------------------------- ### Get Campaign Version Go Example Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/docs/sdks/campaigns/README.md Shows how to retrieve a specific version of a campaign using the TTD Workflows Go SDK. This function requires a context and the campaign ID. Optional parameters can be provided for further customization. The response includes the campaign version details or an error. ```go package main import( "context" "os" ttdworkflows "github.com/thetradedesk/ttd-workflows-go" "log" ) func main() { ctx := context.Background() s := ttdworkflows.New( ttdworkflows.WithSecurity(os.Getenv("WORKFLOWS_TTD_AUTH")), ) campaignID := "your_campaign_id_here" res, err := s.Campaigns.GetCampaignVersion(ctx, campaignID) if err != nil { log.Fatal(err) } if res.CampaignVersionWorkflow != nil { // handle response log.Printf("Retrieved campaign version: %+v\n", res.CampaignVersionWorkflow) } } ``` -------------------------------- ### Archive Campaigns Go Example Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/docs/sdks/campaigns/README.md Demonstrates how to archive one or more campaigns using the TTD Workflows Go SDK. It requires a context and an authentication token. Optional parameters for forcing archiving or providing request bodies can be included. The response indicates success or failure. ```go package main import( "context" "os" ttdworkflows "github.com/thetradedesk/ttd-workflows-go" "log" "time" ) func main() { ctx := context.Background() s := ttdworkflows.New( ttdworkflows.WithSecurity(os.Getenv("WORKFLOWS_TTD_AUTH")), ) // Example for archiving campaigns campaignIDsToArchive := []*string{ ttdworkflows.String("campaign123"), ttdworkflows.String("campaign456"), } // You can set a timeout for the request ctx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() _, err := s.Campaigns.ArchiveCampaigns(ctx, false, campaignIDsToArchive) if err != nil { log.Fatalf("Failed to archive campaigns: %v", err) } log.Println("Campaigns archived successfully") } ``` -------------------------------- ### Create Campaign with TTD Workflows Go SDK Source: https://context7.com/thetradedesk/ttd-workflows-go/llms.txt Go code to create a new advertising campaign using the TTD Workflows Go SDK. It shows how to configure essential campaign details like name, advertiser ID, start date, channel, and goal, then logs the success or failure. ```go package main import ( "context" "fmt" "log" "os" ttdworkflows "github.com/thetradedesk/ttd-workflows-go" "github.com/thetradedesk/ttd-workflows-go/models/components" "github.com/thetradedesk/ttd-workflows-go/types" ) func main() { ctx := context.Background() client := ttdworkflows.New( ttdworkflows.WithServer("sandbox"), ttdworkflows.WithSecurity(os.Getenv("WORKFLOWS_TTD_AUTH")), ) seedID := "seed-123" startDate := types.MustNewTimeFromString("2026-07-08T10:52:56.944Z") // Create campaign with minimal required configuration res, err := client.Campaigns.CreateCampaign(ctx, &components.CampaignCreateWorkflowInputWithValidation{ PrimaryInput: components.CampaignCreateWorkflowPrimaryInput{ Name: "Q3 Brand Awareness Campaign", AdvertiserID: "advertiser-456", SeedID: &seedID, StartDateInUtc: startDate, PrimaryChannel: components.CampaignChannelTypeDooh, PrimaryGoal: components.CampaignWorkflowROIGoalInput{ MaximizeReach: ttdworkflows.Bool(true), }, }, }) if err != nil { log.Fatalf("Failed to create campaign: %v", err) } if res.CampaignPayload != nil { campaign := res.CampaignPayload.GetCampaign() if campaign.ID != nil { fmt.Printf("Campaign created successfully with ID: %s\n", *campaign.ID) } } } ``` -------------------------------- ### Configure Campaign PassThroughFeeCard in Go Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/docs/sdks/campaigns/README.md Sets up pass-through fees for a campaign, including start date and fee details. It uses The Trade Desk's workflow components and data types for configuration. ```Go PassThroughFeeCard: &components.CampaignCreateWorkflowPassThroughFeeCardInput{ StartDateUtc: types.MustNewTimeFromString("2024-07-24T11:58:59.190Z"), PassThroughFees: []components.CampaignCreatePassThroughFeesInput{ components.CampaignCreatePassThroughFeesInput{ Type: components.PassThroughFeeTypeDataCostPercentage.ToPointer(), Description: ttdworkflows.Pointer("sweetly absent fortunately forenenst earnest who solidly wherever step-mother"), Amount: ttdworkflows.Pointer[float64](2888.48), }, }, } ``` -------------------------------- ### Bulk Create Ad Groups API Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/docs/sdks/adgroups/README.md Creates multiple new ad groups with required fields. ```APIDOC ## POST /standardjob/adgroup/bulk ### Description Creates multiple new ad groups with required fields. ### Method POST ### Endpoint /standardjob/adgroup/bulk ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **Input** ([]components.AdGroupCreateWorkflowInput) - Required - N/A - **ValidateInputOnly** (bool*) - Optional - N/A - **CallbackInput** (components.WorkflowCallbackInput*) - Optional - N/A ### Request Example ```go package main import( "context" "os" ttdworkflows "github.com/thetradedesk/ttd-workflows-go" "github.com/thetradedesk/ttd-workflows-go/models/components" "log" ) func main() { ctx := context.Background() s := ttdworkflows.New( ttdworkflows.WithSecurity(os.Getenv("WORKFLOWS_TTD_AUTH")), ) res, err := s.AdGroups.BulkCreate(ctx, &components.AdGroupBulkCreateWorkflowInputWithValidation{ Input: []components.AdGroupCreateWorkflowInput{}, ValidateInputOnly: ttdworkflows.Pointer(false), CallbackInput: &components.WorkflowCallbackInput{ CallbackURL: "https://fantastic-daughter.biz/", CallbackHeaders: map[string]string{ "key": "", "key1": "", "key2": "", }, }, }) if err != nil { log.Fatal(err) } if res.StandardJobSubmitResponse != nil { // handle response } } ``` ### Response #### Success Response (200) - **StandardJobSubmitResponse** #### Response Example N/A ``` -------------------------------- ### Create Ad Groups Job API Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/docs/sdks/adgroups/README.md This endpoint initiates a bulk job for creating ad groups. It accepts a context, a request object containing the ad group data, and optional request options. ```APIDOC ## POST /thetradedesk/ttd-workflows-go/createadgroupsjob ### Description Initiates a bulk job for creating ad groups. It accepts a context, a request object containing the ad group data, and optional request options. ### Method POST ### Endpoint /thetradedesk/ttd-workflows-go/createadgroupsjob ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **ctx** (context.Context) - Required - The context to use for the request. - **request** (components.AdGroupBulkCreateWorkflowInputWithValidation) - Required - The request object to use for the request. - **opts** ([]operations.Option) - Optional - The options for this request. ### Request Example ```json { "ctx": "example_context", "request": { "example": "ad_group_data" }, "opts": [ { "example": "option1" } ] } ``` ### Response #### Success Response (200) - **operations.CreateAdGroupsJobResponse** (operations.CreateAdGroupsJobResponse) - The response object containing details of the created job. #### Response Example ```json { "example": "job_creation_response" } ``` ### Errors - **apierrors.ProblemDetailsError** - Status Code: 400, 403 - Content Type: application/json - **apierrors.APIError** - Status Code: 4XX, 5XX - Content Type: */* ``` -------------------------------- ### Bulk Create Ad Groups using Go Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/docs/sdks/adgroups/README.md Creates multiple new ad groups with required fields. This function accepts a context and an AdGroupBulkCreateWorkflowInputWithValidation object, which includes the ad group details, validation options, and callback information. It returns a StandardJobSubmitResponse or an error. ```go package main import( "context" "os" ttdworkflows "github.com/thetradedesk/ttd-workflows-go" "github.com/thetradedesk/ttd-workflows-go/models/components" "log" ) func main() { ctx := context.Background() s := ttdworkflows.New( ttdworkflows.WithSecurity(os.Getenv("WORKFLOWS_TTD_AUTH")), ) res, err := s.AdGroups.BulkCreate(ctx, &components.AdGroupBulkCreateWorkflowInputWithValidation{ Input: []components.AdGroupCreateWorkflowInput{}, ValidateInputOnly: ttdworkflows.Pointer(false), CallbackInput: &components.WorkflowCallbackInput{ CallbackURL: "https://fantastic-daughter.biz/", CallbackHeaders: map[string]string{ "key": "", "key1": "", "key2": "", }, }, }) if err != nil { log.Fatal(err) } if res.StandardJobSubmitResponse != nil { // handle response } } ``` -------------------------------- ### Create Ad Group with Go using ttd-workflows-go Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/docs/sdks/adgroups/README.md This Go code snippet demonstrates how to create an ad group using the ttd-workflows-go SDK. It requires authentication credentials to be set via the WORKFLOWS_TTD_AUTH environment variable. The function takes a context and a detailed AdGroupCreateWorkflowInputWithValidation object as input, and returns the created ad group or an error. ```go package main import( "context" "os" ttdworkflows "github.com/thetradedesk/ttd-workflows-go" "github.com/thetradedesk/ttd-workflows-go/models/components" "log" ) func main() { ctx := context.Background() s := ttdworkflows.New( ttdworkflows.WithSecurity(os.Getenv("WORKFLOWS_TTD_AUTH")), ) res, err := s.AdGroups.Create(ctx, &components.AdGroupCreateWorkflowInputWithValidation{ PrimaryInput: components.AdGroupCreateWorkflowPrimaryInput{ IsEnabled: ttdworkflows.Pointer(false), Description: ttdworkflows.Pointer("twine from gosh poor safely editor astride vice lost and"), Budget: &components.AdGroupWorkflowBudgetInput{ AllocationType: components.AllocationTypeMaximum.ToPointer(), BudgetInAdvertiserCurrency: ttdworkflows.Pointer[float64](3786.02), BudgetInImpressions: ttdworkflows.Pointer[int64](783190), DailyTargetInAdvertiserCurrency: ttdworkflows.Pointer[float64](9747.02), DailyTargetInImpressions: ttdworkflows.Pointer[int64](985999), }, BaseBidCPMInAdvertiserCurrency: ttdworkflows.Pointer[float64](3785.04), MaxBidCPMInAdvertiserCurrency: ttdworkflows.Pointer[float64](7447.3), AudienceTargeting: &components.AdGroupWorkflowAudienceTargetingInput{ AudienceID: ttdworkflows.Pointer(""), AudienceAcceleratorExclusionsEnabled: ttdworkflows.Pointer(true), AudienceBoosterEnabled: ttdworkflows.Pointer(true), AudienceExcluderEnabled: ttdworkflows.Pointer(true), AudiencePredictorEnabled: ttdworkflows.Pointer(false), CrossDeviceVendorListForAudience: []int{ 107263, }, RecencyExclusionWindowInMinutes: ttdworkflows.Pointer[int](90062), TargetTrackableUsersEnabled: ttdworkflows.Pointer(true), UseMcIDAsPrimary: ttdworkflows.Pointer(true), }, RoiGoal: &components.AdGroupWorkflowROIGoalInput{ MaximizeReach: ttdworkflows.Pointer(true), MaximizeLtvIncrementalReach: ttdworkflows.Pointer(false), CpcInAdvertiserCurrency: ttdworkflows.Pointer[float64](2280.31), CtrInPercent: nil, NielsenOTPInPercent: ttdworkflows.Pointer[float64](5175.21), CpaInAdvertiserCurrency: ttdworkflows.Pointer[float64](2544.37), ReturnOnAdSpendPercent: ttdworkflows.Pointer[float64](8201.47), VcrInPercent: ttdworkflows.Pointer[float64](4846.08), ViewabilityInPercent: nil, VcpmInAdvertiserCurrency: ttdworkflows.Pointer[float64](4649.53), CpcvInAdvertiserCurrency: ttdworkflows.Pointer[float64](313.95), MiaozhenOTPInPercent: ttdworkflows.Pointer[float64](4704.1), }, CreativeIds: nil, AssociatedBidLists: []components.AdGroupWorkflowAssociateBidListInput{ components.AdGroupWorkflowAssociateBidListInput{ BidListID: "", IsEnabled: ttdworkflows.Pointer(false), IsDefaultForDimension: ttdworkflows.Pointer(true), }, }, Name: ttdworkflows.Pointer(""), Channel: components.AdGroupChannelDisplay, FunnelLocation: components.AdGroupFunnelLocationConsideration, ProgrammaticGuaranteedPrivateContractID: ttdworkflows.Pointer(""), }, CampaignID: ttdworkflows.Pointer(""), AdvancedInput: &components.AdGroupWorkflowAdvancedInput{ KoaOptimizationSettings: &components.AdGroupWorkflowKoaOptimizationSettingsInput{ AreFutureKoaFeaturesEnabled: ttdworkflows.Pointer(false), PredictiveClearingEnabled: ttdworkflows.Pointer(false), }, ComscoreSettings: &components.AdGroupWorkflowComscoreSettingsInput{ IsEnabled: false, PopulationID: nil, DemographicMemberIds: []int{ 959580, 236376, }, MobileDemographicMemberIds: []int{ 664689, 827980, 21321, }, }, ContractTargeting: &components.AdGroupWorkflowContractTargetingInput{ AllowOpenMarketBiddingWhenTargetingContracts: ttdworkflows.Pointer(true), }, DimensionalBiddingAutoOptimizationSettings: [][]components.DimensionalBiddingDimensions{ []components.DimensionalBiddingDimensions{}, []components.DimensionalBiddingDimensions{}, }, }, }) if err != nil { log.Fatalf("Error creating ad group: %v", err) } log.Printf("Ad group created successfully: %+v\n", res) } ``` -------------------------------- ### Submit Workflow with Callback URL in Go Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/docs/sdks/adgroups/README.md This Go code snippet shows how to submit a workflow using The Trade Desk API, including specifying a callback URL for asynchronous processing. It demonstrates the structure of the input required for the 'Submit' function and how to handle potential errors and responses. The code uses the 'ttdworkflows' package. ```go func main() { // ... existing code ... res, err := workflowClient.Submit(ctx, &components.WorkflowSubmitInput{ WorkflowInput: &components.WorkflowInput{ // AdGroupInput or other workflow specific inputs would go here // For example: AdGroup: &components.AdGroupInput{ Name: ttdworkflows.Pointer("Example Ad Group"), // ... other ad group configurations ... }, }, ValidateInputOnly: ttdworkflows.Pointer(true), CallbackInput: &components.WorkflowCallbackInput{ CallbackURL: "https://winged-bathhouse.net", CallbackHeaders: nil, }, }) if err != nil { log.Fatal(err) } if res.StandardJobSubmitResponse != nil { // handle response } } ``` -------------------------------- ### Create Campaign with Go SDK Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/docs/sdks/campaigns/README.md Demonstrates how to create a new campaign using the ttd-workflows-go SDK. This snippet requires authentication via an environment variable and configures various campaign settings including budget, goals, and conversion reporting. It utilizes the `ttd-workflows` package and associated model components. ```go package main import( "context" "os" ttdworkflows "github.com/thetradedesk/ttd-workflows-go" "github.com/thetradedesk/ttd-workflows-go/models/components" "github.com/thetradedesk/ttd-workflows-go/types" "log" ) func main() { ctx := context.Background() s := ttdworkflows.New( ttdworkflows.WithSecurity(os.Getenv("WORKFLOWS_TTD_AUTH")), ) res, err := s.Campaigns.CreateCampaign(ctx, &components.CampaignCreateWorkflowInputWithValidation{ PrimaryInput: components.CampaignCreateWorkflowPrimaryInput{ Description: ttdworkflows.Pointer("woot furthermore mentor"), CampaignGroupID: ttdworkflows.Pointer[int64](86586), TimeZone: ttdworkflows.Pointer("Europe/Ulyanovsk"), CustomCPAClickWeight: ttdworkflows.Pointer[float64](2561.01), CustomCPAViewthroughWeight: ttdworkflows.Pointer[float64](5604.35), CustomCPAType: components.CustomCPATypeClickViewthroughWeighting.ToPointer(), CustomRoasType: components.CustomROASTypeDisabled.ToPointer(), ImpressionsOnlyBudgetingCpm: ttdworkflows.Pointer[float64](1502.33), Budget: &components.CampaignWorkflowBudgetInput{ PacingMode: components.CampaignPacingModePaceAsSoonAsPossible, BudgetInAdvertiserCurrency: 6363.35, BudgetInImpressions: ttdworkflows.Pointer[int64](836518), DailyTargetInAdvertiserCurrency: ttdworkflows.Pointer[float64](7814.79), DailyTargetInImpressions: ttdworkflows.Pointer[int64](784985), }, EndDateInUtc: nil, SeedID: nil, CampaignConversionReportingColumns: []components.CampaignWorkflowCampaignConversionReportingColumnInput{ components.CampaignWorkflowCampaignConversionReportingColumnInput{ TrackingTagID: "", IncludeInCustomCPA: false, ReportingColumnID: 888649, ROASConfig: &components.CustomROASConfig{ IncludeInCustomROAS: false, CustomROASWeight: ttdworkflows.Pointer[float64](4766.9), CustomROASClickWeight: ttdworkflows.Pointer[float64](3310.24), CustomROASViewthroughWeight: ttdworkflows.Pointer[float64](2919.37), }, Weight: ttdworkflows.Pointer[float64](5369.43), CrossDeviceAttributionModelID: ttdworkflows.Pointer(""), }, }, IsManagedByTTD: nil, SecondaryGoal: &components.CampaignWorkflowROIGoalInput{ MaximizeReach: ttdworkflows.Pointer(false), MaximizeLtvIncrementalReach: ttdworkflows.Pointer(false), CpcInAdvertiserCurrency: ttdworkflows.Pointer[float64](4128.35), CtrInPercent: ttdworkflows.Pointer[float64](4434.91), NielsenOTPInPercent: ttdworkflows.Pointer[float64](7433.37), CpaInAdvertiserCurrency: nil, ReturnOnAdSpendPercent: ttdworkflows.Pointer[float64](2367.04), VcrInPercent: ttdworkflows.Pointer[float64](2333.15), ViewabilityInPercent: ttdworkflows.Pointer[float64](5018.08), VcpmInAdvertiserCurrency: ttdworkflows.Pointer[float64](6070.6), CpcvInAdvertiserCurrency: nil, MiaozhenOTPInPercent: ttdworkflows.Pointer[float64](4324.01), IqviaAudienceQualityIndex: ttdworkflows.Pointer(true), CrossixAudienceQualityIndex: ttdworkflows.Pointer(true), IqviaAudienceQualityIndexAndCostPerTarget: ttdworkflows.Pointer(false), CrossixCostPerTarget: ttdworkflows.Pointer(true), }, TertiaryGoal: &components.CampaignWorkflowROIGoalInput{ MaximizeReach: ttdworkflows.Pointer(false), MaximizeLtvIncrementalReach: ttdworkflows.Pointer(false), CpcInAdvertiserCurrency: ttdworkflows.Pointer[float64](7814.79), CtrInPercent: ttdworkflows.Pointer[float64](7849.85), NielsenOTPInPercent: nil, CpaInAdvertiserCurrency: nil, ReturnOnAdSpendPercent: ttdworkflows.Pointer[float64](9519.81), VcrInPercent: ttdworkflows.Pointer[float64](6125.66), ViewabilityInPercent: ttdworkflows.Pointer[float64](4766.9), VcpmInAdvertiserCurrency: ttdworkflows.Pointer[float64](3310.24), CpcvInAdvertiserCurrency: ttdworkflows.Pointer[float64](2919.37), MiaozhenOTPInPercent: ttdworkflows.Pointer[float64](5369.43), IqviaAudienceQualityIndex: ttdworkflows.Pointer(false), CrossixAudienceQualityIndex: ttdworkflows.Pointer(false), }, }, }) if err != nil { log.Fatalf("Error creating campaign: %v", err) } log.Printf("Campaign created successfully: %+v\n", res) } ``` -------------------------------- ### Initialize TTD Workflows Go SDK Client Source: https://context7.com/thetradedesk/ttd-workflows-go/llms.txt Go code to initialize the TTD Workflows Go SDK client. It demonstrates setting the server environment (sandbox or production) and authentication using an API key from environment variables. ```go package main import ( "context" "os" ttdworkflows "github.com/thetradedesk/ttd-workflows-go" ) func main() { ctx := context.Background() // Initialize client with sandbox environment and API key authentication client := ttdworkflows.New( ttdworkflows.WithServer("sandbox"), // or "prod" for production ttdworkflows.WithSecurity(os.Getenv("WORKFLOWS_TTD_AUTH")), ) // Client is now ready for operations } ``` -------------------------------- ### Get Campaign Version API Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/docs/sdks/campaigns/README.md Retrieves a specific version of a campaign. This operation requires the campaign ID and a context. ```APIDOC ## GET /campaign/{id}/version ### Description Get a campaign's version. ### Method GET ### Endpoint /campaign/{id}/version ### Parameters #### Path Parameters * **id** (string) - Required - The ID of the campaign. #### Query Parameters N/A #### Request Body * **opts** ([]operations.Option) - Optional - Request options. ### Request Example ```json { "opts": [] } ``` ### Response #### Success Response (200) * **operations.GetCampaignVersionResponse** - The response object containing the campaign version details. #### Response Example ```json { "campaignVersion": { "id": "v1", "campaignId": "campaign_123" } } ``` ### Errors * **apierrors.ProblemDetailsError** - Status Code: 400, 401, 403, 404 - Content Type: application/json * **apierrors.APIError** - Status Code: 4XX, 5XX - Content Type: */* ``` -------------------------------- ### Archive Ad Groups API Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/docs/sdks/adgroups/README.md Archives ad groups. Once archived, ad groups cannot be un-archived. ```APIDOC ## POST /adgroup/archive ### Description Archives ad groups. Once archived, ad groups cannot be un-archived. ### Method POST ### Endpoint /adgroup/archive ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **forceArchive** (bool*) - Optional - N/A - **requestBody** ([]*string*) - Optional - N/A ### Request Example ```go package main import( "context" "os" ttdworkflows "github.com/thetradedesk/ttd-workflows-go" "log" ) func main() { ctx := context.Background() s := ttdworkflows.New( ttdworkflows.WithSecurity(os.Getenv("WORKFLOWS_TTD_AUTH")), ) res, err := s.AdGroups.Archive(ctx, ttdworkflows.Pointer(false), []string{ "", "", }) if err != nil { log.Fatal(err) } if res.Strings != nil { // handle response } } ``` ### Response #### Success Response (200) - **[*operations.ArchiveAdGroupsResponse](../../models/operations/archiveadgroupsresponse.md)** #### Response Example N/A ``` -------------------------------- ### Create Ad Group with ttd-workflows-go Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/README.md This snippet shows the initialization of the ttd-workflows-go client and the creation of an ad group. It covers setting various parameters like budget, targeting, ROI goals, and advanced options. Ensure you have the WORKFLOWS_TTD_AUTH environment variable set for authentication. ```go package main import ( "context" "errors" ttdworkflows "github.com/thetradedesk/ttd-workflows-go" "github.com/thetradedesk/ttd-workflows-go/models/apierrors" "github.com/thetradedesk/ttd-workflows-go/models/components" "log" "os" ) func main() { ctx := context.Background() s := ttdworkflows.New( ttdworkflows.WithSecurity(os.Getenv("WORKFLOWS_TTD_AUTH")), ) res, err := s.AdGroups.Create(ctx, &components.AdGroupCreateWorkflowInputWithValidation{ PrimaryInput: components.AdGroupCreateWorkflowPrimaryInput{ IsEnabled: ttdworkflows.Pointer(false), Description: ttdworkflows.Pointer("twine from gosh poor safely editor astride vice lost and"), Budget: &components.AdGroupWorkflowBudgetInput{ AllocationType: components.AllocationTypeMaximum.ToPointer(), BudgetInAdvertiserCurrency: ttdworkflows.Pointer[float64](3786.02), BudgetInImpressions: ttdworkflows.Pointer[int64](783190), DailyTargetInAdvertiserCurrency: ttdworkflows.Pointer[float64](9747.02), DailyTargetInImpressions: ttdworkflows.Pointer[int64](985999), }, BaseBidCPMInAdvertiserCurrency: ttdworkflows.Pointer[float64](3785.04), MaxBidCPMInAdvertiserCurrency: ttdworkflows.Pointer[float64](7447.3), AudienceTargeting: &components.AdGroupWorkflowAudienceTargetingInput{ AudienceID: ttdworkflows.Pointer(""), AudienceAcceleratorExclusionsEnabled: ttdworkflows.Pointer(true), AudienceBoosterEnabled: ttdworkflows.Pointer(true), AudienceExcluderEnabled: ttdworkflows.Pointer(true), AudiencePredictorEnabled: ttdworkflows.Pointer(false), CrossDeviceVendorListForAudience: []int{ 107263, }, RecencyExclusionWindowInMinutes: ttdworkflows.Pointer[int](90062), TargetTrackableUsersEnabled: ttdworkflows.Pointer(true), UseMcIDAsPrimary: ttdworkflows.Pointer(true), }, RoiGoal: &components.AdGroupWorkflowROIGoalInput{ MaximizeReach: ttdworkflows.Pointer(true), MaximizeLtvIncrementalReach: ttdworkflows.Pointer(false), CpcInAdvertiserCurrency: ttdworkflows.Pointer[float64](2280.31), CtrInPercent: nil, NielsenOTPInPercent: ttdworkflows.Pointer[float64](5175.21), CpaInAdvertiserCurrency: ttdworkflows.Pointer[float64](2544.37), ReturnOnAdSpendPercent: ttdworkflows.Pointer[float64](8201.47), VcrInPercent: ttdworkflows.Pointer[float64](4846.08), ViewabilityInPercent: nil, VcpmInAdvertiserCurrency: ttdworkflows.Pointer[float64](4649.53), CpcvInAdvertiserCurrency: ttdworkflows.Pointer[float64](313.95), MiaozhenOTPInPercent: ttdworkflows.Pointer[float64](4704.1), }, CreativeIds: nil, AssociatedBidLists: []components.AdGroupWorkflowAssociateBidListInput{ components.AdGroupWorkflowAssociateBidListInput{ BidListID: "", IsEnabled: ttdworkflows.Pointer(false), IsDefaultForDimension: ttdworkflows.Pointer(true), }, }, Name: ttdworkflows.Pointer(""), Channel: components.AdGroupChannelDisplay, FunnelLocation: components.AdGroupFunnelLocationConsideration, ProgrammaticGuaranteedPrivateContractID: ttdworkflows.Pointer(""), }, CampaignID: ttdworkflows.Pointer(""), AdvancedInput: &components.AdGroupWorkflowAdvancedInput{ KoaOptimizationSettings: &components.AdGroupWorkflowKoaOptimizationSettingsInput{ AreFutureKoaFeaturesEnabled: ttdworkflows.Pointer(false), PredictiveClearingEnabled: ttdworkflows.Pointer(false), }, ComscoreSettings: &components.AdGroupWorkflowComscoreSettingsInput{ IsEnabled: false, PopulationID: nil, DemographicMemberIds: []int{ 959580, 236376, }, MobileDemographicMemberIds: []int{ 664689, 827980, 21321, }, }, ContractTargeting: &components.AdGroupWorkflowContractTargetingInput{ AllowOpenMarketBiddingWhenTargetingContracts: ttdworkflows.Pointer(true), }, DimensionalBiddingAutoOptimizationSettings: [][]components.DimensionalBiddingDimensions{ []components.DimensionalBiddingDimensions{}, []components.DimensionalBiddingDimensions{}, }, IsUseClicksAsConversionsEnabled: ttdworkflows.Pointer(false), IsUseSecondaryConversionsEnabled: ttdworkflows.Pointer(false), NielsenTrackingAttributes: &components.AdGroupWorkflowNielsenTrackingAttributesInput{ EnhancedReportingOption: components.EnhancedNielsenReportingOptionsInputSite.ToPointer(), Gender: components.TargetingGenderInputMale, StartAge: components.TargetingStartAgeInputTwentyFive, EndAge: components.TargetingEndAgeInputSeventeen, Countries: []string{ "", "", }, }, }, }) if err != nil { log.Fatalf("Failed to create ad group: %v", err) } log.Printf("Ad group created successfully: %+v\n", res) } ``` -------------------------------- ### Create Campaign Workflow in Go Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/docs/sdks/campaigns/README.md This snippet demonstrates how to create a campaign workflow using The Trade Desk's Go SDK. It includes setting up campaign details, targeting, budget, and callback configurations. The code initializes the necessary components and makes an API call, with error handling for the request. ```go func createCampaignWorkflow(client *ttdworkflows.Client) { res, err := client.CampaignsApi.CreateWorkflow(&components.CampaignCreateWorkflowRequest{ CampaignPayload: &components.CampaignCreateWorkflowPayload{ Name: ttdworkflows.Pointer(""), AdvertiserId: "", CampaignGoal: &components.CampaignWorkflowROIGoalInput{ MaximizeReach: ttdworkflows.Pointer(true), MaximizeLtvIncrementalReach: ttdworkflows.Pointer(false), CpcInAdvertiserCurrency: ttdworkflows.Pointer[float64](3354.68), CtrInPercent: ttdworkflows.Pointer[float64](7716.49), NielsenOTPInPercent: nil, CpaInAdvertiserCurrency: ttdworkflows.Pointer[float64](381.7), ReturnOnAdSpendPercent: ttdworkflows.Pointer[float64](8461.44), VcrInPercent: ttdworkflows.Pointer[float64](4170.61), ViewabilityInPercent: ttdworkflows.Pointer[float64](5364.85), VcpmInAdvertiserCurrency: ttdworkflows.Pointer[float64](1107.08), CpcvInAdvertiserCurrency: nil, MiaozhenOTPInPercent: ttdworkflows.Pointer[float64](4584.96), IqviaAudienceQualityIndex: ttdworkflows.Pointer(true), CrossixAudienceQualityIndex: ttdworkflows.Pointer(false), IqviaAudienceQualityIndexAndCostPerTarget: ttdworkflows.Pointer(true), CrossixCostPerTarget: ttdworkflows.Pointer(true), }, StartDateInUtc: types.MustNewTimeFromString("2023-01-13T23:06:05.083Z"), }, AdvancedInput: &components.CampaignUpdateWorkflowAdvancedInput{ Flights: []components.CampaignWorkflowFlightInput{ components.CampaignWorkflowFlightInput{ StartDateInclusiveUTC: types.MustTimeFromString("2023-08-14T13:47:31.198Z"), EndDateExclusiveUTC: types.MustNewTimeFromString("2024-07-07T14:46:57.378Z"), BudgetInAdvertiserCurrency: 1874.95, BudgetInImpressions: ttdworkflows.Pointer[int64](207094), DailyTargetInAdvertiserCurrency: ttdworkflows.Pointer[float64](7255.71), DailyTargetInImpressions: ttdworkflows.Pointer[int64](760981), }, }, PurchaseOrderNumber: ttdworkflows.Pointer(""), }, ValidateInputOnly: ttdworkflows.Pointer(true), CallbackInput: &components.WorkflowCallbackInput{ CallbackURL: "https://soggy-apparatus.org/", CallbackHeaders: map[string]string{ "key": "", "key1": "", "key2": "", }, }, }) if err != nil { log.Fatal(err) } if res.CampaignPayload != nil { // handle response } } ``` -------------------------------- ### Bulk Create Campaigns with TTD Workflows Go SDK Source: https://context7.com/thetradedesk/ttd-workflows-go/llms.txt Demonstrates how to create multiple campaigns simultaneously using the TTD Workflows Go SDK. This function takes a slice of campaign configurations and submits them as a single bulk job. It requires authentication credentials and specifies campaign details like name, advertiser ID, start date, channel, and goal. ```go package main import ( "context" "fmt" "log" "os" ttdworkflows "github.com/thetradedesk/ttd-workflows-go" "github.com/thetradedesk/ttd-workflows-go/models/components" "github.com/thetradedesk/ttd-workflows-go/types" ) func main() { ctx := context.Background() client := ttdworkflows.New( ttdworkflows.WithServer("sandbox"), ttdworkflows.WithSecurity(os.Getenv("WORKFLOWS_TTD_AUTH")), ) seedID := "seed-123" advertiserID := "advertiser-456" startDate := types.MustNewTimeFromString("2026-07-08T10:52:56.944Z") // Create multiple campaigns in a single job campaigns := []components.CampaignCreateWorkflowInput{ { Name: "Q3 Display Campaign", AdvertiserID: advertiserID, SeedID: &seedID, StartDateInUtc: startDate, PrimaryChannel: components.CampaignChannelTypeDisplay, PrimaryGoal: components.CampaignWorkflowROIGoalInput{ CtrInPercent: ttdworkflows.Pointer[float64](2.0), }, }, { Name: "Q3 Video Campaign", AdvertiserID: advertiserID, SeedID: &seedID, StartDateInUtc: startDate, PrimaryChannel: components.CampaignChannelTypeVideo, PrimaryGoal: components.CampaignWorkflowROIGoalInput{ VcrInPercent: ttdworkflows.Pointer[float64](75.0), }, }, } res, err := client.Campaigns.BulkCreate(ctx, &components.CampaignBulkCreateWorkflowInputWithValidation{ Input: campaigns, }) if err != nil { log.Fatalf("Failed to create bulk campaigns: %v", err) } if res.StandardJobSubmitResponse != nil { jobID := res.StandardJobSubmitResponse.GetID() fmt.Printf("Bulk campaign creation job submitted with ID: %d\n", jobID) } } ``` -------------------------------- ### Bulk Update Ad Groups API Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/docs/sdks/adgroups/README.md Updates existing ad groups. Only the fields provided in the request payload for each specific ad group will be updated. ```APIDOC ## POST /thetradedesk/ttd-workflows-go/bulkupdate ### Description Updates existing ad groups. Only the fields provided in the request payload for each specific ad group will be updated. ### Method POST ### Endpoint /thetradedesk/ttd-workflows-go/bulkupdate ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **ctx** (context.Context) - Required - The context to use for the request. - **request** (components.AdGroupBulkUpdateWorkflowInputWithValidation) - Required - The request object containing ad group data to update. - **opts** ([]operations.Option) - Optional - The options for this request. ### Request Example ```json { "ctx": "example_context", "request": { "example": "ad_group_update_data" }, "opts": [ { "example": "option1" } ] } ``` ### Response #### Success Response (200) - **operations.UpdateAdGroupsJobResponse** (operations.UpdateAdGroupsJobResponse) - The response object containing details of the update job. #### Response Example ```json { "example": "job_update_response" } ``` ### Errors - **apierrors.ProblemDetailsError** - Status Code: 400, 403 - Content Type: application/json - **apierrors.APIError** - Status Code: 4XX, 5XX - Content Type: */* ``` -------------------------------- ### Define Campaign Flight Schedule Source: https://github.com/thetradedesk/ttd-workflows-go/blob/main/docs/sdks/campaigns/README.md This Go code snippet defines a campaign flight, specifying the start and end dates. It uses `types.MustTimeFromString` for date parsing, essential for scheduling campaign activities. ```go Flights: []components.CampaignWorkflowFlightInput{ components.CampaignWorkflowFlightInput{ StartDateInclusiveUTC: types.MustTimeFromString("2024-09-20T06:04:19.345Z"), EndDateExclusiveUTC: types.MustNewTimeFromString("2024-01-18T07:43:56.299Z"), }, } ```