Skip to content

Campaign and Coupon Maintenance

Arcadier edited this page Sep 12, 2019 · 2 revisions

Adding Campaigns and Coupons


Screenshot-85

Authorization - Admin token
GET /api/v2/plugins/{PackageID}/custom-tables/Campaign/rows


POST /api/v2/plugins/{PackageID}/custom-tables/Campaign/rows

Save Campaign details to Campaign Custom Table

Request Body
$campaign_details = array('CampaignName' => $campaign_name, 'LastUpdated' => $dates);
$url = $baseUrl . '/api/v2/plugins/'. getPackageID() .'/custom-tables/Campaign/rows';
$result = callAPI("POST",$admin_token['access_token'], $url, $campaign_details);
Get the generated campaign ID
$campaign_id = $result['Id'];
Save the coupon details to Coupon Custom Table
$coupon_details = array('CouponCode' => $coupon_code, 'isLimited' => $isLimited, 'isEnabled' => $isEnabled, 'MaxRedeem' => $max_redeem, 'Quantity'=> '0','DiscountValue' => $discount_value,'CampaignId'=> $campaign_id);
3. Save the Coupon details along with the fetched campaign ID
$url = $baseUrl . '/api/v2/plugins/'. getPackageID() .'/custom-tables/Coupon/rows';
$result = callAPI("POST",$admin_token['access_token'], $url, $coupon_details);

Deleting Campaigns / Coupons

DELETE '/api/v2/plugins/{PackageID}/custom-tables/Coupon/rows/{couponid}


Query for the coupon ID with parameter of campaign ID
$coupon_details = array(array('Name' => 'CampaignId', 'Value' => $campaign_id));
$url = $baseUrl . '/api/v2/plugins/'. getPackageID() .'/custom-tables/Coupon';
$couponDetails = callAPI("POST", $admin_token['access_token'], $url, $coupon_details);
$couponid = $couponDetails['Records'][0]['Id'];
Delete Coupon and Campaign with parameter of each ID.
$url = $baseUrl . '/api/v2/plugins/'. getPackageID() .'/custom-tables/Coupon/rows/'.$couponid;
$result = callAPI("DELETE",$admin_token['access_token'], $url);
$url = $baseUrl . '/api/v2/plugins/'. getPackageID() .'/custom-tables/Campaign/rows/'.$campaign_id;
$result = callAPI("DELETE",$admin_token['access_token'], $url);

Editing Campaign / Coupons

Authorization - Admin token
PUT '/api/v2/plugins/{PackageID}/custom-tables/Coupon/rows/{couponid}


$coupon_details = array('CouponCode' => $coupon_code, 'isLimited' => $isLimited, 'isEnabled' => $isEnabled, 'MaxRedeem' => $max_redeem, 'DiscountValue' => $discount_value);
$url = $baseUrl . '/api/v2/plugins/'. getPackageID() .'/custom-tables/Coupon/rows/'. $coupon_id;
$result = callAPI("PUT",$admin_token['access_token'], $url, $coupon_details);
error_log(json_encode($result));

$campaign_details = array('CampaignName' => $campaign_name);
$url = $baseUrl . '/api/v2/plugins/'. getPackageID() .'/custom-tables/Campaign/rows/'. $campaign_id;
$result = callAPI("PUT",$admin_token['access_token'], $url, $campaign_details);

Searching Coupon


Authorization - Admin token
POST '/api/v2/plugins/{PackageID}/custom-tables/Coupon/rows/{couponid}
$coupon_details = array(array('Name' => 'Id', 'Value' => $coupon_id));
$url = $baseUrl . '/api/v2/plugins/'. getPackageID() .'/custom-tables/Coupon';
$couponDetails = callAPI("POST", $admin_token['access_token'], $url, $coupon_details);