BingAds / BingAds-Python-SDK

Other
116 stars 162 forks source link

Wrong Soap Envelope sent every time not able to update #137

Closed bruno911 closed 4 years ago

bruno911 commented 4 years ago

Using BingAds SDK for Python I am not able to perform any operation to update because of a bug that I cannot resolve. The SDK uses Suds for the handling of SOAP operation.

Here is the wsdl: https://campaign.api.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v13/CampaignManagementService.svc?singleWsdl

# This function internally configures the authorization for BingAdsAPI
campaign_service = bc.get_bing_ads_client(account=account, service='CampaignManagementService')

update_ad_groups_request = campaign_service.factory.create('UpdateAdGroupsRequest')
update_ad_groups_request.CampaignId = campaign_id

ad_group = campaign_service.factory.create('AdGroup')
ad_group.Id = ad_group_id

bid = campaign_service.factory.create('Bid')

bid.Amount = new_bid
ad_group.CpcBid = bid

update_ad_groups_request.AdGroups = campaign_service.factory.create('ArrayOfAdGroup')

update_ad_groups_request.AdGroups.AdGroup.append(ad_group)

campaign_service.UpdateAdGroups(update_ad_groups_request)

When I send it it fails saying:

suds.WebFault: Server raised fault: 'The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter https://bingads.microsoft.com/CampaignManagement/v13:CampaignId. The InnerException message was 'There was an error deserializing the object of type System.Int64. The value '' cannot be parsed as the type 'Int64'.'. Please see InnerException for more details.'

When I open the soap Envelope:

....</SOAP-ENV:Header><ns1:Body><ns0:UpdateAdGroupsRequest><ns0:CampaignId>
<ns0:CampaignId>377072652</ns0:CampaignId><ns0:AdGroups><ns0:AdGroup><ns0:CpcBid>
<ns0:Amount>0.91</ns0:Amount></ns0:CpcBid><ns0:Id>1256742239729725</ns0:Id>
<ns0:Network/><ns0:PrivacyStatus/><ns0:Status/></ns0:AdGroup></ns0:AdGroups>
</ns0:CampaignId></ns0:UpdateAdGroupsRequest></ns1:Body></SOAP-ENV:Envelope>

Note how the Campaign ID is twice and also it wraps the whole envelope. I tried also directly with Suds and I have the same issue, other functions also have the same issue.

Because moving to parsing the envelopes by myself, I was wondering if someone has had this issue and what could be the reason.

eric-urban commented 4 years ago

@bruno911 I replied to the same via stack overflow. Please reach out if you have any follow up questions.