mitra p
mitra p

Reputation: 440

How to Update campaign in Bing Ads?

For Update campaign I am using this Code

public async Task<List<long?>> updateCampaign(Campaign campaign,string status)
    {
        try
        {
            campaign.Status = (CampaignStatus)(int)Enum.Parse(typeof(CampaignStatus), status);
            var request = new UpdateCampaignsRequest
            {
                Campaigns = new Campaign[] { campaign },
                CustomerId = "xxxxxx",
                UserName = "[email protected]",
                Password = "something@123",
                ApplicationToken = "myApplicationToken",
                CustomerAccountId = "123456",
                DeveloperToken = "1234567890"
            };

            CampaignService = new ServiceClient<ICampaignManagementService>(_authorizationData);
            CampaignService.RefreshOAuthTokensAutomatically = false;
            var result = (await CampaignService.CallAsync((s, r) => s.UpdateCampaignsAsync(r), request));

            if (result.TrackingId != null)
            {
                return result.CampaignIds.ToList();
            }
            else
            {
                return new List<long?>();
            }
        }
        catch (Exception ex)
        {
            ErrorLog.log(ex);
            return new List<long?>();
        }
    }

When I run this code, I got this error "Invalid client data. Check the SOAP fault details for more information"

thanks.

Upvotes: 0

Views: 454

Answers (1)

nenu235
nenu235

Reputation: 48

For updating the Campaign we can use "BulkServiceManager" for bulk updating of the campaign,you can use this service single campaign update also.

public async Task<List<long?>> updateCampaign(List<Campaign> campaigns)
    {
        try
        {
            var listBulkCampaign = new List<BulkCampaign>();
            foreach (var campaign in campaigns)
            {
              var _bulkCampaign = new BulkCampaign()
                {
                    Campaign = campaign
                };
                listBulkCampaign.Add(_bulkCampaign);
            }
            BulkServiceManager bulkServiceManager = new BulkServiceManager(_authorizationData);
            string fileName = bingCampaignUpdate.csv;
            var campaigns = (await bulkServiceManager.UploadEntitiesAsync(new EntityUploadParameters
            {
                Entities = listBulkCampaign,
                OverwriteResultFile = true,
                ResultFileDirectory = FileDirectory,
                ResultFileName = fileName,
                ResponseMode = ResponseMode.ErrorsAndResults
            })).OfType<BulkCampaign>().ToList();

            return new List<long?>();
        }
        catch (Exception ex)
        {
            ErrorLog.log(ex);
            return new List<long?>();
        }
}

You have to download .csv report and update the Campaigns.

I hope it helps you

Upvotes: 1

Related Questions