# Process basket

- Operation ID: `processSale_POST`
- HTTP method: `POST`
- Path: `/v4/promotions/v2/sale/process-sale/{identifierType}/{identifierValue}`
- [Human-readable API reference](https://hub.synerise.com/api-reference/loyalty-and-engagement#tag/Promotions/operation/processSale_POST)

## Self-contained OpenAPI method

The fenced document below contains this method's documentation and all of its local references. It is self-contained; no category or master specification fetch is required.

```yaml
openapi: 3.0.0
info:
  title: Synerise Public API
  version: 1.9.1
paths:
  /v4/promotions/v2/sale/process-sale/{identifierType}/{identifierValue}:
    post:
      tags:
        - Promotions
      summary: Process basket
      description: |
        Assign promotions to a basket and recalculate item values after discount.

        This method DOES NOT redeem any promotions or create a transaction.


        ---

        **API consumers:** <a href="/api-reference/authorization?tag=Authorization&amp;operationId=profileLogin" target="_blank" rel="noopener">Workspace (Business Profile)</a>, <a href="/api-reference/authorization?tag=Authorization&amp;operationId=userLogin" target="_blank" rel="noopener">Synerise User</a>

        **API key permission required:** `PROMOTIONS_SALE_PROMOTIONS_READ`

        **User role permission required:** `campaigns_promotions: read`
      operationId: processSale_POST
      security:
        - JWT: []
      parameters:
        - name: identifierType
          in: path
          description: |
            The Profile identifier to use for the request.

            `externalId` is known as `customId` or `custom_identify` in other Synerise services.
          required: true
          schema:
            type: string
            example: email
            enum:
              - email
              - phone
              - externalId
              - uuid
              - clientId
        - name: identifierValue
          in: path
          description: The value of the selected identifier
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - operationId
                - clientDateTime
                - terminal
                - transactionMetric
                - finalValue
                - transactionItems
                - transactionAdditionalItems
              properties:
                operationId:
                  type: integer
                  description: Operation ID
                  nullable: false
                clientDateTime:
                  type: string
                  format: date-time
                  description: Operation's start time
                terminal:
                  type: object
                  description: Data about the terminal that is the transaction's source
                  required:
                    - storeId
                    - posId
                  properties:
                    storeId:
                      type: string
                      description: ID of the store
                    posId:
                      type: integer
                      description: ID of the point of sale (POS)
                transactionMetric:
                  type: object
                  description: Metadata of the transaction
                  required:
                    - posTransactionId
                    - beginDateTime
                    - globalTransactionId
                  properties:
                    posTransactionId:
                      type: integer
                      description: ID of the transaction within the POS
                    beginDateTime:
                      format: date-time
                      description: Time when the transaction starts
                    globalTransactionId:
                      type: string
                      description: Global transaction ID
                      nullable: true
                finalValue:
                  type: string
                  description: The total cost of all items in the basket, after discounts, including tax
                transactionItems:
                  type: array
                  items:
                    type: object
                    required:
                      - seqNo
                      - articleRef
                      - quantity
                      - evidPrice
                      - finalPrice
                      - finalValue
                    properties:
                      seqNo:
                        type: integer
                        description: Sequential number of transaction line item
                      articleRef:
                        type: string
                        description: Item's identifier in the product catalog
                      quantity:
                        type: string
                        description: Quantity of the product, provided to 3 decimal places
                        pattern: ^\d+(\.\d{1,3})?$
                        example: "3.231"
                      evidPrice:
                        type: string
                        description: Price per unit before discount, including tax
                        pattern: ^\d+\.\d{1,2}$
                        example: "34.23"
                      finalPrice:
                        type: string
                        description: Price per unit after discount, including tax
                        pattern: ^\d+\.\d{1,2}$
                        example: "30.23"
                      finalValue:
                        type: string
                        description: "The total cost of the product: `finalValue = finalPrice * quantity`"
                        pattern: ^\d+\.\d{1,2}$
                        example: "123.23"
                  description: Array of transaction items
                transactionAdditionalItems:
                  type: array
                  items:
                    type: object
                    required:
                      - seqNo
                      - type
                      - code
                    properties:
                      seqNo:
                        type: integer
                        description: Sequential number of additional item
                      type:
                        type: string
                        description: Type of the additional item
                        enum:
                          - COUPON
                      code:
                        type: string
                        description: Code of the additional item
                  description: Array of additional items in the transaction
                promotionsToActivate:
                  type: array
                  items:
                    required:
                      - key
                      - value
                      - pointsToUse
                    type: object
                    properties:
                      key:
                        type: string
                        description: Type of promotion identifier
                        enum:
                          - uuid
                          - code
                      value:
                        type: string
                        description: Value of the selected identifier
                      pointsToUse:
                        type: integer
                        minimum: 0
                        description: How many points should be converted to digital money and stored as ready to redeem in transactions in digital cashback promotions.
                    example:
                      key: code
                      value: 7893467834GG
                      pointsToUse: 100
                  description: Array of promotions to activate during the sale process
      responses:
        "200":
          description: Basket processed
          content:
            application/json:
              schema:
                type: object
                properties:
                  responseCode:
                    type: number
                    description: Response code. 0 is the same as HTTP 200. Other HTTP codes are sent as usual.
                  responseDescription:
                    type: string
                    description: Description of the response. Used for diagnostics and troubleshooting.
                  operationId:
                    type: integer
                    description: Operation ID
                    nullable: false
                  clientDateTime:
                    type: string
                    format: date-time
                    description: Operation's start time
                  terminal:
                    type: object
                    description: Data about the terminal that is the transaction's source
                    required:
                      - storeId
                      - posId
                    properties:
                      storeId:
                        type: string
                        description: ID of the store
                      posId:
                        type: integer
                        description: ID of the point of sale (POS)
                  transactionMetric:
                    type: object
                    description: Metadata of the transaction
                    required:
                      - posTransactionId
                      - beginDateTime
                      - globalTransactionId
                    properties:
                      posTransactionId:
                        type: integer
                        description: ID of the transaction within the POS
                      beginDateTime:
                        format: date-time
                        description: Time when the transaction starts
                      globalTransactionId:
                        type: string
                        description: Global transaction ID
                        nullable: true
                  finalValue:
                    type: string
                    description: The total cost of all items in the basket, after discounts, including tax
                  promotionErrors:
                    type: array
                    items:
                      type: array
                      description: Array of promotion errors
                      items:
                        type: object
                        description: Details of errors that occurred during promotion activation
                        properties:
                          key:
                            type: string
                            description: Type of promotion identifier
                            enum:
                              - uuid
                              - code
                          value:
                            type: string
                            description: Value of the selected identifier
                          error:
                            type: object
                            description: Details of an error
                            properties:
                              errorCode:
                                type: string
                                description: Error code which helps identify the issue. See [API error reference](https://hub.synerise.com/api-reference/errors.html).
                                example: ERR-001
                                nullable: true
                              message:
                                type: string
                                description: Error details
                            example:
                              message: Points not met limits for activation
                              name: PointsNotMetError
                              errorCode: ERR-042
                  transactionItems:
                    type: array
                    items:
                      type: object
                      required:
                        - seqNo
                        - articleRef
                        - quantity
                        - evidPrice
                        - finalPrice
                        - finalValue
                        - grantedDiscounts
                      properties:
                        seqNo:
                          type: integer
                          description: Sequential number of transaction line item
                        articleRef:
                          type: string
                          description: Item's identifier in the product catalog
                        quantity:
                          type: string
                          description: Quantity of the product, provided to 3 decimal places
                          pattern: ^\d+(\.\d{1,3})?$
                          example: "3.231"
                        evidPrice:
                          type: string
                          description: Price per unit before discount, including tax
                          pattern: ^\d+\.\d{1,2}$
                          example: "34.23"
                        finalPrice:
                          type: string
                          description: Price per unit after discount, including tax
                          pattern: ^\d+\.\d{1,2}$
                          example: "30.23"
                        finalValue:
                          type: string
                          description: "The total cost of the product: `finalValue = finalPrice * quantity`"
                          pattern: ^\d+\.\d{1,2}$
                          example: "123.23"
                        grantedDiscounts:
                          type: array
                          items:
                            type: object
                            required:
                              - source
                              - priceDiscount
                            properties:
                              source:
                                type: object
                                description: Source of the discount
                                required:
                                  - type
                                  - id
                                properties:
                                  type:
                                    type: integer
                                    description: |
                                      
                                      By default:

                                      - `1` for promotions from your own database

                                      - `2` for promotions from your Synerise Workspace
                                  id:
                                    type: string
                                    description: ID of the promotion in the source domain, for example a promotion code
                              priceDiscount:
                                type: string
                                description: The amount subtracted from `evidPrice`
                                pattern: ^\d+\.\d{1,2}$
                                example: "12.45"
                          description: Array of granted discounts
                    description: Array of processed transaction items
                  transactionAdditionalItem:
                    type: array
                    items:
                      type: object
                      required:
                        - seqNo
                        - type
                        - code
                      properties:
                        seqNo:
                          type: integer
                          description: Sequential number of additional item
                        type:
                          type: string
                          description: Type of the additional item
                          enum:
                            - COUPON
                        code:
                          type: string
                          description: Code of the additional item
                    description: Array of processed additional items, currently not used
                  transactionGrantReport:
                    type: array
                    description: Report of printouts related to the transaction, currently not used
                    items: {}
        "400":
          description: Request body invalid/malformed/missing elements
          content:
            application/json:
              schema:
                anyOf:
                  - type: object
                    title: JSON content issue
                    properties:
                      message:
                        type: string
                        description: Summary of the error
                      error:
                        description: Details of the error
                        anyOf:
                          - type: array
                            description: An array of objects with error details
                            items:
                              type: object
                              description: Details of an error
                              properties:
                                message:
                                  type: string
                                  description: Short description of the error
                                  example: Internal Error
                                additionalProperties:
                                  description: Additional information, if applicable
                          - type: string
                            description: Description of the error
                  - type: object
                    title: JSON structure issue
                    properties:
                      message:
                        type: string
                        description: Summary of the error
                      code:
                        type: string
                        description: String-type code of the error
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: integer
                    description: HTTP code of the problem
                  error:
                    type: string
                    description: Summary of the error
                  message:
                    type: string
                    description: Error details
                  timestamp:
                    type: string
                    description: Time when the error occurred
        "403":
          description: Forbidden
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: integer
                    description: HTTP code of the problem
                  error:
                    type: string
                    description: Summary of the error
                  message:
                    type: string
                    description: Error details
                  timestamp:
                    type: string
                    description: Time when the error occurred
      x-snr-doc-urls:
        - /api-reference/loyalty-and-engagement#tag/Promotions/operation/processSale_POST
      x-codeSamples:
        - lang: cURL
          label: cURL
          source: |-
            curl --request POST \
              --url https://api.synerise.com/v4/promotions/v2/sale/process-sale/email/%7BidentifierValue%7D \
              --header 'Authorization: Bearer REPLACE_BEARER_TOKEN' \
              --header 'content-type: application/json' \
              --data '{"operationId":0,"clientDateTime":"2019-08-24T14:15:22Z","terminal":{"storeId":"string","posId":0},"transactionMetric":{"posTransactionId":0,"beginDateTime":null,"globalTransactionId":"string"},"finalValue":"string","transactionItems":[{"seqNo":0,"articleRef":"string","quantity":"3.231","evidPrice":"34.23","finalPrice":"30.23","finalValue":"123.23"}],"transactionAdditionalItems":[{"seqNo":0,"type":"COUPON","code":"string"}],"promotionsToActivate":[{"key":"code","value":"7893467834GG","pointsToUse":100}]}'
        - lang: Python
          label: Python
          source: |-
            import http.client

            conn = http.client.HTTPSConnection("api.synerise.com")

            payload = "{\"operationId\":0,\"clientDateTime\":\"2019-08-24T14:15:22Z\",\"terminal\":{\"storeId\":\"string\",\"posId\":0},\"transactionMetric\":{\"posTransactionId\":0,\"beginDateTime\":null,\"globalTransactionId\":\"string\"},\"finalValue\":\"string\",\"transactionItems\":[{\"seqNo\":0,\"articleRef\":\"string\",\"quantity\":\"3.231\",\"evidPrice\":\"34.23\",\"finalPrice\":\"30.23\",\"finalValue\":\"123.23\"}],\"transactionAdditionalItems\":[{\"seqNo\":0,\"type\":\"COUPON\",\"code\":\"string\"}],\"promotionsToActivate\":[{\"key\":\"code\",\"value\":\"7893467834GG\",\"pointsToUse\":100}]}"

            headers = {
                'Authorization': "Bearer REPLACE_BEARER_TOKEN",
                'content-type': "application/json"
                }

            conn.request("POST", "/v4/promotions/v2/sale/process-sale/email/%7BidentifierValue%7D", payload, headers)

            res = conn.getresponse()
            data = res.read()

            print(data.decode("utf-8"))
        - lang: JavaScript
          label: JavaScript
          source: |-
            const data = JSON.stringify({
              "operationId": 0,
              "clientDateTime": "2019-08-24T14:15:22Z",
              "terminal": {
                "storeId": "string",
                "posId": 0
              },
              "transactionMetric": {
                "posTransactionId": 0,
                "beginDateTime": null,
                "globalTransactionId": "string"
              },
              "finalValue": "string",
              "transactionItems": [
                {
                  "seqNo": 0,
                  "articleRef": "string",
                  "quantity": "3.231",
                  "evidPrice": "34.23",
                  "finalPrice": "30.23",
                  "finalValue": "123.23"
                }
              ],
              "transactionAdditionalItems": [
                {
                  "seqNo": 0,
                  "type": "COUPON",
                  "code": "string"
                }
              ],
              "promotionsToActivate": [
                {
                  "key": "code",
                  "value": "7893467834GG",
                  "pointsToUse": 100
                }
              ]
            });

            const xhr = new XMLHttpRequest();
            xhr.withCredentials = true;

            xhr.addEventListener("readystatechange", function () {
              if (this.readyState === this.DONE) {
                console.log(this.responseText);
              }
            });

            xhr.open("POST", "https://api.synerise.com/v4/promotions/v2/sale/process-sale/email/%7BidentifierValue%7D");
            xhr.setRequestHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN");
            xhr.setRequestHeader("content-type", "application/json");

            xhr.send(data);
        - lang: Node.js
          label: Node.js
          source: |-
            const http = require("https");

            const options = {
              "method": "POST",
              "hostname": "api.synerise.com",
              "port": null,
              "path": "/v4/promotions/v2/sale/process-sale/email/%7BidentifierValue%7D",
              "headers": {
                "Authorization": "Bearer REPLACE_BEARER_TOKEN",
                "content-type": "application/json"
              }
            };

            const req = http.request(options, function (res) {
              const chunks = [];

              res.on("data", function (chunk) {
                chunks.push(chunk);
              });

              res.on("end", function () {
                const body = Buffer.concat(chunks);
                console.log(body.toString());
              });
            });

            req.write(JSON.stringify({
              operationId: 0,
              clientDateTime: '2019-08-24T14:15:22Z',
              terminal: {storeId: 'string', posId: 0},
              transactionMetric: {posTransactionId: 0, beginDateTime: null, globalTransactionId: 'string'},
              finalValue: 'string',
              transactionItems: [
                {
                  seqNo: 0,
                  articleRef: 'string',
                  quantity: '3.231',
                  evidPrice: '34.23',
                  finalPrice: '30.23',
                  finalValue: '123.23'
                }
              ],
              transactionAdditionalItems: [{seqNo: 0, type: 'COUPON', code: 'string'}],
              promotionsToActivate: [{key: 'code', value: '7893467834GG', pointsToUse: 100}]
            }));
            req.end();
        - lang: PHP
          label: PHP
          source: |-
            <?php

            $request = new HttpRequest();
            $request->setUrl('https://api.synerise.com/v4/promotions/v2/sale/process-sale/email/%7BidentifierValue%7D');
            $request->setMethod(HTTP_METH_POST);

            $request->setHeaders([
              'Authorization' => 'Bearer REPLACE_BEARER_TOKEN',
              'content-type' => 'application/json'
            ]);

            $request->setBody('{"operationId":0,"clientDateTime":"2019-08-24T14:15:22Z","terminal":{"storeId":"string","posId":0},"transactionMetric":{"posTransactionId":0,"beginDateTime":null,"globalTransactionId":"string"},"finalValue":"string","transactionItems":[{"seqNo":0,"articleRef":"string","quantity":"3.231","evidPrice":"34.23","finalPrice":"30.23","finalValue":"123.23"}],"transactionAdditionalItems":[{"seqNo":0,"type":"COUPON","code":"string"}],"promotionsToActivate":[{"key":"code","value":"7893467834GG","pointsToUse":100}]}');

            try {
              $response = $request->send();

              echo $response->getBody();
            } catch (HttpException $ex) {
              echo $ex;
            }
        - lang: Java
          label: Java
          source: |-
            HttpResponse<String> response = Unirest.post("https://api.synerise.com/v4/promotions/v2/sale/process-sale/email/%7BidentifierValue%7D")
              .header("Authorization", "Bearer REPLACE_BEARER_TOKEN")
              .header("content-type", "application/json")
              .body("{\"operationId\":0,\"clientDateTime\":\"2019-08-24T14:15:22Z\",\"terminal\":{\"storeId\":\"string\",\"posId\":0},\"transactionMetric\":{\"posTransactionId\":0,\"beginDateTime\":null,\"globalTransactionId\":\"string\"},\"finalValue\":\"string\",\"transactionItems\":[{\"seqNo\":0,\"articleRef\":\"string\",\"quantity\":\"3.231\",\"evidPrice\":\"34.23\",\"finalPrice\":\"30.23\",\"finalValue\":\"123.23\"}],\"transactionAdditionalItems\":[{\"seqNo\":0,\"type\":\"COUPON\",\"code\":\"string\"}],\"promotionsToActivate\":[{\"key\":\"code\",\"value\":\"7893467834GG\",\"pointsToUse\":100}]}")
              .asString();
servers:
  - description: Microsoft Azure EU
    url: https://api.synerise.com
  - description: Microsoft Azure USA
    url: https://api.azu.synerise.com
  - description: Google Cloud Platform
    url: https://api.geb.synerise.com
tags:
  - name: Promotions
components:
  securitySchemes:
    JWT:
      type: http
      scheme: bearer
      description: |-
        JWT Bearer token. The header looks like this: `Bearer {JWT}`

        Remember to include the space between 'Bearer' and the token.

        Generate a token via the **Authorization** endpoints.
```
