Export (0) Print
Expand All

Update Campaigns in C#

The following example shows how to update campaigns within an account using the Campaign Management UpdateCampaigns service operation.

This example has been developed and run within the environment described in Getting Started Using C# and Visual Basic with Bing Ads Services.

System_CLiX_note Note

This example uses the UserName and Password elements for authentication. For Managing User Authentication with OAuth, replace the UserName and Password elements with the AuthenticationToken, which is your OAuth access token.

static void UpdateCampaigns(
    CampaignManagementServiceClient service,
    string username,
    string password,
    string appToken,
    string devToken,
    long customerAccountId,
    long customerId,
    long accountId,
    long campaignId)
    UpdateCampaignsRequest request = new UpdateCampaignsRequest();
    request.ApplicationToken = appToken;
    request.CustomerAccountId = customerAccountId.ToString();
    request.CustomerId = customerId.ToString();
    request.DeveloperToken = devToken;
    request.Password = password;
    request.UserName = username;

    // Set the account ID.
    request.AccountId = accountId;

    // Create an array of Campaign objects.
    request.Campaigns = new Campaign[1];

    // Create the first Campaign object.
    request.Campaigns[0] = new Campaign();

    // Initialize the first Campaign object.
    // The Id element defines which campaign will be updated.
    request.Campaigns[0].Id = 1234;

    // Change the daily budget of the campaign.
    request.Campaigns[0].DailyBudgetStandard = 112.75;

        UpdateCampaignsResponse response = service.UpdateCampaigns(request);

    // Handle any faults from the Web service.
    // Exceptions not handled here will be passed back to the 
    // caller.

    // Capture any generic errors.
    catch (FaultException<AdApiFaultDetail> adApiFault)
        // Get the AdApiFaultDetail object.
        AdApiFaultDetail detail = adApiFault.Detail;
        foreach (AdApiError error in detail.Errors)
            Console.Write("Ad API error");
            Console.WriteLine(" '{0}' ({1}) encountered.",

    // Capture any service operation exceptions.
    catch (FaultException<ApiFaultDetail> apiFault)
        ApiFaultDetail detail = apiFault.Detail;

        // Display any service operation error information.
        foreach (OperationError opError in detail.OperationErrors)
            Console.Write("Operation error");
            Console.WriteLine(" '{0}' ({1}) encountered.",

        // Display any batch error information.
        foreach (BatchError batchError in detail.BatchErrors)
            Console.Write("Batch error");
            Console.Write(" '{0}' ({1}) encountered",
            Console.WriteLine(" array index = {0}.",


Community Additions

© 2015 Microsoft