(Quick Reference) Service: Upsert a promotion list

Description: This web service is used to insert a promotion list object to the database if it does not already exist, or update it.

URL with external_id:

https://BASE_URL/api/VERSION/promotionLists/reference/{id}

Method: POST

Request content type: application/json

Parameters:

NameDescriptionTypeRequiredExample values
description Stringyes 
startDateShould be formatted as yyyy-MM-ddDateyes 
endDateShould be formatted as yyyy-MM-ddDateyes 
isActiveBy default, it is set to true and it tell if the promotion list is active or notBooleannotrue, false
applyToAllCustomersBy default, it's set to false and it tell if the promotion list is assigned to all customers or notBooleannotrue, false
promotionInputsIt contain the sequence inputs for the promotionJSONyes 
promotionOutputsIt contain the sequence outputs concluded from the inputs of the promotionJSONyes 

Promotion details parameters :

Parameter name: promotionInputs

Parameter type: a json structure

NameDescriptionTypeRequiredExample values
inputTypeShould be equal to 1 for item quantity , 2 for item group, 3 for invoice amount, 4 for item amount and 5 for item categoryInteger/Stringyes1,2,3,"4","5"
valueShould be a double if inputType is an amount (3,4) or integer if inputType is a quantity (1,2,5)Double/Integeryes 
sequenceUsed to manage input/ouput sequencesIntegeryes 
serialIn every sequence, input can have one or more serials connected by operator ANDIntegeryes 
itemIdRequired if inputType equal to '1' or '4'String- 
unitIdRequired if inputType equal to '1' or '4'String- 
itemGroupIdRequired if inputType equal to '2'String- 
itemCategoryIdRequired if inputType equal to '5'String- 
enablePromotionSumBy default it is set to falseBooleannotrue, false
applyToAllItemsInputBy default it set to false and it tell if the promotion inputs are applied for all items or not, it is considered only if inputType equal to '1' or '4'Booleanyestrue , false
promotionTypeIt define the promotion type and it take one of this value : '1' for greater than , '2' for less than and '3' for equalInteger/Stringyes1,2,"3"

the numeric value used in sequence attribute to declare a sequence must at least used one time for sequence in the promotion output
In case inputType equal to '1' or '4' so itemId and unitId are required, there is one more condition is that the item extracted from the specified itemId must be assigned to the unit related to the specified unitId

Parameter name: promotionOutputs

Parameter type: a json structure

NameDescriptionTypeRequiredExample values
outputTypeShould be equal to 1 if Item quantity, 2 if Item Discount , 3 if Item Group, 4 if Item Group Discount, 5 if Invoice Discount, 6 if Item Category and 7 if Item Category DiscountInteger/Stringyes1,2,3,4,5,6,7
valueShould be a double if outputType is a discount (2,4,5,7) or integer if outputType is a quantity (1,3,6)Double/Integeryes 
discountTypeShould be equal to 1 if Percentage, 2 if Value, required if outputType is a discount (2,4,5,7)Integer/String-1,2
sequenceUsed to manage input/ouput sequencesIntegeryes 
serialIn every sequence, input can have one or more serials connected by operator ANDIntegeryes 
itemIdRequired if inputType equal to '1' or '2'String- 
unitIdRequired if inputType equal to '1' or '2'String- 
itemGroupIdRequired if inputType equal to '3' or '4'String- 
itemCategoryIdRequired if inputType equal to '6' or '7'String- 
duplicatePromotionBy default, it is set to falseBooleannotrue, false
applyToAllItemsOutputBy default it set to false and it tell if the promotion outputs are applied to all items or not, it is considered only if outputType@ equal to '1' or '2'Booleanyestrue , false

the numeric value used in sequence attribute to declare a promotion output must be already used in a promotion input.

In case outputType equal to '1' or '2' so itemId and unitId are required, there is one more condition is that the item extracted from the specified itemId must be assigned to the unit related to the specified unitId.

Example:

{
    "reference": "R-P-08969",
    "description": "Five for double five",
    "startDate": "2016-08-01",
    "endDate": "2016-08-31",
    "isActive": true,
    "paymentTypeId": 7,
    "applyToAllCustomers":true,
    "promotionInputs": [
      {
      "itemId": 13,
      "unitId": 1,
      "inputType": "5",
      "sequence": 1,
      "serial": 1,
      "value": "5",
      "enablePromotionSum": true,
      "applyToAllItemsInput":true,
      "promotionType" : 1,
      "itemGroupId" : 1,
      "itemCategoryId" :1
     }],
    "promotionOutputs": [
      {
        "itemId": 13,
        "unitId": 1,
        "outputType": "7",
        "itemGroupId": "1",
        "discountType": "1",
        "sequence": 1,
        "serial": 1,
        "value": "5",
        "duplicatePromotion":true,
        "applyToAllItemsOutput":false,
        "itemGroupId" : 1,
        itemCategoryId:1
     },
     {
        "itemId": 13,
        "unitId": 1,
        "outputType": "7",
        "itemGroupId": "1",
        "discountType": "2",
        "sequence": 1,
        "serial": 2,
        "value": "5",
        "duplicatePromotion":true,
        "applyToAllItemsOutput":false,
        "itemGroupId" : 1,
        "itemCategoryId" :1
     }]
}

Success Output

Success case: response.status = 201

{
  "id": 18,
  "reference": "R-P-08969",
  "description": "Five for double five",
  "startDate": "2016-08-01",
  "endDate": "2016-08-31",
  "isActive": true,
  "applyToAllCustomers": true,
  "promotionInputs": [
    {
      "id": 46,
      "href": "/api/v1.0/promotionInputs/46"
    }
  ],
  "promotionOutputs": [
    {
      "id": 48,
      "href": "/api/v1.0/promotionOutputs/48"
    },
    {
      "id": 49,
      "href": "/api/v1.0/promotionOutputs/49"
    }
  ],
  "organization": "New Delice",
  "dateCreated": "2016-10-07T15:38:30Z",
  "lastUpdated": "2016-10-07T15:38:30Z"
}

Failure Output

Failure case:response.status = 400

{
  "error": "not_unique",
  "error_description": "reference already used"
}

{
  "error": "missing_param",
  "error_description": "discountType parameter is missing"
}

{
  "error": "missing_param",
  "error_description": "itemId parameter is missing"
}

{
  "error": "invalid_sequence",
  "error_description": "Input options should be equal to output options."
}

Failure case:response.status = 404
{
  "error": "not_found",
  "error_description": "The item with the id 999 doesn't exist."
}

{
  "error": "not_found",
  "error_description": "The unit with the id 100 doesn't exist."
}

{
  "error": "not_found",
  "error_description": "The unit with the id 100 doesn't exist."
}

{
  "error": "not_found",
  "error_description": "The item group with the id 618 doesn't exist."
}

Failure case:response.status = 500
{
   "error": "server_error",
   "error_description": "Oops! Something went wrong..."
}