Question

I am trying to use EasyPost with Codeigniter to build an e-commerce store that allows customers to choose the shipping rate they want.

I have loaded the CURL library and the REST library into my project and then have the following code:

class Shipping extends CI_Controller {

   function __construct() {
      parent::__construct();

      error_reporting(E_ALL);

      $this->rest->initialize(array(
        'server' => 'https://api.easypost.com/v2'
      ));
      $this->rest->api_key('replaced-hidden-api_key');
   }

   function index() {
      $result = $this->rest->get('/shipments');
      var_dump($result);
   }

}

When I load www.myurl.com/shipping I get the Sign in page for EasyPost but under my url? What in the world am I doing wrong? I'm not understanding how everyone says api's are so easy.

Otherwise

How can I include the EasyPost library into codeigniter without making a class for the files. These are the files I'm talking about

Was it helpful?

Solution

Are you including all of the required fields? All I see is that you included the api_key.

Here are the other required fields to make a shipment:

to_address       Address    required
from_address     Address    required
parcel           Parcel     required 

Example in PHP:

$to_address = \EasyPost\Address::create(...);
$from_address = \EasyPost\Address::create(...);
$parcel = \EasyPost\Parcel::create(...);
$customs_info = \EasyPost\CustomsInfo::create(...);

\EasyPost\Shipment::create(array(
  "to_address" => $to_address,
  "from_address" => $from_address,
  "parcel" => $parcel,
  "customs_info" => $customs_info
));

Source:

https://www.easypost.com/docs/api

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top