BingAds / BingAds-PHP-SDK

Other
56 stars 45 forks source link

Can't update product group bids. #173

Closed yoosefi closed 1 year ago

yoosefi commented 1 year ago

SDK Version: v13.0.14

The following (simplified) code:

$updateProductGroupBids = new ApplyProductPartitionActionsRequest();
$updateProductGroupBids->CriterionActions = [];
$action = new AdGroupCriterionAction();
$action->Action = ItemAction::Update;
$action->AdGroupCriterion = new BiddableAdGroupCriterion();
$action->AdGroupCriterion->AdGroupId = $adGroupId;
$action->AdGroupCriterion->Id = $criterionId;
$action->AdGroupCriterion->CriterionBid = new FixedBid();
$action->AdGroupCriterion->CriterionBid->Amount = $bid;
$updateProductGroupBids->CriterionActions[] = $action;

$soap->ApplyProductPartitionActions($updateProductGroupBids);

Generates this SOAP request:

POST /Api/Advertiser/CampaignManagement/V13/CampaignManagementService.svc HTTP/1.1
Host: campaign.api.bingads.microsoft.com
Connection: close
User-Agent: BingAdsSDKPHP 13.0.14 7.4.32
Content-Type: text/xml; charset=utf-8
SOAPAction: "ApplyProductPartitionActions"
Content-Length: redacted

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://bingads.microsoft.com/CampaignManagement/v13" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SOAP-ENV:Header>
    <ns1:CustomerAccountId>redacted</ns1:CustomerAccountId>
    <ns1:CustomerId/>
    <ns1:DeveloperToken>redacted</ns1:DeveloperToken>
    <ns1:UserName/>
    <ns1:Password/>
    <ns1:AuthenticationToken>redacted</ns1:AuthenticationToken>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <ns1:ApplyProductPartitionActionsRequest>
      <ns1:CriterionActions>
        <ns1:AdGroupCriterionAction>
          <ns1:Action>Update</ns1:Action>
          <ns1:AdGroupCriterion>
            <ns1:AdGroupId>redacted</ns1:AdGroupId>
            <ns1:Criterion xsi:nil="true"/>
            <ns1:Id>redacted</ns1:Id>
            <ns1:Status xsi:nil="true"/>
            <ns1:Type xsi:nil="true"/>
          </ns1:AdGroupCriterion>
        </ns1:AdGroupCriterionAction>
      </ns1:CriterionActions>
    </ns1:ApplyProductPartitionActionsRequest>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

That doesn't look right. The bid amount isn't even included in the XML. The docs say the request should be different.

https://learn.microsoft.com/en-us/advertising/campaign-management-service/adgroupcriterion?view=bingads-13#remarks

If you generate the SOAP manually, use the type attribute of the node as shown in the following example, to specify the type of criterion.

<AdGroupCriterion i:type="BiddableAdGroupCriterion" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Id i:nil="true" />
<Status i:nil="true" />
. . .
</AdGroupCriterion>

Got this generic response, btw:

HTTP/1.1 200 OK
Content-Length: 730
Connection: keep-alive
Content-Type: text/xml; charset=utf-8
Date: Tue, 18 Oct 2022 01:04:07 GMT
Server: Kestrel
x-ms-requestid: redacted
x-ms-trackingid: redacted

<?xml version="1.0"?>
<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>

Looks like the SDK isn't encoding this request correctly. I tried some SoapVar hackery to inject custom XML to make it conform to the spec, but couldn't nail it down.

yoosefi commented 1 year ago

deferring to the forum https://learn.microsoft.com/en-us/answers/questions/1129654/applyproductpartitionactions-internal-error.html