Discount codes and catalogs

    List the catalogs a discount code is applied to

    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/discountcodes/[discount_code_ID]/catalogues
      • Alternatively, use siteID instead of 'current'
    • Authorization header: This should contain the authorization token. Here is how to obtain the token.

    Response

    You can output additional fields to those listed above as default, see the API v3 Discovery APP for additional details.

    An array of the first 10 catalogs the discount code is applied to.


    Sample code

    var access_token = BCAPI.Helper.Site.getAccessToken();
    var request = $.ajax({
        url: "/webresources/api/v3/sites/current/discountcodes/3309/catalogs",
        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": [
        {
          "discountCodeId": 17339,
          "catalogueId": 591,
          "siteId": 146985,
          "catalogue": {
            "catalogueId": 591,
            "siteId": 146985,
            "parentId": 88,
            "templateId": -2,
            "roleId": 14075,
            "displayTypeId": 1,
            "weight": null,
            "name": "Biographies",
            "title": "",
            "description": "// Biography catalog description is here //",
            "image": "/Images/productimages/books/biographies/mylife_small.jpg",
            "releaseDate": "2005-08-24T00:00:00",
            "expiryDate": "9998-12-31T15:00:00",
            "notify": null,
            "useFriendlyUrl": true,
            "excludeFromFeed": false,
            "enabled": true,
            "deleted": false,
            "minPrice": 0,
            "maxPrice": 1000,
            "priceSlots": 5,
            "productsStatsXml": "3000100000007000000200000030000110202100",
            "reIndex": false
          }
        },
        {
          "discountCodeId": 17339,
          "catalogueId": 593,
          "siteId": 146985,
          "catalogue": {
            "catalogueId": 593,
            "siteId": 146985,
            "parentId": 88,
            "templateId": -2,
            "roleId": 14075,
            "displayTypeId": 1,
            "weight": null,
            "name": "Business",
            "title": null,
            "description": "",
            "image": "/Images/productimages/books/business/marketing_small.jpg",
            "releaseDate": "2005-08-24T17:00:00",
            "expiryDate": "9998-12-31T15:00:00",
            "notify": null,
            "useFriendlyUrl": true,
            "excludeFromFeed": false,
            "enabled": true,
            "deleted": false,
            "minPrice": 0,
            "maxPrice": 1000,
            "priceSlots": 5,
            "productsStatsXml": "280090000007000000200000030000110202100",
            "reIndex": false
          }
        }
      ],
      "totalItemsCount": 2,
      "skip": 0,
      "limit": 10
    }

    Apply a discount code to a catalog or catalogs

    Request

    • Method: POST
    • Version: v3
    • 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/[discount_code_ID]/catalogues
      • Alternatively, use siteID instead of 'current'
    • Authorization header: This should contain the authorization token. Here is how to obtain the token.

    Note: If the discount code type is 3 (Free shipping) it cannot be applied to a catalog.

    Response

    The response should be "204 no content" if the discount code was successfully applied to the catalog.


    Sample code

    var access_token = BCAPI.Helper.Site.getAccessToken();
    var request = $.ajax({
        url: "/webresources/api/v3/sites/current/discountcodes/65460/catalogs",
        data: JSON.stringify({
            "items": [{
                "catalogueId": 25481
            }, {
                "catalogueId": 25482
            }]
        }),
            type:   "POST",
        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);
    })

    Note: If the discountCode has the discountType equal to 3, then you can't assign a catalogue to it.


    Remove the discount code from a catalog or catalogs

    Request

    • Method: DELETE
    • Version: v3
    • 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.a
    • Path: /webresources/api/v3/sites/current/discountcodes/[discount_code_ID]/catalogues?items=[{"discountCodeId":discountCodeId,"catalogueId":catalogueId}]"
      • Alternatively, use siteID instead of 'current'
    • Authorization header: This should contain the authorization token. Here is how to obtain the token.

    Response

    The response should be "204 no content" if the catalogues were successfully removed from list of catalogues discounted with this particular discount code.


    Sample code

    var access_token = BCAPI.Helper.Site.getAccessToken();
    var  request = $.ajax({    
      url: "/webresources/api/v3/sites/current/discountcodes/6188/catalogs?items=[{'catalogueId':25481},{'catalogueId':25482}]",
      type:   "DELETE",
      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);
    })