Creating Transfers in PHP using Guzzle


(Shreya Thapa) #1

Continuing the discussion from Activating customers via API:

Following is @spencer’s code sample to create a transfer using Guzzle in PHP.

<?php
require 'vendor/autoload.php';
$access_token = '';


$path = realpath('/Path/to/file/someFile.jpeg');
$customerId = 'e528f2be-56f5-4d86-8a79-b854488fd689';

$client = new GuzzleHttp\Client(['base_uri' => 'https://api-sandbox.dwolla.com']);
  $response =  $client->post('/customers/' . $customerId . '/documents', [
         'headers' => [
             'Accept' => 'application/vnd.dwolla.v1.hal+json',
             'Authorization' => 'Bearer ' . $access_token,
         ],
         'multipart' => [
             [
                 'name' => 'documentType',
                 'contents' => 'passport'
             ],
             [
                 'Content-type' => 'multipart/form-data',
                 'name'     => 'file',
                 'contents' => fopen($path, 'r')
             ]
         ]
     ]);

$response = $response->getHeader('location');
echo $response[0];
?>