L3Y Posted July 23, 2015 Report Posted July 23, 2015 Hi, As per ICANN recent policy changes we must list all our domain prices on our website. I am trying to fetch a list of our tld through the external API, and return the price + the tld. I am wondering what is the best way to do this using the current available methods. Someone can point me to the right direction? Thank you, Carl Quote
0 L3Y Posted July 23, 2015 Author Report Posted July 23, 2015 Ok. Here is how. The model is packages, the method get, and the parameter is package_id. The api is easy to use... ...once you get familiar with it First create a product group with all your domains. Then, fetch the products lists to return all the infos (including the pricing). Example : $response = $api->get(packages, getAllPackagesByGroup, package_group_id'=>100); Michael and PauloV 2 Quote
0 L3Y Posted July 24, 2015 Author Report Posted July 24, 2015 Hi, I'm able to fetch the info from the api, and return the BlestaResponse Object. However, i am having a hard time trying to loop through what's the API replied. Here is my code : $api = new Api($url, $user, $key); $model = "packages"; $method = "getAllPackagesByGroup"; $params = array('package_group_id'=>'2'); $response = $api->get($model, $method, $params); Here is what i tried : the following returned an error : "Cannot use object of type STDClass as array" foreach ($response as $item) { foreach ($item->pricing as $pricing) { var_dump($pricing->price); } } I've also tried : $i = 1; $response->pricing[$i]->price; And i've also tried : foreach($response as $resp) { foreach($resp->pricing as $key=>$pricing ) { echo $pricing[$key]->price."<br>"; } } ...but nothing is working and my third attemp to loop returned only a blank page with no errors in the logs. All i want is to display the price per year in a table. Quote
0 Michael Posted July 24, 2015 Report Posted July 24, 2015 Have you done the require_once? require_once "urltoblesta.com/billing/blesta_api.php"; Then: $user = "user"; $key = "key"; $url = "https://blestadomain.com/billing/api/"; $api = new BlestaApi($url, $user, $key); Then something like: $value1 = getPackagePrice($api, 1, "month", 1); So your value would be something else the first 1 is the package id. Quote
0 L3Y Posted July 24, 2015 Author Report Posted July 24, 2015 Hi, Thank you for trying to help on this, but i am able to fetch the info from the api. I just can't loop through the response. Here is my code : $api = new Api($url, $user, $key); $model = "packages"; $method = "getAllPackagesByGroup"; $params = array('package_group_id'=>'2'); $response = $api->get($model, $method, $params); The api response (sorry about the formatting) : Array ( [0] => stdClass Object ( [id] => 965 [id_format] => {num} [id_value] => 413 [module_id] => 3 [name] => .biz [description] => .biz [description_html] => .biz [qty] => [module_row] => 2 [module_group] => [taxable] => 1 [single_term] => 0 [status] => active [company_id] => 1 [prorata_day] => [prorata_cutoff] => [id_code] => 413 [module_name] => Namecheap [pricing] => Array ( [0] => stdClass Object ( [id] => 1903 [pricing_id] => 1903 [package_id] => 165 [term] => 1 [period] => year [price] => 23.4000 [setup_fee] => 0.0000 [cancel_fee] => 0.0000 [currency] => CAD ) [1] => stdClass Object ( [id] => 1904 [pricing_id] => 1904 [package_id] => 165 [term] => 2 [period] => year [price] => 46.8000 [setup_fee] => 0.0000 [cancel_fee] => 0.0000 [currency] => CAD ) Here is what i tried : foreach ($response as $item) { foreach ($item->pricing as $pricing) { var_dump($pricing->price); } } I've also tried : $i = 1; $response->pricing[$i]->price; And i've also tried : foreach($response as $resp) { foreach($resp->pricing as $key=>$pricing ) { echo $pricing[$key]->price."<br>"; } } . Quote
0 Michael Posted July 24, 2015 Report Posted July 24, 2015 Hi, Thank you for trying to help on this, but i am able to fetch the info from the api. I just can't loop through the response. Here is my code : $api = new Api($url, $user, $key); $model = "packages"; $method = "getAllPackagesByGroup"; $params = array('package_group_id'=>'2'); $response = $api->get($model, $method, $params); Here is what i tried : the following returned an error : "Cannot use object of type STDClass as array" for ($i=0;$i<sizeof($response);$i++) { echo $response[$i]->pricing[$i]->price; } I've also tried : $i = 1; $response->pricing[$i]->price; And i've also tried : foreach($response as $resp) { foreach($resp->pricing as $key=>$pricing ) { echo $pricing[$key]->price."<br>"; } } . Ah you'll need Paul, Cody or Tyson then Quote
0 L3Y Posted July 24, 2015 Author Report Posted July 24, 2015 Ah you'll need Paul, Cody or Tyson then I also think the same... ...or maybe one of the well know plugin dev's will know? Here is my current loop : foreach ($response as $item) { foreach ($item->pricing as $pricing) { var_dump($pricing->price); } } Quote
0 Tyson Posted July 24, 2015 Report Posted July 24, 2015 Take a look at the example in the docs. I can't speak to the error you received as I don't know which line the error refers to from your example. In any case, the BlestaResponse is an object. You are looping over the object's properties rather than the package pricing you want. // Fetch the packages $api = new Api($url, $user, $key); $model = "packages"; $method = "getAllPackagesByGroup"; $params = array('package_group_id'=>'2'); $response = $api->get($model, $method, $params); // Output each package's pricing if (($packages = $response->response())) { foreach ($packages as $package) { print_r($package->pricing); } } Blesta Addons and Michael 2 Quote
0 L3Y Posted July 24, 2015 Author Report Posted July 24, 2015 Hi Tyson, Seems like this return another array. I am looking to only display only the tld name and price. Is there any better way? Here is what i am getting now. Array([0] => stdClass Object([id] => 1903[pricing_id] => 1903[package_id] => 165[term] => 1[period] => year[price] => 23.4000[setup_fee] => 0.0000[cancel_fee] => 0.0000[currency] => CAD)[1] => stdClass Object([id] => 1904[pricing_id] => 1904[package_id] => 165[term] => 2[period] => year[price] => 46.8000[setup_fee] => 0.0000[cancel_fee] => 0.0000[currency] => CAD) Quote
0 Michael Posted July 24, 2015 Report Posted July 24, 2015 Hi Tyson, Seems like this return another array. I am looking to only display only the tld name and price. Is there any better way? Here is what i am getting now. Array ( [0] => stdClass Object ( [id] => 1903 [pricing_id] => 1903 [package_id] => 165 [term] => 1 [period] => year [price] => 23.4000 [setup_fee] => 0.0000 [cancel_fee] => 0.0000 [currency] => CAD ) [1] => stdClass Object ( [id] => 1904 [pricing_id] => 1904 [package_id] => 165 [term] => 2 [period] => year [price] => 46.8000 [setup_fee] => 0.0000 [cancel_fee] => 0.0000 [currency] => CAD ) That's because your printing, you could try: if (($packages = $response->response())) { foreach ($packages as $package) { echo $package->price; } } Quote
0 L3Y Posted August 9, 2015 Author Report Posted August 9, 2015 Hi, For prosperity, here is how you can display a list of all TLD's through the API in a table... echo "<table>"; if (($packages = $response->response())) { foreach ($packages as $package) { echo "<tr>"; $pricingsArray=($package->pricing); foreach ($pricingsArray as $pricing) { $priceArray = ($pricing->price); echo "<td>". $priceArray . "</td>"; } } } echo "</table>"; Thank you for your help on this I was simply missing another loop Michael 1 Quote
0 bdacus01 Posted April 29, 2018 Report Posted April 29, 2018 All: I am trying to Display my tld prices. This post is the only one I could find. I am not a Coder... I have loaded the api file from https://github.com/phillipsdata/blesta_sdk I have created a API user in the application under API access. I have a working Blesta 4.2.2 install. on php 7.1 I created a file prices.php and put the below in it. All I get is a White screen... What I want to do it to be able to link to a Page and all the info display. Like domainpricing.html <?php require_once "blesta_api.php"; $user = "my user "; $key = "my key here"; $url = "https://my domain/blesta/api/"; // Fetch the packages $api = new Api($url, $user, $key); $model = "packages"; $method = "getAllPackagesByGroup"; $params = array('package_group_id'=>'2'); $response = $api->get($model, $method, $params); echo "<table>"; if (($packages = $response->response())) { foreach ($packages as $package) { echo "<tr>"; $pricingsArray=($package->pricing); foreach ($pricingsArray as $pricing) { $priceArray = ($pricing->price); echo "<td>". $priceArray . "</td>"; } } } echo "</table>"; ?> Quote
0 Blesta Addons Posted April 29, 2018 Report Posted April 29, 2018 We have added to our cms PRO a function to list the domains, a proof of example are in live production here https://nh.ma/en/domains admin side for the page Paul 1 Quote
0 Tyson Posted April 30, 2018 Report Posted April 30, 2018 On 4/28/2018 at 7:16 PM, bdacus01 said: I created a file prices.php and put the below in it. All I get is a White screen... A white screen is indicative of a 500 internal server error or a php fatal error with error reporting disabled/suppressed. I would suggest enabling error reporting or checking your php error logs for the error that was encountered during runtime. Quote
Question
L3Y
Hi,
As per ICANN recent policy changes we must list all our domain prices on our website.
I am trying to fetch a list of our tld through the external API, and return the price + the tld.
I am wondering what is the best way to do this using the current available methods.
Someone can point me to the right direction?
Thank you,
Carl
13 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.