Discount codes

    List the discount codes in a site

    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
      • 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)
    • createDate - discount code's creation date (dateTime)
    • lastUpdateDate - discount code's last update 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/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": [
        {
          "id": 264,
          "siteId": 146985,
          "discountType": 1,
          "code": "discount1",
          "description": "discount1",
          "discountPercentageOrFixedAmount": 0.25,
          "discountThreshold": -1,
          "expireAfterXUses": -1,
          "releaseDate": "2011-01-11T23:00:00",
          "expiryDate": "9998-12-31T15:00:00",
    	  "createDate": "2011-01-11T23:00:00",
    	  "lastUpdateDate": "2011-01-11T23:00:00",
          "enabled": true
        },
        {
          "id": 322,
          "siteId": 146985,
          "discountType": 2,
          "code": "dsc12",
          "description": "discount 12",
          "discountPercentageOrFixedAmount": 12,
          "discountThreshold": -1,
          "expireAfterXUses": -1,
          "releaseDate": "2011-03-03T23:00:00",
          "expiryDate": "9998-12-31T15:00:00",
    	  "createDate": "2011-01-11T23:00:00",
    	  "lastUpdateDate": "2011-01-11T23:00:00",
          "enabled": true
        }
      ],
      "totalItemsCount": 2,
      "skip": 0,
      "limit": 10
    }

    Get a discount code's attributes

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

    Response

    Displays the details for the discount code as a JSON object

    • 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)
    • createDate - discount code's creation date (dateTime)
    • lastUpdateDate - discount code's last update date (dateTime)
    • enabled - whether the discount code is enabled or not (boolean)

    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/discountcodes/146985",
        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

    {
      "id": 322,
      "siteId": 146985,
      "discountType": 2,
      "code": "dsc12",
      "description": "discount 12",
      "discountPercentageOrFixedAmount": 12,
      "discountThreshold": -1,
      "expireAfterXUses": -1,
      "releaseDate": "2011-03-03T23:00:00",
      "expiryDate": "9998-12-31T15:00:00",
      "createDate": "2011-01-11T23:00:00",
      "lastUpdateDate": "2011-01-11T23:00:00",
      "enabled": true
    }

    Create a discount code

    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/discountcodes
      • 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 "201 created" if the discount code was successfully created.

    Here are the parameters you can use when creating a discount code:

    • 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)
    • createDate - discount code's creation date (dateTime)
    • lastUpdateDate - discount code's last update date (dateTime)
    • enabled - whether the discount code is enabled or not (boolean)

    Sample code

    var access_token = BCAPI.Helper.Site.getAccessToken();
    var request = $.ajax({
    	url: "/webresources/api/v3/sites/current/discountcodes",
        processData: false,
        data: JSON.stringify({
    "discountType": 1,
    "code": "DC1093",
    "description": "Discount for Electronics",
    "discountPercentageOrFixedAmount": 0.5
    }), 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); })

    Update an existing discount code

    Request

    • Method: PUT
    • 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/discountcodes/[discount_code_ID]
      • 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 discount code was successfully modified.

    Here are the parameters you can use when updating a discount code:

    • 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)
    • createDate - discount code's creation date (dateTime)
    • lastUpdateDate - discount code's last update date (dateTime)
    • enabled - whether the discount code is enabled or not (boolean)

    Sample code

    var access_token = BCAPI.Helper.Site.getAccessToken();
    var request = $.ajax({
        url: "/webresources/api/v3/sites/current/discountcodes/17339",
        processData: false,
        data: JSON.stringify({
    "code": "DC1093-extended",
    "discountPercentageOrFixedAmount": 0.8,
    "expiryDate":"2016-01-11T23:00:00"
    }), type: "PUT", 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); })

    Delete a discount code

    This section details the endpoints you can use to delete a discount code.

    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.
    • Path: /webresources/api/v3/sites/current/discountcodes/[discount_code_ID]
      • 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 discount code was successfully deleted.


    Sample code

    var access_token = BCAPI.Helper.Site.getAccessToken();
    var request = $.ajax({
        url: "/webresources/api/v3/sites/current/discountcodes/17339",
        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);
    })