Problem using forecastService
Closed this issue · 1 comments
Hi, I've problems using node-google-dfp. When I use service like InventoryService, all works well. But, I'm trying to use ForecastService (getAvailabilityForecast) that needs 2 params btw and doesn't work.
Here is some code:
const Dfp = require('node-google-dfp');
const dfpUser = new Dfp.User(MY_NETWORK_CODE, 'test pub', 'v201708');
const google = require('googleapis')
const ADVERTISER_ID = 'MY_ADVERTISER_ID'
const jwtClient = new google.auth.JWT(
'MY_EMAIL',
'./cred.pem',
null,
['https://www.googleapis.com/auth/dfp']);
dfpUser.setClient(jwtClient)
const endDatetime = moment().add(30, 'days').toISOString()
console.log('end_datetime ->', endDatetime)
const lineItem = {
targeting: {
inventoryTargeting: {
targetedAdUnits: [
{
adUnitId: 'MY_ADD_UNIT_ID',
includeDescendants: true,
}
]
},
geoTargeting: {
targetedLocations: [
{
id: '9068897'
}
]
},
},
lineItemType: 'SPONSORSHIP',
startDateTimeType: 'IMMEDIATELY',
endDateTime: endDatetime,
costType: 'CPM',
primaryGoal: {
units: '50',
unitType: 'IMPRESSIONS',
goalType: 'DAILY'
},
contractedUnitsBought: '100',
creativeRotationType: 'EVEN'
}
const prospectiveLineItem = {
'lineItem': lineItem,
'advertiserId': ADVERTISER_ID
}
const forecastOptions = {
includeContendingLineItems: true,
includeTargetingCriteriaBreakdown: true
}
dfpUser.getService('ForecastService', (err, service) => {
console.log('service ->', service)
/* LOG:
service -> { getAvailabilityForecast: [Function],
getAvailabilityForecastById: [Function],
getDeliveryForecast: [Function],
getDeliveryForecastByIds: [Function] }
*/
service.getAvailabilityForecast({lineItem: prospectiveLineItem, forecastOptions: forecastOptions}, (err, result) => {
console.log('err ->', err)
// console.log('result ->', result)
})
})
Here is my err output:
body: '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">soap:Bodysoap:Faultsoap:ClientUnmarshalling Error: cvc-complex-type.2.4.d: Invalid content was found starting with element 'geoTargeting'. No child element is expected at this point. </soap:Fault></soap:Body></soap:Envelope>' }
I don't understand this error since inventoryTargeting can have geoTargeting parameter. Do you have any idea why this call return this error ?
Thanks !! :)
Found the solution:
Object given to the soap api has to be in the order defined in the dfp api documentation.
Exemple:
Good
{
startDateTime: {...},
endDateTime: {...}
}
Bad
{
endDateTime: {...},
startDateTime: {...}
}