OCAPI JSONP

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’s much more efficient to respond with JavaScript code instead of with a JSON document. The response is directly evaluated by the JavaScript interpreter and isn’t 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.

1REQUEST:
2GET /dw/shop/v24_5/products/99225?client_id=[your_own_client_id]&pretty_print=true&callback=parseResponse HTTP/1.1
3Host: example.com
4
5RESPONSE:
6HTTP/1.1 200 OK
7Content-Length: 351
8Content-Type: text/javascript;charset=UTF-8
9X-Content-Type-Options: nosniff
10
11/**/parseResponse({
12  "_v" : "24.5",
13  "brand" : "Apparelstore",
14  "id" : "99225",
15  "name" : "Boot Sauce™ Brown Cream"
16})

Attention!

The Open Commerce API (OCAPI) is now deprecated. The provisions described in our versioning and deprecation policy fully apply. For all new projects and major refactoring work, use B2C Commerce API (SCAPI) as the default REST API. For additional details, refer to Why Use SCAPI Instead of OCAPI.

DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!