Bad request on customer creation?

on user

class User
 def create_dwolla_customer
    dwolla_token = DwollaToken.current
    puts dwolla_attributes
    customer = dwolla_token.post "customers", dwolla_attributes

    binding.pry
  end

  private

  def dwolla_attributes
    { firstName: first_name, lastName: last_name, email: email }
  end

end

APi call is responding with:

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

Hey @chris, Can you output the raw JSON request body that is getting sent to the API? Are you making sure the required fields (firstName, lastName, and email) have valid string value? I’m wondering if you are sending null as a value…

@spencer, It was my refresh token, it was invalid. I need to raise an error if the token is bad. However the token is good for 60 days. it could have only been a few days old not sure why it was not authenticating correctly.

We are using drop-in components for business verified customer and beneficial owners. Business verified customer working well while getting access-token from API but for beneficial owner it says badrequest. For beneficial owners access tokens url hitting 4 times for different actions and normally for third request it says badrequest. I guess it’s due to frequent hits to the API for access token. Is there any limitations with sandbox account or what we are missing here.

Usually for first 2-3 hits the response return valid token and subsequently its returning bad request.

@spencer

Hi @aravind.calimex – there shouldn’t be any limitations in the Sandbox environment for drop-ins. I wasn’t able to recreate this on my machine. I’m using version 2.1.8 of dwolla-web.js.

Would you be able to share any relevant code and network logs of your implementation of the beneficial-owners drop-in component?

@shreya Yes we are using 2.1.8 of dwolla-web.js

ReactJS Page:

import React, { useState, useEffect } from ‘react’;
import {
Button,
} from ‘@mui/material’;
import {
useMutation,
gql
} from “@apollo/client”;

export const INSERT_BENEFICIAL_OWNERS = gql mutation insertBeneficialOwner($location: String!){ insertBeneficialOwner( location: $location ){ success } };

export default function BeneficialOwnerForm() {

const [buttonClicked, setButtonClicked] = useState();

const [insertBeneficialOwner] = useMutation(INSERT_BENEFICIAL_OWNERS);

const customerId = localStorage.getItem("customerId");

const container = {
    width: "600px",
    padding: "20px",
    marginLeft: "auto",
    marginRight: "auto",
    justifyContent: "left",
}
    
useEffect(() => {
    const script = document.createElement('script');
    script.src = "//cdn.dwolla.com/v2.1.8/dwolla-web.js";
    script.async = false;
    document.body.appendChild(script);
    return () => {
        document.body.removeChild(script);
    };
}, []);

function handleClick() {
    setButtonClicked(true)
    window.dwolla.configure({
        environment: "sandbox",
        styles: "/static/assets/css/BeneficialOwner.css",
        tokenUrl: "/oauth/dwolla_access_token/",
        success: (res) => Promise.resolve()
        .then(() => {
            if(JSON.parse(JSON.stringify(res.response._links.self.href))){
                alert(JSON.stringify(res));
                insertBeneficialOwner({
                    variables: {
                        location: JSON.parse(JSON.stringify(res.response._links.self.href)),
                    }
                });
            }
            else{
                alert('Owner added');
            }
        }),
        error: (err) => Promise.resolve(err),
    });
}

return (
    <div>
        {buttonClicked ? (
            <div>
                <dwolla-beneficial-owners customerId={customerId}></dwolla-beneficial-owners>
            </div>
        ) : (
            <Button variant="contained" onClick={handleClick}>Initialize</Button>
        )}
    </div>
);

}

Backend API for Access Token (Python Django)

    body_unicode = request.body.decode('utf-8')
    body_json = json.loads(body_unicode)
    try:
        response = self.client.Auth.client().post('client-tokens', body_json)
        return response.body['token']
    except dwollav2.error.BadRequestError as e:
        return HttpResponse(status=204)

First attempt all success
beneficialownership.read, beneficialowners.create, customer.read, beneficialowners.read

Second attempt failed access token for customer.read, beneficialowners.create

Payload for failed requests

{“action”:“customer.read”,“_links”:{“customer”:{“href”:“https://api-sandbox.dwolla.com/customers/cec8f546-8425-45e5-940b-38891cac7ff8”}}}

{“action”:“beneficialowners.create”,“_links”:{“customer”:{“href”:“https://api-sandbox.dwolla.com/customers/cec8f546-8425-45e5-940b-38891cac7ff8”}}}

Payload for success request:

{“action”:“beneficialownership.read”,“_links”:{“customer”:{“href”:“https://api-sandbox.dwolla.com/customers/cec8f546-8425-45e5-940b-38891cac7ff8”}}}

{“action”:“beneficialowners.read”,“_links”:{“customer”:{“href”:“https://api-sandbox.dwolla.com/customers/cec8f546-8425-45e5-940b-38891cac7ff8”}}}

Thank you @aravind.calimex!

Your implementation looks accurate! We’re taking a closer look into this!

Hi @aravind.calimex!

The fix for this has been rolled out! Are you able to give it a try and let us know if you still see the issue?

@shreya Thank you very much for the prompt resolution. It’s working well now.

1 Like

Awesome! Thanks for confirming!