Bad Request initiating a transfer via Laravel 9 guzzle

I am trying since three days i cant understand why transfer is not working.
anytime when post transfer respose showing me this.

   $token = $this->access_token();
       

        $transfer_request = 
          array("_links" =>
          array (
            "source" =>
            array (
               "href"=>"https://api-sandbox.dwolla.com/accounts/824e1684-fd56-4b4f-b896-a2d7fa10b11d"
            ),
            "destination" =>
            array (
               "href"=>"https://api-sandbox.dwolla.com/customers/824e1684-fd56-4b4f-b896-a2d7fa10b11d"
            ),
          ),
          "amount" =>
          array (
            "currency" => "USD",
            "value" => "225.00",
          )
        );
        $response = Http::contentType("application/json")->withHeaders([
    'accept' => 'application/vnd.dwolla.v1.hal+json',
    ])->withToken(json_decode($token)->token)->post('https://api-sandbox.dwolla.com/transfers',$transfer_request)->headers();
           
           return $response;

help me please

1 Like

@hasnain_khan, can you please send over the full error that Dwolla is returning so that we can investigate this issue further?

yes sure this is the response body

{"code":"BadRequest","message":"The request body contains bad syntax or is incomplete."}

Thank you! If I’m looking at the message correctly, I believe this was already addressed via another channel; however, just in case, I’ll leave the response here as well.

When we received this request, the JSON contained a top-level json property, with the remainder properties—for example, _links and amount—nested inside:

{"json":{"_links":{"source":{"href":"https://api-sandbox.dwolla.com/accounts/824e1684-fd56-4b4f-b896-a2d7fa10b11d"},"destination":{"href":"https://api-sandbox.dwolla.com/customers/824e1684-fd56-4b4f-b896-a2d7fa10b11d"}},"amount":{"currency":"USD","value":"225.00"}}}

Instead, when the request is sent (and subsequently parsed by us), _links and amount must not be contained as a child of another JSON element; they must be at the top-most level of the structure:

{"_links":{"source":{"href":"https://api-sandbox.dwolla.com/accounts/824e1684-fd56-4b4f-b896-a2d7fa10b11d"},"destination":{"href":"https://api-sandbox.dwolla.com/customers/824e1684-fd56-4b4f-b896-a2d7fa10b11d"}},"amount":{"currency":"USD","value":"225.00"}}

I hope this helps! If you have any further questions, please feel free to reach out!

{
    "code": "BadRequest",
    "message": "The request body contains bad syntax or is incomplete."
}

same result

Hi @hasnain_khan – it appears you may have resolved the issue. The more recent calls from your application are processing successfully.

As for the BadRequest errors previously, it appears some had to do with passing a null value in one of the fields, and some were due to using the wrong funding-source link in the request body like the following:

https://api-sandbox.dwolla.com/accounts/824e1684-fd56-4b4f-b896-a2d7fa10b11d

{
   "_links":{
      "source":{
         "href":"https://api-sandbox.dwolla.com/accounts/824e1684-fd56-4b4f-b896-a2d7fa10b11d"
      },
      "destination":{
         "href":"https://api-sandbox.dwolla.com/funding-sources/d929b033-b4e9-49fb-bc0e-b2296f47d1e7"
      }
   },
   "amount":{
      "currency":"USD",
      "value":"45"
   }
}