7.7.8.2.1 How to start the Manual programmatic data import for certain time frames and test runs?
Challenge:
The default ADvendio settings allow scheduling an import for Programmatic Data based on the current month. During initial testing, there might be the need to customize the time frame and for example only import data for a single day, or data from a past month. Is there a way to import more specific Programmatic Data into ADvendio?
Solution:
There is the possibility to start a Programmatic Data Import by using code in the Development Console, which allows setting manual information.
Go to your Org
Go to “Setup” → Developer Console
A new pop window will open
Go to the “Open Execute Anonymous Window”
A “Enter Apex Code” window will open
Paste the Sample APEX CODE *
To do these steps a System Administrator user is required with access to the Salesforce Development Console.
Where the following Sample APEX code needs to be executed.
Sample APEX CODE*
Paste this code ONLY after the parts of the code described below have been edited.
String adserverLoginId = 'THE RECORD ID OF YOUR CONNECTION';
String username = 'YOUR SALESFORCE USERNAME';
String smail = 'EMAIL RECIPIENT FOR RESULT MAIL';
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeStringField('operation', 'RTBReport');
gen.writeStringField('endpoint', 'https://MYDOMAIN.my.salesforce.com/services/Soap/c/46.0/');
gen.writeBooleanField('sandbox', true);
gen.writeStringField('adserverLoginIds', adserverLoginId);
gen.writeStringField('username', username);
gen.writeStringField('smail', smail);
gen.writeStringField('startDate', 'STARTING TIME IN FORMAT: 2020-02-01T00:00:00+01:00');
gen.writeStringField('endDate', 'END TIME IN FORMAT: 2020-02-02T23:59:59+01:00');
gen.writeStringField('currencyCode', Userinfo.getDefaultCurrency());
gen.writeEndObject();
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint('https://exchange.advendio.com:8080/AdServerGateway_2.138/startJob?operation=RTBReport');
req.setHeader('Content-Type', 'application/json');
req.setBody(gen.getAsString());
HttpResponse res = new Http().send(req);
Here highlighted in green are the parts of the lines/code of the sample APEX CODE that need to be edited accordingly:
Line 1 → String adserverLoginId = 'THE RECORD ID OF YOUR CONNECTION'
Go to the connection in use and copy the ID from the URL
e.g. a0a4I00000K4xAWQAZ (present in your URL)
Line 2 → String username = 'YOUR SALESFORCE USERNAME'
e.g. test@user.com
Line 3 → String smail = 'EMAIL RECIPIENT FOR RESULT MAIL'
e.g. email@user.com
Line 7 → gen.writeStringField('endpoint', 'https://MYDOMAIN.my.salesforce.com/services/Soap/c/46.0/')
Replace the first part of the URL with the configured my domain of your Salesforce Org
See more information here
Line 8 → ('sandbox', true);
If you are using this script in a Sandbox environment use ‘true’ otherwise use ‘false’
Line 12 → gen.writeStringField('startDate', 'STARTING TIME IN FORMAT: 2020-02-01T00:00:00+01:00');
Delete “ STARTING TIME IN FORMAT: “
Only leave the start date formatting
e.g. of how it should look → ('startDate', '2023-11-01T00:00:00+01:00')
+ Hour difference of your local timezone. As default we’re using GMT, so you have to add the difference in hours to your timezone, which is also the same as the UTC difference.
For example, for EST (New York) it’s GMT/UTC - 5:00, so you enter -05:00
Line 13 → gen.writeStringField('endDate', 'END TIME IN FORMAT: 2020-02-02T23:59:59+01:00')
Delete “ END TIME IN FORMAT: “
Only leave the start date formatting
e.g. of how it should look → ('endDate', '2023-11-30T00:00:00+01:00')
+ Hour difference of your local timezone. As default we’re using GMT, so you have to add the difference in hours to your timezone, which is also the same as the UTC difference.
For example, for EST (New York) it’s GMT/UTC - 5:00, so you enter -05:00
Line 18 → req.setEndpoint('https://exchange.advendio.com:8080/AdServerGateway_2.138/startJob?operation=RTBReport');
The part after “AdServerGateway_” needs to be replaced with the current ADvendio version you are using.
If you are unsure, please check the Custom Label ServiceVersionGateway in the Setup of your Salesforce Org.
Setup → User Interface → Custom Labels → ServiceVersionGateway
programmatic data import