Manipulating Orders and LineItems with rdfp

First, we load rdfp and specify the DFP network we would like to connect to. Then we authenticate by using dfp_auth(). Any existing cached token would be used or we will be prompted to authenticate via the browser.

library(rdfp)
options(rdfp.network_code = 123456789)
dfp_auth()

Create an Order

This example uses a test company as an advertiser and yourself as the trafficker, to create an order.

request_data <- list('filterStatement'=list('query'="WHERE name = 'TestCompany1'"))
dfp_getCompaniesByStatement_result <- dfp_getCompaniesByStatement(request_data) 

request_data <- list(list(name='TestOrder', 
                          startDateTime=list(date=list(year=2018, month=12, day=1), 
                                             hour=0,
                                             minute=0,
                                             second=0,
                                             timeZoneID='America/New_York'),
                          endDateTime=list(date=list(year=2018, month=12, day=31), 
                                           hour=23,
                                           minute=59,
                                           second=59,
                                           timeZoneID='America/New_York'), 
                          notes='API Test Order', 
                          externalOrderId=99999, 
                          advertiserId=dfp_getCompaniesByStatement_result$id, 
                          traffickerId=dfp_getCurrentUser()$id))
dfp_createOrders_result <- dfp_createOrders(request_data)

Get Line Items By A Filter

Below is an example of how to get objects by Publishers Query Language (PQL) statement. The statement is constructed as a list of lists that are nested to emulate the hierarchy of the XML to be created. The example uses the dfp_getLineItemsByStatement function from the [LineItemService] (https://developers.google.com/ad-manager/api/reference/v201905/LineItemService)

# retrieve 3 line items that have a status of "DELIVERING"
request <- list('filterStatement'=list('query'="WHERE status='DELIVERING' LIMIT 3"))
resultset <- dfp_getLineItemsByStatement(request, as_df=TRUE)
resultset[,c('orderId', 'id', 'priority', 'deliveryRateType')]