The request body contains bad syntax or is incomplete

POST to https://api-sandbox.dwolla.com/client-tokens via postman

Provided: up to date bearer token, content type:application/json, accept: application/vnd.dwolla.v1.hal+json, and the body has this: {
“_links”: {
“customer”: {
“href”: “https://api-sandbox.dwolla.com/customers/12V8efa0-33a7-4914-80ce-369ebb755147
}
}
}

But response always:{
“code”: “BadRequest”,
“message”: “The request body contains bad syntax or is incomplete.”
}

Hi @Robin1243 – it looks like the request body is missing the action field for which the client-token is to be granularly scoped for.

Rather than generating client-tokens yourself, we recommend letting the library handle that by implementing your dwollaAPIToken() function in the following way:

Configuration step:

<script>
  dwolla.configure({
      environment: "sandbox",
      styles: "/styles/create-custom.css",
      success: (res) => Promise.resolve(),
      error: (err) => Promise.resolve(),
      token: (req) => Promise.resolve(dwollaAPIToken(req)),
  });
</script>

dwollaAPIToken function example:

function dwollaAPIToken(req, additional) {
  const tokenUrl = "/tokenUrl";
  const headers = {
    Accept: "application/json",
    "Content-Type": "application/json",
    "X-Requested-With": "Dwolla-Drop-Ins-Library",
  };

  return fetch(`${tokenUrl}`, {
    credentials: "include",
    method: "POST",
    body: JSON.stringify(req),
    headers,
  })
    .then((response) => {
      return response.json();
    })
    .then((result) => {
      return result;
    })
    .catch((error) => {
      console.log(error);
      return error;
    });
}

tokenUrl endpoint implementation (the dwollaAPIToken function acts as passthrough between your client-side where the drop-in component lives, and the server-side which makes the calls to the Dwolla API as shown below) :

/**
 * Using Dwolla Node.js SDK - https://github.com/Dwolla/dwolla-v2-node
 * Refer to Step 1 on setup and configuration of Dwolla SDK
 */

app.post("/tokenUrl", function (req, res) {
  generateClientTokenWithBody(req.body).then((clientTokenRes) => {
    console.log(clientTokenRes);
    res.send({ token: clientTokenRes.token });
  });
});

function generateClientTokenWithBody(body) {
  const url = `/client-tokens`;

  return dwolla
    .post(url, body)
    .then((response) => {
      return response.body;
    })
    .catch((error) => {
      return error;
    });
}

Hope this helps! Let us know if you have any questions!

This topic was automatically closed after 365 days. New replies are no longer allowed.