---
title: Purchase Data
slug: apis/purchase-data
docTags: 
createdAt: 2024-06-25T00:32:49.338Z
---

:::ApiMethodV2
```json
{
  "tab": "examples",
  "url": "https://{{ Analytics_URL }}/analytics/productTracking",
  "name": "Reporting Single Order Data",
  "method": "GET",
  "request": {
    "pathParameters": [],
    "queryParameters": [
      {
        "kind": "required",
        "name": "klevu_apiKey",
        "type": "string",
        "description": "This is your Klevu JS API Key."
      },
      {
        "kind": "required",
        "name": "klevu_type",
        "type": "string",
        "description": "This is constant value. The value must be checkout."
      },
      {
        "kind": "required",
        "name": "klevu_productId",
        "type": "string",
        "description": "This is the Klevu ID of the clicked product. eg. 54321-12345."
      },
      {
        "kind": "required",
        "name": "klevu_productGroupId",
        "type": "string",
        "description": "This is the parent ID of the clicked product. eg. 54321. For compound products with a parent and multiple child/variant products, this is the common ID which ties the products together. For simple products, please specify the same as klevu_productId."
      },
      {
        "kind": "required",
        "name": "klevu_productVariantId",
        "type": "string",
        "description": "This is the child/variant ID of the clicked product. eg. 12345. For compound products with a parent and multiple child/variant products, this is the ID of the specific variant. For simple products, please specify the same as klevu_productId."
      },
      {
        "kind": "required",
        "name": "klevu_unit",
        "type": "Integer",
        "description": "This is the total quantity purchased. It must be an integer (e.g. 5)."
      },
      {
        "kind": "required",
        "name": "klevu_salePrice",
        "type": "Number",
        "description": "Product's sale price for one unit. You can supply decimal values. "
      },
      {
        "kind": "required",
        "name": "klevu_currency",
        "type": "string",
        "description": "Three digit currency code. e.g GBP, USD, EUR."
      },
      {
        "kind": "required",
        "name": "klevu_shopperIP",
        "type": "string",
        "description": "IP address of the shopper who bought the product(s). \n\n*If calling from javascript, this is an optional parameter."
      },
      {
        "name": "klevu_shopperIP_v4",
        "kind": "optional",
        "type": "string",
        "description": "IPv4 address of the shopper who purchased a product. ",
        "children": []
      },
      {
        "name": "klevu_shopperIP_v6",
        "kind": "optional",
        "type": "string",
        "description": "IPv6 address of the shopper who purchased a product. ",
        "children": []
      },
      {
        "name": "data_protection",
        "kind": "optional",
        "type": "Boolean",
        "description": "If set to false, Klevu's backend do not obtain the shoppers' IP address. The default value is true.",
        "children": []
      },
      {
        "name": "klevu_uuid",
        "kind": "optional",
        "type": "string",
        "description": "Universally unique identifier generated by Klevu, it can be also considered as session id. Please obtain UUID using end-point: https://docs.klevu.com/apis/uuid",
        "children": []
      },
      {
        "name": "klevu_country",
        "kind": "optional",
        "type": "string",
        "description": "2-digit country code of the shopper who purchased a product. Valid codes can be found at https://developers.google.com/hotels/hotel-prices/dev-guide/country-codes",
        "children": []
      },
      {
        "name": "klevu_city",
        "kind": "optional",
        "type": "string",
        "description": "City name of the shopper who purchased a product.",
        "children": []
      }
    ],
    "headerParameters": [],
    "bodyDataParameters": [],
    "formDataParameters": []
  },
  "results": {
    "languages": [
      {
        "id": "DdxomvWNISlr_Jx48gHQd",
        "code": "<data>\n    <response>SUCCESS</response>\n</data>",
        "language": "200",
        "customLabel": ""
      }
    ],
    "selectedLanguageId": "DdxomvWNISlr_Jx48gHQd"
  },
  "examples": {
    "languages": [
      {
        "id": "ewnRZCOKsK8s4PdjFvhyM",
        "code": "<?php\n\n$curl = curl_init();\n\ncurl_setopt_array($curl, array(\n  CURLOPT_URL => 'https://stats.ksearchnet.com/analytics/productTracking?klevu_apiKey=klevu-1234567890&klevu_type=checkout&klevu_productId=54321-12345&klevu_productGroupId=54321&klevu_productVariantId=12345&klevu_unit=2&klevu_salePrice=123.45&klevu_currency=GBP',\n  CURLOPT_RETURNTRANSFER => true,\n  CURLOPT_ENCODING => '',\n  CURLOPT_MAXREDIRS => 10,\n  CURLOPT_TIMEOUT => 0,\n  CURLOPT_FOLLOWLOCATION => true,\n  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n  CURLOPT_CUSTOMREQUEST => 'GET',\n));\n\n$response = curl_exec($curl);\n\ncurl_close($curl);\necho $response;\n",
        "language": "curl",
        "customLabel": ""
      },
      {
        "id": "EQqDeUhwCKDCWovOoWPGC",
        "code": "var request = require('request');\nvar options = {\n  'method': 'GET',\n  'url': 'https://stats.ksearchnet.com/analytics/productTracking?klevu_apiKey=klevu-1234567890&klevu_type=checkout&klevu_productId=54321-12345&klevu_productGroupId=54321&klevu_productVariantId=12345&klevu_unit=2&klevu_salePrice=123.45&klevu_currency=GBP',\n  'headers': {\n  }\n};\nrequest(options, function (error, response) {\n  if (error) throw new Error(error);\n  console.log(response.body);\n});\n",
        "language": "nodejs",
        "customLabel": ""
      },
      {
        "id": "8jgVxehuUIB8HJb3WWGYb",
        "code": "var xhr = new XMLHttpRequest();\nxhr.withCredentials = false;\n\nxhr.addEventListener(\"readystatechange\", function() {\n  if(this.readyState === 4) {\n    console.log(this.responseText);\n  }\n});\n\nxhr.open(\"GET\", \"https://stats.ksearchnet.com/analytics/productTracking?klevu_apiKey=klevu-1234567890&klevu_type=checkout&klevu_productId=54321-12345&klevu_productGroupId=54321&klevu_productVariantId=12345&klevu_unit=2&klevu_salePrice=123.45&klevu_currency=GBP\");\n\nxhr.send();",
        "language": "javascript",
        "customLabel": ""
      },
      {
        "id": "6DGdWEWXLComG0sNANahm",
        "code": "import requests\n\nurl = \"https://stats.ksearchnet.com/analytics/productTracking?klevu_apiKey=klevu-1234567890&klevu_type=checkout&klevu_productId=54321-12345&klevu_productGroupId=54321&klevu_productVariantId=12345&klevu_unit=2&klevu_salePrice=123.45&klevu_currency=GBP\"\n\npayload={}\nheaders = {}\n\nresponse = requests.request(\"GET\", url, headers=headers, data=payload)\n\nprint(response.text)\n",
        "language": "python",
        "customLabel": ""
      },
      {
        "id": "ZX8_wo0Tig8YCFpmpqeIo",
        "code": "require \"uri\"\nrequire \"net/http\"\n\nurl = URI(\"https://stats.ksearchnet.com/analytics/productTracking?klevu_apiKey=klevu-1234567890&klevu_type=checkout&klevu_productId=54321-12345&klevu_productGroupId=54321&klevu_productVariantId=12345&klevu_unit=2&klevu_salePrice=123.45&klevu_currency=GBP\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Get.new(url)\n\nresponse = https.request(request)\nputs response.read_body\n",
        "language": "ruby",
        "customLabel": ""
      }
    ],
    "selectedLanguageId": "ewnRZCOKsK8s4PdjFvhyM"
  },
  "description": "Use this API endpoint to submit the purchase data per product.\nThe request should be made once for each line item purchased.\n",
  "currentNewParameter": {
    "label": "Query Parameter",
    "value": "queryParameters"
  },
  "autoGeneratedAnchorSlug": "reporting-single-order-data",
  "legacyHash": "ApE2ZH_SYSTjaBS9NQ9Yr"
}
```
:::



:::ApiMethodV2
```json
{
  "tab": "examples",
  "url": "https://{{ Analytics_URL }}/analytics/collect",
  "name": "Reporting Multiple Order Data (JSON)",
  "method": "POST",
  "request": {
    "pathParameters": [],
    "queryParameters": [],
    "headerParameters": [],
    "bodyDataParameters": [
      {
        "kind": "required",
        "name": "event_version",
        "type": "String",
        "description": "The event version is used by Klevu's backend. The current version is 1.0.0"
      },
      {
        "kind": "required",
        "name": " event",
        "type": "string",
        "children": [],
        "description": "Define the type of event. For order, use a constant value order_purchase. "
      },
      {
        "kind": "required",
        "name": "event_apikey",
        "type": "string",
        "children": [],
        "description": "Your Klevu JS Api Key, eg. klevu-12345."
      },
      {
        "name": "event_timestamp_ms",
        "kind": "optional",
        "type": "Number",
        "description": "Event timestamp in milliseconds e.g. 1736256722349",
        "children": []
      },
      {
        "name": "user_profile",
        "kind": "required",
        "type": "Object",
        "description": "The json object that holds the user related information such as ip_address, email. ",
        "": "The json object that holds the user related information such as ip_address, email. ",
        "children": [
          {
            "name": "ip_address",
            "kind": "required",
            "type": "string",
            "description": "IP address of the shopper who purchased the product. \n"
          },
          {
            "name": "email",
            "kind": "optional",
            "type": "string",
            "description": "Email id of the shopper who purchased the product.\n"
          },
          {
            "name": "ip_address_v4",
            "kind": "optional",
            "type": "string",
            "description": "IPv4 address of the shopper who purchased a product."
          },
          {
            "name": "ip_address_v6",
            "kind": "optional",
            "type": "string",
            "description": "IPv6 address of the shopper who purchased products."
          },
          {
            "name": "data_protection",
            "kind": "optional",
            "type": "boolean",
            "description": "If set to false, Klevu's backend do not obtain the shoppers' IP address. The default value is true."
          },
          {
            "name": "klevu_uuid",
            "kind": "optional",
            "type": "string",
            "description": "Universally unique identifier generated by Klevu, it can be also considered as session id."
          },
          {
            "name": "klevu_country",
            "kind": "optional",
            "type": "string",
            "description": "2-digit country code of the shopper who purchased products. Valid codes can be found at https://developers.google.com/hotels/hotel-prices/dev-guide/country-codes"
          },
          {
            "name": "klevu_city",
            "kind": "optional",
            "type": "string",
            "description": "City name of the shopper who purchased products."
          }
        ],
        "schema": [
          {
            "name": "ip_address",
            "kind": "required",
            "type": "string",
            "description": "IP address of the shopper who purchased the product. \n"
          },
          {
            "name": "email",
            "kind": "optional",
            "type": "string",
            "description": "Email id of the shopper who purchased the product.\n"
          },
          {
            "name": "ip_address_v4",
            "kind": "optional",
            "type": "string",
            "description": "IPv4 address of the shopper who purchased a product."
          },
          {
            "name": "ip_address_v6",
            "kind": "optional",
            "type": "string",
            "description": "IPv6 address of the shopper who purchased products."
          },
          {
            "name": "data_protection",
            "kind": "optional",
            "type": "boolean",
            "description": "If set to false, Klevu's backend do not obtain the shoppers' IP address. The default value is true."
          },
          {
            "name": "klevu_uuid",
            "kind": "optional",
            "type": "string",
            "description": "Universally unique identifier generated by Klevu, it can be also considered as session id."
          },
          {
            "name": "klevu_country",
            "kind": "optional",
            "type": "string",
            "description": "2-digit country code of the shopper who purchased products. Valid codes can be found at https://developers.google.com/hotels/hotel-prices/dev-guide/country-codes"
          },
          {
            "name": "klevu_city",
            "kind": "optional",
            "type": "string",
            "description": "City name of the shopper who purchased products."
          }
        ]
      },
      {
        "kind": "required",
        "name": "items",
        "type": "Array",
        "children": [],
        "description": "Depending on the number of orders, the item array accepts single or more orders.  "
      },
      {
        "kind": "optional",
        "name": "order_id",
        "type": "string",
        "children": [],
        "description": "The unique identifier for your orders. "
      },
      {
        "kind": "optional",
        "name": "order_line_id",
        "type": "string",
        "children": [],
        "description": "The unique identifier for reference to a line on an order within the database. "
      },
      {
        "kind": "required",
        "name": "item_name",
        "type": "string",
        "children": [],
        "description": "The name of the product."
      },
      {
        "kind": "required",
        "name": "item_id",
        "type": "string",
        "children": [],
        "description": "The full ID of the product. eg. 12345-54321. This will match the unique value used in your data sync process with Klevu. For compound products consisting of a child/variant and a parent, this is usually parentId-childId."
      },
      {
        "kind": "required",
        "name": "item_group_id",
        "type": "string",
        "children": [],
        "description": "The Parent ID of the product. eg. 12345. For compound products consisting of a child/variant and a parent, please specify the ID of the parent. For simple products, please re-use the same value as item_id"
      },
      {
        "kind": "required",
        "name": "item_variant_id",
        "type": "string",
        "children": [],
        "description": "The Child ID of the product.eg. 54321. Please specify the ID of the child/variant product. For simple products, please re-use the same value as item_id."
      },
      {
        "kind": "required",
        "name": "unit_price",
        "type": "Number",
        "children": [],
        "description": "The final selling price of the product, for example 123.45"
      },
      {
        "kind": "required",
        "name": "currency",
        "type": "string",
        "children": [],
        "description": "The currency of the above price, eg. USD."
      },
      {
        "kind": "optional",
        "name": "units",
        "type": "Integer",
        "children": [],
        "description": "The number of units sold for a product. In case if the parameter is mising, the default value will be 1 "
      }
    ],
    "formDataParameters": []
  },
  "results": {
    "languages": [
      {
        "id": "FI7DVhQck3_P270nihiHK",
        "code": "",
        "language": "200",
        "customLabel": ""
      }
    ],
    "selectedLanguageId": "FI7DVhQck3_P270nihiHK"
  },
  "examples": {
    "languages": [
      {
        "id": "DjsRpQrxfQsrjFNj4P-wd",
        "code": "<?php\n\n$curl = curl_init();\n\ncurl_setopt_array($curl, array(\n  CURLOPT_URL => 'https://stats.ksearchnet.com/analytics/collect',\n  CURLOPT_RETURNTRANSFER => true,\n  CURLOPT_ENCODING => '',\n  CURLOPT_MAXREDIRS => 10,\n  CURLOPT_TIMEOUT => 0,\n  CURLOPT_FOLLOWLOCATION => true,\n  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n  CURLOPT_CUSTOMREQUEST => 'POST',\n  CURLOPT_POSTFIELDS =>'[\n    {\n        \"event\": \"order_purchase\",\n        \"event_apikey\": \"klevu-12345\",\n        \"user_profile\" : {\n           \"ip_address\":\"111.11.11.1\",\n           \"email\":\"user@klevu.com\"\n        },\n        \"event_version\": \"1.0.0\",\n        \"event_data\": {\n            \"items\": [\n                {\n                    \"order_id\": \"1223434\",\n                    \"order_line_id\": \"ABC-12343\",\n                    \"item_name\": \"45RU,800x1070,N-Type,D,NoS,CM,WH,EA\",\n                    \"item_id\": \"75882\",\n                    \"item_group_id\": \"75882\",\n                    \"item_variant_id\": \"75882\",\n                    \"unit_price\": 6033.42,\n                    \"currency\": \"USD\",\n                    \"units\": 2\n                },\n                {\n                    \"order_id\": \"1223435\",\n                    \"order_line_id\": \"ABC-12344\",\n                    \"item_name\": \"NoS,CM,WH,EA\",\n                    \"item_id\": \"75883\",\n                    \"item_group_id\": \"75883\",\n                    \"item_variant_id\": \"75883\",\n                    \"unit_price\": 6033.42,\n                    \"currency\": \"US\",\n                    \"units\": 1\n                }\n            ]\n        }\n    }\n]',\n  CURLOPT_HTTPHEADER => array(\n    'Content-Type: application/json'\n  ),\n));\n\n$response = curl_exec($curl);\n\ncurl_close($curl);\necho $response;",
        "language": "php",
        "customLabel": ""
      },
      {
        "id": "EDjoAAR2ZByzaLdipyefN",
        "code": "// WARNING: For POST requests, body is set to null by browsers.\nvar data = JSON.stringify([\n  {\n    \"event\": \"order_purchase\",\n    \"event_apikey\": \"klevu-12345\",\n    \"user_profile\" : {\n           \"ip_address\":\"111.11.11.1\",\n           \"email\":\"user@klevu.com\"\n    },\n    \"event_version\": \"1.0.0\",\n    \"event_data\": {\n      \"items\": [\n        {\n          \"order_id\": \"1223434\",\n          \"order_line_id\": \"ABC-12343\",\n          \"item_name\": \"45RU,800x1070,N-Type,D,NoS,CM,WH,EA\",\n          \"item_id\": \"75882\",\n          \"item_group_id\": \"75882\",\n          \"item_variant_id\": \"75882\",\n          \"unit_price\": 6033.42,\n          \"currency\": \"CAD\",\n          \"units\": 2\n        }\n      ]\n    }\n  }\n]);\n\nvar xhr = new XMLHttpRequest();\nxhr.withCredentials = false;\n\nxhr.addEventListener(\"readystatechange\", function() {\n  if(this.readyState === 4) {\n    console.log(this.responseText);\n  }\n});\n\nxhr.open(\"POST\", \"https://stats.ksearchnet.com/analytics/collect\");\nxhr.setRequestHeader(\"Content-Type\", \"application/json\");\n\nxhr.send(data);",
        "language": "javascript",
        "customLabel": ""
      },
      {
        "id": "ZZuMafHLxj_2bRMNg3sSL",
        "code": "OkHttpClient client = new OkHttpClient().newBuilder()\n  .build();\nMediaType mediaType = MediaType.parse(\"application/json\");\nRequestBody body = RequestBody.create(mediaType, \"[\\n    {\\n        \\\"event\\\": \\\"order_purchase\\\",\\n        \\\"event_apikey\\\": \\\"klevu-12345\\\",\\n        \\\"event_version\\\": \\\"1.0.0\\\",\\n        \\\"event_data\\\": {\\n            \\\"items\\\": [\\n                {\\n                    \\\"order_id\\\": \\\"1223434\\\",\\n                    \\\"order_line_id\\\": \\\"ABC-12343\\\",\\n                    \\\"item_name\\\": \\\"45RU,800x1070,N-Type,D,NoS,CM,WH,EA\\\",\\n                    \\\"item_id\\\": \\\"75882\\\",\\n                    \\\"item_group_id\\\": \\\"75882\\\",\\n                    \\\"item_variant_id\\\": \\\"75882\\\",\\n                    \\\"unit_price\\\": 6033.42,\\n                    \\\"currency\\\": \\\"CAD\\\",\\n                    \\\"units\\\": 2\\n                }\\n            ]\\n        }\\n    }\\n]\");\nRequest request = new Request.Builder()\n  .url(\"https://stats.ksearchnet.com/analytics/collect\")\n  .method(\"POST\", body)\n  .addHeader(\"Content-Type\", \"application/json\")\n  .build();\nResponse response = client.newCall(request).execute();",
        "language": "java",
        "customLabel": ""
      },
      {
        "id": "d8aE_l0VU6R3vBKtka0iZ",
        "code": "var request = require('request');\nvar options = {\n  'method': 'POST',\n  'url': 'https://stats.ksearchnet.com/analytics/collect',\n  'headers': {\n    'Content-Type': 'application/json'\n  },\n  body: JSON.stringify([\n    {\n      \"event\": \"order_purchase\",\n      \"event_apikey\": \"klevu-1234\",\n      \"user_profile\" : {\n           \"ip_address\":\"111.11.11.1\",\n           \"email\":\"user@klevu.com\"\n      },\n      \"event_version\": \"1.0.0\",\n      \"event_data\": {\n        \"items\": [\n          {\n            \"order_id\": \"1223434\",\n            \"order_line_id\": \"ABC-12343\",\n            \"item_name\": \"45RU,800x1070,N-Type,D,NoS,CM,WH,EA\",\n            \"item_id\": \"75882\",\n            \"item_group_id\": \"75882\",\n            \"item_variant_id\": \"75882\",\n            \"unit_price\": 6033.42,\n            \"currency\": \"CAD\",\n            \"units\": 2\n          }\n        ]\n      }\n    }\n  ])\n\n};\nrequest(options, function (error, response) {\n  if (error) throw new Error(error);\n  console.log(response.body);\n});\n",
        "language": "nodejs",
        "customLabel": ""
      }
    ],
    "selectedLanguageId": "DjsRpQrxfQsrjFNj4P-wd"
  },
  "description": "The end-point is used for reporting multiple orders in batch.",
  "currentNewParameter": {
    "label": "Body Parameter",
    "value": "bodyDataParameters"
  },
  "autoGeneratedAnchorSlug": "reporting-multiple-order-data-json",
  "legacyHash": "1mbNqPgyf_8tnxUqaldk8"
}
```
:::



