Campaign Item Amount Calculation API
- 1 REST web service
- 1.1 URL
- 1.2 Method
- 1.3 URL Params
- 1.4 Data Params
- 1.5 Success Response
- 1.6 Error Response
- 1.7 Logic
- 1.7.1 Amount Calculation
- 1.7.2 Package Calculations
- 1.7.3 Fields calculated
- 1.8 Examples
- 1.8.1 Get a Session-ID
- 1.8.2 Simple request for an existing Campaign Item
- 1.8.2.1 Call Amount calculation web service
- 1.8.2.2 requestBody.txt
- 1.8.2.3 Response
- 1.8.3 Simple request for a new Campaign Item (virtual Campaign Item)
- 1.8.3.1 Call Amount calculation web service
- 1.8.3.2 requestBody.txt
- 1.8.3.3 Response
- 1.8.4 Simple request for new Campaign Items (virtual Campaign Items) in the same Media Campaign
- 1.8.5 Simple request for a Package
- 1.9 Usage in Apex
In order to use the Campaign Item Calculation API, your Salesforce Org needs to have API usage activated through having an API usage license as well as having the finance module activated with the finance license.
The Campaign Item Calculation API is implemented as Apex class and is exposed as REST web service by using Salesforce standard functionality (see Apex Developer Guide for more information). For general information about the Campaign Item calculations, see 4.5 Net Calculator . The Campaign Item Calculation functionality calculates the net and gross amounts (B3-N3) and also calculates values in package Campaign Items.
REST web service
URL
https://<my-domain-name>.my.salesforce.com/services/apexrest/ADvendio/ADvendio__Campaign_Item__c/DoCalculations/
Method
PATCH
URL Params
Â
Data Params
A JSON object with the attribute campaignItems, containing a JSON serialized list of Campaign Items.
Example: { "campaignItems":[{<Campaign Item>}, ...]}
Success Response
Code: 200
Content: A JSON serialized list of the Campaign Items from the request body, but now with updated packages and amount fields.
Example: [{<Campaign Item>}, ...]
Error Response
See Salesforce Apex REST Documentation
Logic
Amount Calculation
The Campaign Item amounts are calculated by using the Sales Price, the Quantity and the Frequency with all the surcharge and discount fields.
Package Calculations
Fields calculated
The following fields are calculated by either the amount calculation or the package calculation:
Sales_Price__c, SurchargeSalesPrice__c, SurchargeSalesPricePct__c, Quantity__c,
Frequency__c, Amount_B3APEX__c, SurchargeB3__c, SurchargeB3Abs__c,
Amount_B2APEX__c, SurchargeB2__c, SurchargeB2Abs__c, AmountAPEX__c,
RateDiscount1AbsCustom__c, Quantity_Discount_custom__c, RateDiscount2AbsCustom__c,
Rate_Discount_2_custom__c, RateDiscount3AbsCustom__c, Rate_Discount_3_custom__c,
RateDiscount4AbsCustom__c, Rate_Discount_4__c, Amount_netAPEX__c, AC__c,
Agency_Commission__c, Amount_net_netAPEX__c, ThirdPartyCommissionCustom__c,
Amount_net3APEX__c, from_Date__c, until_Date__c, Guaranteed_AI__c, VatAmount__c,
VatAmountB__c, AgencyEarnings__c, RateDiscount1Abs__c, RateDiscount2Abs__c,
RateDiscount3Abs__c, RateDiscount4Abs__c, ThirdPartyCommissionAbs__c
Examples
Get a Session-ID
curl -v https://login.salesforce.com/services/oauth2/token -d "grant_type=password" -d "client_id=<CLIENT_ID>" -d "client_secret=<CLIENT_SECRET>" -d "username=<USER_NAME>" -d "password=<PASSWORD+TOKEN>" -H 'X-PrettyPrint:1'
Â
Get CLIENT_ID and CLIENT_SECRET from any connected app or create a new app in your org: App Manager -> New Connected App
Simple request for an existing Campaign Item
A simple request with an existing Campaign Item to calculate the amounts with a new Quantity Discount of 10%.
Call Amount calculation web service
curl https://<my-domain-name>.my.salesforce.com/services/apexrest/ADvendio/ADvendio__Campaign_Item__c/DoCalculations/ -H 'Authorization: Bearer <SESSION_ID>' -H "Content-Type: application/json" -H 'X-PrettyPrint:1' -d @requestBody.txt --request PATCH
requestBody.txt
Response
Simple request for a new Campaign Item (virtual Campaign Item)
A simple request with a Campaign Item we want to create, to calculate the amounts.
Call Amount calculation web service
requestBody.txt
Response
Simple request for new Campaign Items (virtual Campaign Items) in the same Media Campaign
A simple request with multiple Campaign Items in the same Media Campaign we want to create, to calculate the amounts.
Call Amount calculation web service
In this part you need to execute the an Apex method through the developer console in order to obtain a valid virtual MC Id.
System.debug(CheckAvailabilityService.getFakeId(MediaCampaign__c.SObjectType));
Then the following request can be used:
Simple request for a Package
A simple request with an existing Campaign Item to calculate the amounts for a package.
Call Amount calculation web service
Usage in Apex
Â