Jump to content
  • 0

List Domain Tld And Return Prices Through Api


L3Y

Question

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

Link to comment
Share on other sites

13 answers to this question

Recommended Posts

  • 0

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);
Link to comment
Share on other sites

  • 0

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.   :D 

Link to comment
Share on other sites

  • 0

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.

Link to comment
Share on other sites

  • 0

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>";
}
}

.

Link to comment
Share on other sites

  • 0

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 :)

Link to comment
Share on other sites

  • 0

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);
}
}
Link to comment
Share on other sites

  • 0

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);
    }
}
Link to comment
Share on other sites

  • 0

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
)
 

Link to comment
Share on other sites

  • 0

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;
    }
}
Link to comment
Share on other sites

  • 0

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 :)

Link to comment
Share on other sites

  • 0

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>";
?>

 

Link to comment
Share on other sites

  • 0
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...