Related products

    Get all related products for a product

    Request

    • Method: GET
    • Version: v3, this API call supports additional sort and filter mechanisms as well as retrieving only a sub-set of fields

      Note: In order to access the v3 API endpoints please make sure you have enabled the new rendering engine.

    • Server: https://[app key here]-[site_ID here]-apps.worldsecuresystems.com. Take a look at the Authorize your API calls document for more info on how this URL is formed.
      • Note: When building apps always use relative request URLs. Do not use the "full" URL above because you might have problems running your app on a different site as the site_ID parameter will be different.
    • Path: /webresources/api/v3/sites/current/products/[product_ID]/relatedproducts
      • Alternatively, use siteID instead of 'current'
    • Authorization header: This should contain the authorization token. Here is how to obtain the token.

    Response

    An array of the first 10 variations; each object has the following properties:

    • productId - product ID (number)
    • relatedProductId - related product's ID (number)
    • siteId - site ID (number)
    • relatedProduct - related product's object - full list in Products API page (object)

    Accepts and returns JSON as Content-Type.


    Sample request

    var access_token = BCAPI.Helper.Site.getAccessToken();
    var request = $.ajax({
        url: "/webresources/api/v3/sites/current/products/6710934/relatedproducts",
        type: "GET",
        connection: "keep-alive",    
        contentType: "application/json",
        headers: {
            "Authorization": $.cookie('access_token')
        }
    });
    request.done(function (msg) {
        console.log(msg);
    });
    request.fail(function (jqXHR) {
        console.log("Request failed.");
        console.log("Error code: " + jqXHR.status);
        console.log("Error text: " + jqXHR.statusText);
        console.log("Response text: " + jqXHR.responseText);
    });

    Sample response

    {
      "items": [
        {
          "productId": 6710934,
          "relatedProductId": 6710935,
          "siteId": 1767665,
          "relatedProduct": {
            "id": 6710935,
            "siteId": 1767665,
            "name": "Item 2",
            ...
          }
        },
        {
          "productId": 6710934,
          "relatedProductId": 6710936,
          "siteId": 1767665,
          "relatedProduct": {
            "id": 6710936,
            "siteId": 1767665,
            "name": "Item 3",
            ...
          }
        },
        {
          "productId": 6710934,
          "relatedProductId": 6710937,
          "siteId": 1767665,
          "relatedProduct": {
            "id": 6710937,
            "siteId": 1767665,
            "name": "Item 4",
            ...
          }
        },
        {
          "productId": 6710934,
          "relatedProductId": 6710938,
          "siteId": 1767665,
          "relatedProduct": {
            "id": 6710938,
            "siteId": 1767665,
            "name": "Item 5",
            ...
          }
        }
      ],
      "totalItemsCount": 4,
      "skip": 0,
      "limit": 10
    

    Add a related product to a product

    Request

    • Method: POST
    • Version: v3, this API call supports additional sort and filter mechanisms as well as retrieving only a sub-set of fields

      Note: In order to access the v3 API endpoints please make sure you have enabled the new rendering engine.

    • Server: https://[app key here]-[site_ID here]-apps.worldsecuresystems.com. Take a look at the Authorize your API calls document for more info on how this URL is formed.
      • Note: When building apps always use relative request URLs. Do not use the "full" URL above because you might have problems running your app on a different site as the site_ID parameter will be different.
    • Path: /webresources/api/v3/sites/current/products/[product_ID]/relatedproducts
      • Alternatively, use siteID instead of 'current'
    • Authorization header: This should contain the authorization token. Here is how to obtain the token.

    Parameters

    • relatedProductId - the product's ID to be related (numeric)

    Response

    Returns an empty body if successful or a detailed error message.

    Accepts and returns JSON as Content-Type.

    Response:

    HTTP/1.1 204 No Content

    Sample request

    var access_token = BCAPI.Helper.Site.getAccessToken();
    
    var request = $.ajax({
        url: "/webresources/api/v3/sites/current/products/951888/relatedproducts",
        type: "POST",
        connection: "keep-alive",    
    	contentType: "application/json",headers: {
            "Authorization": $.cookie('access_token')
        },
        processData: false,
        data: JSON.stringify({
            "items": [
            {	"relatedProductId": 951894
            }]
        })
    });
    request.done(function (msg) {
        console.log(msg);
    })
    request.fail(function (jqXHR) {
        console.log("Request failed.");
        console.log("Error code: " + jqXHR.status);
        console.log("Error text: " + jqXHR.statusText);
        console.log("Response text: " + jqXHR.responseText);
    })

    Remove related product from a product

    Request

    • Method: DELETE
    • Version: v3, this API call supports additional sort and filter mechanisms as well as retrieving only a sub-set of fields

      Note: In order to access the v3 API endpoints please make sure you have enabled the new rendering engine.

    • Server: https://[app key here]-[site_ID here]-apps.worldsecuresystems.com. Take a look at the Authorize your API calls document for more info on how this URL is formed.
      • Note: When building apps always use relative request URLs. Do not use the "full" URL above because you might have problems running your app on a different site as the site_ID parameter will be different.
    • Path: /webresources/api/v3/sites/current/products/[product_ID]/relatedproducts?items={"relatedProductId":[related_product_ID]}]
      • Alternatively, use siteID instead of 'current'
    • Authorization header: This should contain the authorization token. Here is how to obtain the token.

    Response

    Returns an empty body if successful or a detailed error message.


    Request:

    DELETE /webresources/api/v3/sites/current/products/955809/relatedproducts?items={"relatedProductId":951894}] HTTPS/1.1
    Authorization: 14f87f21c5ea4830a06a6314a8aad82b45bc61dc08f24a0fb55599cea83ca811
    Connection: keep-alive
    Content-Type: application/json
    

    Response:

    HTTP/1.1 204 NO CONTENT

    Sample request

    var access_token = BCAPI.Helper.Site.getAccessToken();
    
    var request = $.ajax({
        url: "/webresources/api/v3/sites/current/products/955809/relatedproducts?items={"relatedProductId":951894}]",
        type: "DELETE
        connection: "keep-alive",    
    	contentType: "application/json",headers: {
            "Authorization": $.cookie('access_token')
        }
    });
    request.done(function (msg) {
        console.log(msg);
    })
    request.fail(function (jqXHR) {
        console.log("Request failed.");
        console.log("Error code: " + jqXHR.status);
        console.log("Error text: " + jqXHR.statusText);
        console.log("Response text: " + jqXHR.responseText);
    })