Jump to content

FlamesRunner

Members
  • Posts

    3
  • Joined

  • Last visited

FlamesRunner's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Turns out I needed to encapsulate the array data with another keyed array called "vars." For anyone who stumbles on this in the future, the following code will work: <?php require_once "blesta_api.php"; require_once "blesta_response.php"; $user = "..."; $key = "..."; $url = "https://(snipped)/api"; $api = new BlestaApi($url, $user, $key); $code = bin2hex(openssl_random_pseudo_bytes(5)); $coupon_data = array( "vars" => array( "code" => $code, "company_id" => 1, "used_qty" => 0, "max_qty" => 1, "start_date" => date("c"), "end_date" => "2025-12-30 11:59:59 UTC", "status" => "active", "recurring" => 0, "limit_recurring" => 0, "packages" => array(1, 2), "amounts" => array( "currency" => "USD", "amount" => 50, "type" => "percent" ) ) ); $response = $api->post("coupons", "add", $coupon_data); ?>
  2. @Tyson I appreciate the reply. I figured out what was causing the empty responses; turns out the URL requires a trailing slash. I don't believe there's anything wrong with my system, as I was able to obtain information about users, etc (using $response = $api->get("users", "get", array("user_id" => 1)); for example works and responds with data). However, when I attempt to use the coupon API to add something, I now get the following error: object(stdClass)#5 (1) { ["error"]=> object(stdClass)#6 (2) { ["message"]=> string(28) "An unexpected error occured." ["response"]=> string(52) "Internal error: Failed to retrieve the default value" } } At this time, I'm also able to retrieve existing coupons and query for data. However, it is only the part that adds coupons that does not work. I've also tried running it on another server, to no effect. Perhaps there's a bug, or I'm missing something? Thanks, Andrew
  3. Hello, I've been trying to work with the Blesta PHP API library for a bit and I stumbled on an issue while trying to interface with it. I am currently using the following code: <?php require_once "blesta_api.php"; require_once "blesta_response.php"; $user = "..."; $key = "..."; $url = "https://(snipped)/api"; $api = new BlestaApi($url, $user, $key); $code = bin2hex(openssl_random_pseudo_bytes(5)); $coupon_data = array( "code" => $code, "company_id" => 1, "used_qty" => 0, "max_qty" => 1, "start_date" => date("c"), "end_date" => "2025-12-30 11:59:59 UTC", "status" => "active", "recurring" => 0, "limit_recurring" => 0, "packages" => array(1, 2), "amounts" => array( "currency" => "USD", "amount" => 50, "type" => "percent" ) ); $response = $api->post("coupons", "add", $coupon_data); echo var_dump($response); ?> There doesn't seem to be an issue as when I execute this, I receive no errors back. However, the response is empty, and the coupon API suggests that it will respond with an integer. Am I doing something wrong?
×
×
  • Create New...