Trouble setting BiddingScheme on campaign creation

Lonny Kapelushnik 16 Reputation points
2022-01-14T08:17:07.613+00:00

I am trying to set the bidding scheme when adding a campaign. Here is a sample script:

$authentication = (new OAuthWebAuthCodeGrant())
    ->withEnvironment(ApiEnvironment::Production)
    ->withClientId($clientId)
    ->withClientSecret($clientSecret);

$authorizationData = (new AuthorizationData())
    ->withAuthentication($authentication)
    ->withDeveloperToken($developerToken)
    ->withAccountId($advertiserAccountId);

$authorizationData->Authentication->withOAuthTokens($oAuthTokens)

$campaign = new Campaign();
$campaign->Name = 'test name';
$campaign->BudgetType = BudgetLimitType::DailyBudgetStandard;
$campaign->DailyBudget = 5;
$campaign->Languages = ['English'];
$campaign->TimeZone = 'EasternTimeUSCanada';

$campaign->BiddingScheme = new MaxClicksBiddingScheme();
$campaign->BiddingScheme->MaxCpc = new Bid();
$campaign->BiddingScheme->MaxCpc->Amount = 0.05;

$request = new AddCampaignsRequest();

$request->AccountId = $advertiserAccountId;
$request->Campaigns = [$campaign];

$proxy = new ServiceClient(
    ServiceClientType::CampaignManagementVersion13,
    $authorizationData,
    ApiEnvironment::Production
);

$proxy->GetService()->AddCampaigns($request);

Here is the response I receive:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</faultcode><faultstring xml:lang="en-US">The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the &lt;serviceDebug&gt; configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.</faultstring></s:Fault></s:Body></s:Envelope>

Any guidance/suggestions are appreciated.

Microsoft Advertising API
Microsoft Advertising API
A Microsoft API that provides programmatic access to Microsoft Advertising to manage large campaigns or to integrate your marketing with other in-house systems.
424 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lonny Kapelushnik 16 Reputation points
    2022-01-14T17:39:17.707+00:00

    I believe I found the solution. The code for setting the BiddingScheme needed to be like this:

            $biddingScheme = new MaxClicksBiddingScheme();
            $biddingScheme->MaxCpc = new Bid();
            $biddingScheme->MaxCpc->Amount = $data['bid'];
            $campaign->BiddingScheme = new SoapVar(
                $biddingScheme, 
                SOAP_ENC_OBJECT, 
                'MaxClicksBiddingScheme', 
                $proxy->GetNamespace()
            );
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.