Activating customers via API


#21

Hi @shreya, we made the suggested changes and tried using Guzzle the but the realpath function is not working. It’s returning blank.

<?php 

echo echo realpath("/documents/11_053234_sample-usa-passport.jpg");
 
?>

The above code isn’t working but the file exists: https://www.rx-post.com/documents/11_053234_sample-usa-passport.jpg

After using Guzzle, we got the following error:

Client error: `POST https://api-sandbox.dwolla.com/customers/7a2b38f2-08b2-4587-baac-094b6990ac90/documents` resulted in a `400 Bad Request` response:
{"code":"BadRequest","message":"The request body contains bad syntax or is incomplete."} 
{"code":"BadRequest","message":"The request body contains bad syntax or is incomplete."}

Below is the code we’re using:

include("vendor/autoload.php");
  $client = new \GuzzleHttp\Client();  
  $file_name_with_full_path = "/home/rxpost/public_html/documents/11_231701_sample-usa-passport.jpg"
 Try {
            $response = $client->post(
                "https://api-sandbox.dwolla.com/customers/7a2b38f2-08b2-4587-baac-094b6990ac90/documents", [
                    'headers' => [
                        'Accept'                => 'application/vnd.dwolla.v1.hal+json',
                        'Content-Type'          => 'multipart/form-data',  // <-- commented out this line
                        'Authorization'         => 'Bearer '. $token,
                    ],
                    'multipart' => [
                        [
					        'name'     => 'documentType',
					        'contents' => 'passport'
					    ],
                        [
                            'name'     => 'file',
                            'contents' => fopen($file_name_with_full_path, 'r') ,
                            'filename' => "my-passport.jpg"                        ] 
                    ],
                ] 
            );
           echo $response->getBody()->getContents();
        } catch(\Exception $e) {
            echo $e->getMessage();
            $response = $e->getResponse();
            $responseBody = $response->getBody()->getContents();

            echo $responseBody;
            exit;
        }

(Shreya Thapa) #22

Hi @sunlightmedia, thank you for applying the changes, and getting back to us. It seems you can omit realpath() if you are using Guzzle.

The response is referring to a syntax error in your code. I checked the Guzzle documentation for sending form files, and found that this may have something to do with how you are POSTing the data,

According to the documentation, your POST request should look something like this,

$response = $client->request(‘POST’, ‘https://api-sandbox.dwolla.com/customers/7a2b38f2-08b2-4587-baac-094b6990ac90/documents’, […

Please let us know if the code works after referring to the official documentation.


#23

Hi @shreya

We have removed the realpath, but the same issue happens. The error is saying that “The request body contains bad syntax or is incomplete”. We also find the same error after adding that.

Both are doing same job ($client->post or $client->request(‘POST’ ). As you we haven’t been able to find any PHP-based documentation about “document upload”, we need your help regarding this. Below is our code. We did not find any issue, but the document is not uploaded.

$file_name_with_full_path = realpath($_SERVER['DOCUMENT_ROOT'].'/documents/'.$img_path)  ;
   
  include("vendor/autoload.php");
  $client = new \GuzzleHttp\Client();  
   
 Try {
            $response = $client->request('POST',
                'https://api-sandbox.dwolla.com/customers/7a2b38f2-08b2-4587-baac-094b6990ac90/documents', [
                    'headers' => [
                        'Accept'                => 'application/vnd.dwolla.v1.hal+json',
                        'Content-Type'          => 'multipart/form-data',  // <-- commented out this line
                        'Authorization'         => 'Bearer '. $token,
                    ],
                    'multipart' => [
                        [
					        'name'     => 'documentType',
					        'contents' => 'passport'
					    ],
                        [
                            'name'     => 'file',
                            'contents' => fopen($file_name_with_full_path, 'r') ,
                            'filename' => $img_path
                        ] 
                    ] 
                ] 
            );
           echo $response->getBody()->getContents();
        } catch(\Exception $e) {
            echo $e->getMessage();
            $response = $e->getResponse();
            $responseBody = $response->getBody()->getContents();

           echo '<pre>'. print_r($responseBody,true);
            exit;
        }
        
Error : {"code":"BadRequest","message":"The request body contains bad syntax or is incomplete."}
Online Documentation

Creating Transfers in PHP using Guzzle