From f1f75fdb9762fbd4738a89435103b0fa2e6f1995 Mon Sep 17 00:00:00 2001 From: Mehmet Gungoren Date: Fri, 8 Oct 2021 11:38:08 +0300 Subject: [PATCH] implement assign creative set to an adgroup --- asa/creative_sets.go | 18 ++++++++++++++++++ asa/creative_sets_test.go | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/asa/creative_sets.go b/asa/creative_sets.go index c5e0ded..f19e8e6 100644 --- a/asa/creative_sets.go +++ b/asa/creative_sets.go @@ -356,3 +356,21 @@ func (s *CreativeSetsService) FindCreativeSets(ctx context.Context, params *Find return res, resp, err } + +// AssignAdGroupCreativeSetRequest is the request to assign a Creative Set to an ad group +// +// https://developer.apple.com/documentation/apple_search_ads/assignadgroupcreativesetrequest +type AssignAdGroupCreativeSetRequest struct { + CreativeSetID int64 `json:"creativeSetID"` +} + +// AssignCreativeSetsToAdGroup Creates a Creative Set assignment to an ad group +// +// https://developer.apple.com/documentation/apple_search_ads/assign_creative_sets_to_an_ad_group +func (s *CreativeSetsService) AssignCreativeSetsToAdGroup(ctx context.Context, campaignID int64, adgroupID int64, request *AssignAdGroupCreativeSetRequest) (*AdGroupCreativeSetResponse, *Response, error) { + url := fmt.Sprintf("campaigns/%d/adgroups/%d/adgroupcreativesets", campaignID, adgroupID) + res := new(AdGroupCreativeSetResponse) + resp, err := s.client.post(ctx, url, request, res) + + return res, resp, err +} diff --git a/asa/creative_sets_test.go b/asa/creative_sets_test.go index 4bab10d..cf77504 100644 --- a/asa/creative_sets_test.go +++ b/asa/creative_sets_test.go @@ -68,3 +68,11 @@ func TestFindCreativeSets(t *testing.T) { return client.CreativeSets.FindCreativeSets(ctx, &FindCreativeSetRequest{}) }) } + +func TestAssignCreativeSetsToAdGroup(t *testing.T) { + t.Parallel() + + testEndpointWithResponse(t, "{}", &AdGroupCreativeSetResponse{}, func(ctx context.Context, client *Client) (interface{}, *Response, error) { + return client.CreativeSets.AssignCreativeSetsToAdGroup(ctx, 1, 99, &AssignAdGroupCreativeSetRequest{}) + }) +}