OCAPI JSONP 23.2

JSONP (JSON with padding) allows a browser page to request data from a server in a different domain. Normally, a Web API request returns a plain JSON document, which requires the client to parse the JSON document. There are some Browser JavaScript cases where it is much more efficient to respond with JavaScript code instead of with a JSON document. The response is directly evaluated by the JavaScript interpreter and is not parsed by a JSONParser. The response, in these cases, is merely a JSON document with a JavaScript function call wrapped around it.

The Open Commerce API offers the URL request parameter callback. The value of this parameter is the name of the JavaScript function that is wrapped around the JSON document.


REQUEST:
GET /dw/shop/v23_2/products/99225?client_id=[your_own_client_id]&pretty_print=true&callback=parseResponse HTTP/1.1
Host: example.com

RESPONSE:
HTTP/1.1 200 OK
Content-Length: 351
Content-Type: text/javascript;charset=UTF-8
X-Content-Type-Options: nosniff

/**/parseResponse({
  "_v" : "23.2",
  "brand" : "Apparelstore",
  "id" : "99225",
  "name" : "Boot Sauce™ Brown Cream"
})
X OCAPI versions 15.x and 16.x will be retired on March 31, 2021. For dates and more information, see the OCAPI versioning and deprecation policy and this Knowledge Article.