/
Dynamic Pricing API - Documentation

Dynamic Pricing API - Documentation

Ā Content

Table of Contents

In order to use the Dynamic Pricing API, your Salesforce Org needs to have API usage activated through having an API usage License.Ā 

Custom Matching criterion

Please make sureĀ to add the relevant fields also to the Campaign Item you provide to the API method if you are using the Custom Matching Criteria as described hereĀ 8.4.6 Setup Price Rules/Dynamic Pricing (Feature Setting). Our logic will not query these fields by itself so missing this data might lead to not matching Price Rules.Ā 

The Dynamic Pricing 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 dynamic pricing feature, see 3.3.5 Price Rules / Dynamic Pricing

1. REST web service

1.1. URL

https://<my-domain-name>.my.salesforce.com/services/apexrest/ADvendio/ADvendio__Campaign_Item__c/ApplyPriceRules/

1.2. Method

PATCH

1.3. URL Params

-

1.4. Data Params

A JSON object with the attribute campaignItems, what contains a JSON serialized list of Campaign Items.

Example: { "campaignItems":[{<Campaign Item>}, ...]}

1.5. Success Response

Code: 200

Content: A JSON serialized list of the Campaign Items from the request body, but now with updated surcharge and discount fields.

Example: [{<Campaign Item>}, ...]

1.6. Error Response

See Salesforce Apex REST Documentation

1.7. Logic

Error rendering macro 'excerpt-include' : User 'null' does not have permission to view the page 'AD:Technical Documentation - Dynamic Pricing'.

1.8. Examples

1.8.1. Get a Session-ID

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'

Connected App

Get CLIENT_ID and CLIENT_SECRET from any connected app or create a new app in your org: App Manager -> New Connected App

1.8.2. Simple request

A simple request with a Price Rule, having all criteria fields empty (so it matches every Campaign Item) and setting surcharge B2 to 20%.

Call Dynamic Pricing web service
curl https://<my-domain-name>.my.salesforce.com/services/apexrest/ADvendio/ADvendio__Campaign_Item__c/ApplyPriceRules/ -H 'Authorization: Bearer <SESSION_ID>' -H "Content-Type: application/json" -H 'X-PrettyPrint:1' -d @requestBody.txt --request PATCH
requestBody.txt
{
    "campaignItems": [
        {
            "ADvendio__Ad_Price__c": "a0T7Y000005TxIWUA0",
            "ADvendio__from_Date__c": "2019-06-03",
            "ADvendio__until_Date__c": "2019-06-09"
        }
    ]
}
Response
[
    {
        "attributes": {
            "type": "ADvendio__Campaign_Item__c"
        },
        "ADvendio__from_Date__c": "2019-06-03",
        "ADvendio__until_Date__c": "2019-06-09",
        "ADvendio__Ad_Price__r": {
            "attributes": {
                "type": "ADvendio__Ad_price__c",
                "url": "/services/data/v45.0/sobjects/ADvendio__Ad_price__c/a0T7Y000005TxIWUA0"
            },
            "ADvendio__Ad_Spec__c": "a0R7Y00000Bi9JBUAZ",
            "Id": "a0T7Y000005TxIWUA0",
            "ADvendio__Ad_Spec__r": {
                "attributes": {
                    "type": "ADvendio__Ad_Specs__c",
                    "url": "/services/data/v45.0/sobjects/ADvendio__Ad_Specs__c/a0R7Y00000Bi9JBUAZ"
                },
                "Id": "a0R7Y00000Bi9JBUAZ",
                "ADvendio__Ad_Type__c": "a0S7Y00000JRcaDUAT",
                "ADvendio__Placement__c": "a2B7Y000001ox8RUAQ",
                "ADvendio__Ad_Type__r": {
                    "attributes": {
                        "type": "ADvendio__Ad_Type__c",
                        "url": "/services/data/v45.0/sobjects/ADvendio__Ad_Type__c/a0S7Y00000JRcaDUAT"
                    },
                    "Id": "a0S7Y00000JRcaDUAT"
                },
                "ADvendio__Placement__r": {
                    "attributes": {
                        "type": "ADvendio__Placement__c",
                        "url": "/services/data/v45.0/sobjects/ADvendio__Placement__c/a2B7Y000001ox8RUAQ"
                    },
                    "Id": "a2B7Y000001ox8RUAQ",
                    "ADvendio__Site__c": "a2o7Y00000176LMQAY",
                    "ADvendio__Site__r": {
                        "attributes": {
                            "type": "ADvendio__Site__c",
                            "url": "/services/data/v45.0/sobjects/ADvendio__Site__c/a2o7Y00000176LMQAY"
                        },
                        "Id": "a2o7Y00000176LMQAY"
                    }
                }
            }
        },
        "ADvendio__Rate_Discount_4__c": 15.00,
        "ADvendio__Ad_Price__c": "a0T7Y000005TxIWUA0",
        "ADvendio__AppliedPriceRules__c": "{\"UpdatedFields\":{\"ADvendio__Rate_Discount_4__c\":\"15.00\"},\"AppliedRules\":[{\"attributes\":{\"type\":\"ADvendio__PriceRule__c\",\"url\":\"/services/data/v57.0/sobjects/ADvendio__PriceRule__c/a2C7Y000001Ia6UUAS\"},\"Id\":\"a2C7Y000001Ia6UUAS\",\"Name\":\"prise rules 1\",\"ADvendio__WhereToApply__c\":\"ADvendio__Rate_Discount_4__c\"}]}"
    }
]


1.8.3. Complex request

A more complex example to match the following Price Rule (additionally to more simple ones)

a more complex Price Rule
{
   "ADvendio__PriceRule__c":{
      "Id":"a2C7Y000001Ia6UUAS",
      "ADvendio__AdServerIdCategory__c":"Inventory",
      "ADvendio__FrequencyCapping__c":true,
      "ADvendio__DayTimeTargeting__c":true,
      "ADvendio__AdType__c":"a0GA000000mXrcMMAS",
      "ADvendio__Placement__c":"a1MA0000009rsHWMAY",
      "ADvendio__AdvertisingMedium__c":"a1kA0000002JIb0IAG",
      "ADvendio__WhereToApply__c":"ADvendio__Rate_Discount_2_custom__c",
      "ADvendio__Percentage__c":"99.00000000000",
      "CurrencyIsoCode":"EUR"
   }
}


Call Dynamic Pricing web service
curl https://<my-domain-name>.my.salesforce.com/services/apexrest/ADvendio/ADvendio__Campaign_Item__c/ApplyPriceRules/ -H 'Authorization: Bearer <SESSION_ID>' -H "Content-Type: application/json" -H 'X-PrettyPrint:1' -d @requestBody.txt --request PATCH
requestBody.txt
{
  "campaignItems":
    [
      {
        "attributes": {
          "type": "ADvendio__Campaign_Item__c",
          "url": "/services/data/v46.0/sobjects/ADvendio__Campaign_Item__c/a0w7Y00000oiyH9QAI"
        },
        "Id": "a0w7Y00000oiyH9QAI",
        "ADvendio__from_Date__c": "2023-06-05",
        "ADvendio__until_Date__c": "2023-06-25",
        "ADvendio__Ad_Price__c": "a0T7Y000005TxIQUA0",
        "ADvendio__FrequencyCapping__c": "1 per 1 hour",
        "RecordTypeId": "0127Y000002Kg5VQAS",
        "ADvendio__AdServerTargeting__c": "{\"Inventory\":{\"type\":\"List\",\"logic\":\"&&\",\"valL\":[{\"type\":\"Id\",\"valS\":\"\"},{\"type\":\"Id\",\"valS\":\"a0L7Y00000FA7jyUAD\"}]}}",
        "CurrencyIsoCode": "EUR",
        "ADvendio__DayTimeTargeting__c": "{\"Wednesday\":[{\"hour\":\"12\"},{\"hour\":\"13\"},{\"hour\":\"14\"}],\"Thursday\":[{\"hour\":\"12\"},{\"hour\":\"13\"},{\"hour\":\"14\"}],\"Friday\":[{\"hour\":\"12\"},{\"hour\":\"13\"},{\"hour\":\"14\"}]}"

      }
    ]
}
Response
[
    {
        "attributes": {
            "type": "ADvendio__Campaign_Item__c",
            "url": "/services/data/v45.0/sobjects/ADvendio__Campaign_Item__c/a0w7Y00000oiyH9QAI"
        },
        "ADvendio__Ad_Price__r": {
            "attributes": {
                "type": "ADvendio__Ad_price__c",
                "url": "/services/data/v45.0/sobjects/ADvendio__Ad_price__c/a0T7Y000005TxIQUA0"
            },
            "ADvendio__Ad_Spec__c": "a0R7Y00000Bi9J6UAJ",
            "Id": "a0T7Y000005TxIQUA0",
            "ADvendio__Ad_Spec__r": {
                "attributes": {
                    "type": "ADvendio__Ad_Specs__c",
                    "url": "/services/data/v45.0/sobjects/ADvendio__Ad_Specs__c/a0R7Y00000Bi9J6UAJ"
                },
                "Id": "a0R7Y00000Bi9J6UAJ",
                "ADvendio__Ad_Type__c": "a0S7Y00000JRcaKUAT",
                "ADvendio__Placement__c": "a2B7Y000001ox8GUAQ",
                "ADvendio__Ad_Type__r": {
                    "attributes": {
                        "type": "ADvendio__Ad_Type__c",
                        "url": "/services/data/v45.0/sobjects/ADvendio__Ad_Type__c/a0S7Y00000JRcaKUAT"
                    },
                    "Id": "a0S7Y00000JRcaKUAT",
                    "ADvendio__AdServer_Login__c": "a0M7Y000008E9coUAC",
                    "ADvendio__AdServer_Login__r": {
                        "attributes": {
                            "type": "ADvendio__AdServer_Logins__c",
                            "url": "/services/data/v45.0/sobjects/ADvendio__AdServer_Logins__c/a0M7Y000008E9coUAC"
                        },
                        "Id": "a0M7Y000008E9coUAC",
                        "RecordTypeId": "0127Y000002Kg4LQAS",
                        "RecordType": {
                            "attributes": {
                                "type": "RecordType",
                                "url": "/services/data/v45.0/sobjects/RecordType/0127Y000002Kg4LQAS"
                            },
                            "Id": "0127Y000002Kg4LQAS",
                            "DeveloperName": "DFP"
                        }
                    }
                },
                "ADvendio__Placement__r": {
                    "attributes": {
                        "type": "ADvendio__Placement__c",
                        "url": "/services/data/v45.0/sobjects/ADvendio__Placement__c/a2B7Y000001ox8GUAQ"
                    },
                    "Id": "a2B7Y000001ox8GUAQ",
                    "ADvendio__Site__c": "a2o7Y00000176LGQAY",
                    "ADvendio__Site__r": {
                        "attributes": {
                            "type": "ADvendio__Site__c",
                            "url": "/services/data/v45.0/sobjects/ADvendio__Site__c/a2o7Y00000176LGQAY"
                        },
                        "Id": "a2o7Y00000176LGQAY"
                    }
                }
            }
        },
        "CurrencyIsoCode": "EUR",
        "ADvendio__from_Date__c": "2023-06-05",
        "ADvendio__until_Date__c": "2023-06-25",
        "ADvendio__DayTimeTargeting__c": "{\"Wednesday\":[{\"hour\":\"12\"},{\"hour\":\"13\"},{\"hour\":\"14\"}],\"Thursday\":[{\"hour\":\"12\"},{\"hour\":\"13\"},{\"hour\":\"14\"}],\"Friday\":[{\"hour\":\"12\"},{\"hour\":\"13\"},{\"hour\":\"14\"}]}",
        "ADvendio__Rate_Discount_2_custom__c": 99.00,
        "RecordTypeId": "0127Y000002Kg5VQAS",
        "ADvendio__Ad_Price__c": "a0T7Y000005TxIQUA0",
        "ADvendio__AppliedPriceRules__c": "{\"UpdatedFields\":{\"ADvendio__Rate_Discount_2_custom__c\":\"99.00\"},\"AppliedRules\":[{\"attributes\":{\"type\":\"ADvendio__PriceRule__c\",\"url\":\"/services/data/v57.0/sobjects/ADvendio__PriceRule__c/a2C7Y000001Ia6UUAS\"},\"Id\":\"a2C7Y000001Ia6UUAS\",\"Name\":\"prise rules 1\",\"ADvendio__WhereToApply__c\":\"ADvendio__Rate_Discount_2_custom__c\"}]}",
        "Id": "a0w7Y00000oiyH9QAI",
        "ADvendio__FrequencyCapping__c": "1 per 1 hour",
        "ADvendio__AdServerTargeting__c": "{\"Inventory\":{\"type\":\"List\",\"logic\":\"&&\",\"valL\":[{\"type\":\"Id\",\"valS\":\"\"},{\"type\":\"Id\",\"valS\":\"a0L7Y00000FA7jyUAD\"}]}}"
    }
]


1.9. Usage in Apex

List<ADvendio__Campaign_Item__c> cis = ...
cis = ADvendio.DynamicPricing.applyPriceRules(cis);

Related content

3.3.5 Price Rules / Dynamic Pricing
3.3.5 Price Rules / Dynamic Pricing
More like this
8.4.6 Setup Price Rules/Dynamic Pricing (Feature Setting)
8.4.6 Setup Price Rules/Dynamic Pricing (Feature Setting)
Read with this
Campaign Item Amount Calculation API
Campaign Item Amount Calculation API
More like this
3.3.5.4 Automatically apply Price Rules
3.3.5.4 Automatically apply Price Rules
Read with this
Apply Targeting Sets API - Documentation
Apply Targeting Sets API - Documentation
More like this
8.5.4 Settings for the Custom Campaign Item Related List
8.5.4 Settings for the Custom Campaign Item Related List
Read with this