Catalogs and discount codes

    List the discount codes applied to a catalog

    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/catalogs/[catalog_ID]/discountcodes
      • 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 discount codes; each object has the following properties:

    • id - the id of the discount code (integer)
    • siteId - the id of the site (integer)
    • discountType - the type of the discount code (integer)
      • 1 - Percentage of Order
      • 2 - Fixed Dollar Amount
      • 3 - Free Shipping
    • code - the discount code's code(string)
    • description - the discount code's description (string)
    • discountPercentageOrFixedAmount - if the discount type is "1" this represents the percentage to be discounted. If the discount type is 1 or 2 this value is -1 (numeric)
    • discountThreshold - only apply this discount if the order's value is over this threshold (integer)
    • expireAfterXUses - the number of uses the discount code expires after (string)
    • releaseDate - the release date (dateTime)
    • expiryDate - the expiry date (dateTime)
    • enabled - whether the discount code is enabled or not (boolean)

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

    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/catalogs/25479/discountcodes",
        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": 64036,
          "catalogueId": 25481,
          "siteId": 246884,
          "discountCode": {
            "id": 64036,
            "siteId": 246884,
            "discountType": 2,
            "code": "CHR-1235",
            "description": "Christmas discount code",
            "discountPercentageOrFixedAmount": 10,
            "discountThreshold": -1,
            "expireAfterXUses": -1,
            "releaseDate": "2014-11-23T23:00:00",
            "expiryDate": "2014-12-30T23:00:00",
            "enabled": true
          }
        }
      ],
      "totalItemsCount": 1,
      "skip": 0,
      "limit": 10
    }

    Remove the discount code from a catalog

    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/catalogs/[catalog_ID]/discountcodes?items=[{'discountCodeId':discountCodeID_1, "catalogueId":catalogueId_2}]
      • 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/catalogs/25481/discountcodes?items=[{"discountCodeId":65460,"catalogueId":25481}]",
        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); })