Fatal error: Uncaught DwollaSwagger\ApiException

Hello Team,
I want to connect Dwolla to my Wordpress site, but after adding code and loading the page it shows this error (please see attached image).

This is my code:
require get_stylesheet_directory() . ‘/vendor/autoload.php’;
include get_stylesheet_directory() . ‘/dwolla-swagger-php/DwollaSwagger.php’;
DwollaSwagger\Configuration::$username = ‘I’;
DwollaSwagger\Configuration::$password = ‘’;
$apiClient = new DwollaSwagger\ApiClient(“https://api-sandbox.dwolla.com”);
$customersApi = new DwollaSwagger\CustomersApi($apiClient);

$customer = $customersApi->create([
‘firstName’ => ‘Jane’,
‘lastName’ => ‘Merchant’,
‘email’ => ‘jmerchant@nomail.net’,
‘type’ => ‘receive-only’
]);

print($customer);

Did I use the wrong code? Sorry I’m new so I don’t understand much

Hi @devrentaraj

That error looks like it’s saying you are lacking valid authentication credentials. It looks like you’re trying to call the sandbox api, have you set up a sandbox account in order to obtain you key and secret?

https://accounts-sandbox.dwolla.com/login

Hmm…looks like @devrentaraj does have the Sandbox credentials in his code. A 401 error usually means there’s something wrong with the request-body.

@devrentaraj, you should be able to catch the error and get the JSON response-body by wrapping the request in a try/catch and display the error response by calling the getResponseBody() method.

Example:

try{
    $new_customer = $customersApi->create([
        //request_body   
    ]);
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getResponseBody(), "\n";
}

Yes, I already have the Sandbox credentials, please see attached image below.

I tried catching the error as per your instructions and I get the following error:

Hi @devrentaraj

I erased your creds from the your posts so it won’t be shared with the public.

I was also wondering if you could try formulating your code the way it is in the Swagger “Quick start” section of the Readme

I’m seeing a few minor differences in your original req that may be throwing things off

Hi @kmoreira
Thank you for responding, but I can’t access this page Readme

Hi, I was missing access token, I added it in my code and now it worked for me. Thank you so much!

1 Like

Our pleasure. And apologies for the link. Here is the correct link in case anything else comes up GitHub - Dwolla/dwolla-swagger-php: Autogenerated PHP SDK client for API V2

Hello @kmoreira,
Can I ask you to delete some accounts that I no longer need from my sandbox account? I can only change them to suspended and deactivate but I want to remove it completely from my account.

Hi @devrentaraj

While you can deactivate and suspend a Customer, the functionality to delete a Customer isn’t supported as per the data retention guidelines that Dwolla is subject to within the USA.

Hi @kmoreira, I got it, thank you very much!

1 Like