Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Refer to Salesforce Apex REST Documentation for error responses.

1.8. Examples

1.8.1.

...

Code Block
bash

Copy code

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'

...

Simple Request

Creating a Standard Campaign Item and a Package with a Header and Component:

...

1.8.3. Response

Code Block
json

Copy code

...

},
    "ADvendio__

...

Ad_

...

Price__c

...

": "a0T5t000001QpPYEA0",
    "from_Date__c": "2020-01-01",
    "until_Date__c": "2020-01-01",
    "Rate_Discount_4__c": 4.2,
    "Quantity__c": 3
  },

...

1.9. Usage in Apex

...

...

Code Block
List<ADvendio__Campaign_Item__c> cis = ... cis = ADvendio.PackageService.applyPackage(cis);

...

1.7. Logic

Technical Documentation - Package Creation

...

The Package Service API is an API service where you can create Virtual Campaign Items, either Standard or P

ackages.

Setup

Check this /wiki/spaces/QA/pages/3619913782 Wiki page to know how to configure Postman for your Scratch Org.

Once you have set up Postman in your Scratch Org, set up all the required data into a Postman Environment, set up a Postman request to obtain the access token, and saved the just obtained access token into the previously created environment, you will be ready to set up a Postman request for this API.

 

Fist and foremost, create a new PATCH request with an URL of {{instance-url}}/services/apexrest/ADvendio/ADvendio__Campaign_Item__c/PackageService. In this case {{instance-url}}is the base url of the Scratch Org that you will use, this Postman variable should have been set up during the previously referenced documentation. /wiki/spaces/QA/pages/3619913782

Next, in the Header tab you should have 2 headers, the Authorization key with a value of Bearer {{access-token}}, with {{access-token}} previously set up in the Postman Documentation, and the Content-Type key, with the value of application/json.

Here is an image example

...

Once that is done, head on to the Body tab, and put the campaign items data that you will use to create the virtual Campaign Items. In the following format:

 

...

 

Finally, execute the request.

Request Considerations

Here are some rules that must be followed in order for the request to be successful.

  • The Id of the Media Campaign put in mediaCampaignId must exist in the Org.

  • The Media Campaign record referenced in mediaCampaignId must have the ADvendio__NextNewPositionNumber__c field filled up with a number. (Example: 0)

  • The Id of any Ad Price put in Ad_Price__c from any Campaign Item in campaignItems must exist in the Org.

  • All Campaign Items in campaignItems must have have the following attributes filled, in other words, they are required:

    • Ad_Price__c, with a String format.

    • from_Date__c, with a [year]-[month]-[day] format as a String, using 2 numbers each, minus the year, which required 4. i.e. 2020-01-02.

    • until_Date__c, with a [year]-[month]-[day] format as a String, using 2 numbers each, minus the year, which required 4. i.e. 2020-01-02.

    • Quantity__c, with an Integer format.

  • A Package Header Campaign Item will be as such only if they have a Ad_Price__c that links to a Ad Spec with a Package Header (or Packet) Record Type.

  • A Package Header Campaign Item must have an Id attribute if there are Package Component Campaign Item in the request that are linked to the Package Header Campaign Item.

    • The value of this Id attribute can be any Id (but remember that it must be different between Package Header Campaign Item), here is one that works: a0wXX00XX000000001, just change the last digit to make a new Id.

  • A Package Component Campaign Item will be as such only if they:

    • Have a Ad_Price__c that links to the Ad Price of the Package Header Campaign Item, as a Component. This Package Header Campaign Item must also be in the body of the request.

    • Have a PacketItem__c attribute that has the same value as the Id of the Package Header Campaign Item that is linked to.

  • Additional optional Surcharge and Discount fields are allowed in the request, here is a list of the fields (Remember that each field has a format that they must be, check said format of each field in Setup → Object Manager of your Scratch Org):

Code Block
Sales_Price__c
SurchargeB2__c
SurchargeB2Abs__c
SurchargeB3__c
SurchargeB3Abs__c
SurchargeSalesPrice__c
SurchargeSalesPricePct__c
RateDiscount1AbsCustom__c
RateDiscount2AbsCustom__c
RateDiscount3AbsCustom__c
RateDiscount4AbsCustom__c
Rate_Discount_2_custom__c
Rate_Discount_3_custom__c
Rate_Discount_4__c
Quantity_Discount_custom__c

 

Examples

In this example -made with the curl format- there are 3 Campaign Items, the first one is a Standard Campaign Item, it is as such because of the Ad Price. The second one is a Package Header Campaign Item, and the third is a Package Component of the previous Package Header Campaign Item. See that the Package Header has a Id attribute that has the same value as the PacketItem__cattribute of the Package Component, this is very important, if they are not linked like this in the request -even when they are linked in the data base- the package component will not show as package component of the package header.

Request

Code Block
breakoutModewide
curl --location --request PATCH 'https://<MY_DOMAIN_NAME>.my.salesforce.com/services/apexrest/ADvendio/ADvendio__Campaign_Item__c/PackageService/' \
--header 'Authorization: Bearer <SESSION_ID>' \
--header 'Content-Type: application/json' \
--header 'X-PrettyPrint: 1' \
--data '{
  "request": {
    "mediaCampaignId": "a235t000000yMAZAA2",
    "campaignItems": [
      {
        "Ad_Price__c": "a0T5t000001QpPYEA0",
        "from_Date__c": "20-01-01",
        "until_Date__c": "20-01-01",
        "Rate_Discount_4__c": 4.2,
        "Quantity__c": 3
      },
      {
        "Ad_Price__c": "a0T5t000001QpQNEA0",
        "from_Date__c": "20-01-01",
        "until_Date__c": "30-01-01",
        "Quantity__c": 44,
        "Id": "a0wXX00XX000000001"
      },
      {
        "Ad_Price__c": "a0T5t000001QpPgEAK",
        "from_Date__c": "21-01-01",
        "until_Date__c": "29-01-01",
        "Quantity__c": 53,
        "PacketItem__c": "a0wXX00XX000000001"
      }
    ]
  }
}'

Result

...

breakoutModewide

...

Package.