API - Create Coupon

Create Coupon

This API is used to create a coupon for a group by specifying the path to the group or id.

Path syntax is as follows:

Path = segment/segment/......

segment = * | {code: "group code"} | {name: "group name"}

Each segment can contain * (matches any group at that level), name of the group or code of the group. Path must result in single group otherwise the API will fail.

Example of Path

Path = {name:"Training"}/{name: "Corporate"}/{name: "Sales"}

Path = {name:"Training"}/{name: "Corporate"}/*

 

API Details

Signature of API call

connection.invokeApi(String uri, String realUserName, Map<String, String> requestParameters);

See details about invoking API in general

 

Parameter 1 - URI

couponService.do

 

Parameter 2 - UserName

Username of the site admin

 

Parameter 3 - Request Parameters

Name Value
dispatch createCoupon
xml true
authCode
Coupon name (optional)
type

Coupon type (required). Must be from one of the below values

- USAGE

- AMOUNT

- PERCENT

- TOTAL_AMOUNT

entityType

entityType should be set to one of the following values

- SITE (to create coupon that is valid for all items in the site)

- PROGRAM_SESSION (to create coupon that is valid for a program session)

- COURSE_SESSION (to create coupon that is valid for a course session)

- EVENT (to create coupon that is valid for an event)

- GROUP (to create coupon that is valid for everything available in a group)

entityId

Id of the above entity.

In case entityType is SITE, this value is optional. If not passed, current site id is assumed. In case of multi site enabled accounts, pass the value of any site id from your own account. You can also pass url of the site instead of Id in this parameter (if id is not known)

In case entityType is GROUP, ID or the path should be passed

valueCount number of times the coupon can be used 
valueAmount

numeric total discount amount value for coupon (if type is AMOUNT)

numeric total amount (credit) available via coupon (if type is TOTAL_AMOUNT)

valuePercent numeric % discount value for coupon (if type is PERCENT)
startDate Start date of the coupon (optional), represented as epoch time in milliseconds - number of milliseconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds
expDate
Expiration date of the coupon (optional), represented as epoch time in milliseconds - number of milliseconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds
ownerGroupId
ID or path of the authorized group which can use this coupon
setMembershipExpiration

Boolean (true | false)

If true - sets user's membership expiration same as coupon expiration.

addUserToCouponsGroup

Boolean (true | false)

If true - adds the user to coupon's authorized group if the user is not already a member

requireApproval

Boolean (true | false)

If true - usage will require coupon's authorized group admin to approve

previewAccessOnly

Boolean (true | false)

If true - the user will get only limited time access to course session / program session

comment Comments

 

Response

Response on successfully creating the coupon

HTTP Response Code = HttpServletResponse.SC_OK

Response XML

<response code="0">
   <msgs>
      <msg>
         <code>0219</code>
         <value>
            <![CDATA[Coupon Created Successfully]]>
         </value>
      </msg>
   </msgs>
</response>

 

Code Snippet

/* Check API Call for detail */

Map<String, String> parameters = new HashMap<String, String>();
populateMapForCouponCreation(parameters);
String result = connection.invokeApi("couponService.do", "adminusername", parameters);
System.out.println(result);
 
private void populateMapForCouponCreation(Map<String, String> parameters) {
    parameters.put("dispatch", "createCoupon");
    parameters.put("xml", String.valueOf(true));
    parameters.put("couponName", "partner1-free");
    parameters.put("type", "USAGE");
    parameters.put("entityType", "SITE");
    parameters.put("entityId", "yoursite.edubrite.com");
    parameters.put("valueCount", "999999");
    parameters.put("expDate", "1495163497116"); //always
    parameters.put("ownerGroupId
", "{name:\"Training\"}/{name: \"Corporate\"}/{name: \"Sales\"}");        
}

 


Rating: