Transfer location not appearing in header, and empty JSON response

From the guide here: https://developers.dwolla.com/guides/transfer-money-between-users/create-transfer#step-5-initiating-a-transfer

I should be able to use the following code to create a transfer:

var requestBody = {
  _links: {
    source: {
      href:
        "https://api-sandbox.dwolla.com/funding-sources/80275e83-1f9d-4bf7-8816-2ddcd5ffc197",
    },
    destination: {
      href:
        "https://api-sandbox.dwolla.com/funding-sources/375c6781-2a17-476c-84f7-db7d2f6ffb31",
    },
  },
  amount: {
    currency: "USD",
    value: "225.00",
  },
};

// For Dwolla API applications, an appToken can be used for this endpoint. (https://docs.dwolla.com/#application-authorization)
appToken
  .post("transfers", requestBody)
  .then((res) => res.headers.get("location")); // => 'https://api.dwolla.com/transfers/d76265cd-0951-e511-80da-0aa34a9b2388'

However when doing this, the location header does not exist on the result. All I get is an empty JSON document with a status: 201.

How do I get the ID of the transfer I have just created? (In the sandbox UI, I can see the transfers are being created, so there’s nothing wrong with my request object)

Hi @aaronmboyd

The location header would not be returned in a JSON body, so an empty JSON with a 201 status is the expected behavior for a successful transfer.

You can find the id of the transfer in the location header itself. The code above looks to be from the docs, so you wouldn’t be able to create a successful transfer with it, being that the ids in it are attached to someone else’s account (a developer advocate’s).

You would need to create funding sources of your own to initiate a successful transfer.

Below are some resource on location headers and a screencast I did using our Postman Collection

MDN
GeeksForGeeks

Thanks for following up.

I’m not using the code verbatim from the documentation, I’m using my own verified funding sources. I know the transfers are being created because I can see them in the sandbox web login, and process them using the sandbox simulation.

My code is exactly the same, but the location header never appears using the same pattern in the documentation.

Is there something different I should be doing? For other patterns, for example the “create unverified customer” flow, which uses a location header return value, it works as documented. e.g. I have this code, and everything works as expected:

    const appToken: dwolla.Client = await getAppToken();
    const res: dwolla.Response = await appToken.post("customers", customer);
    const customerURL = res.headers.get("location");

Any ideas what to try next?

Hi @aaronmboyd

What gets returned when you print customerURL in the console? In case it helps, here is an app we built which also gets the location header from a transfer.

The second example with customerURL is an example of mine that works perfectly.

I’m trying to get transfers to work the same. I have pretty much exactly the same code as in the app example you linked. The res.headers.get("location") for transfers is always undefined or empty.

If I log the dwolla.Response object res, all I see is:

{
  status: 201
  headers: {}
  body: {}
}

@kmoreira Could you please confirm the expected output from posting a new transfer? Are we just meant to get a 201 and then wait for the “customer_transfer_created” webhook event instead? I was hoping to get the ID straight from the post, but this doesn’t appear to be the case.

In fact, from my test suite, it appears that transfers take many seconds to appear in the sandbox backend after creation. Is this the case?

Hi @aaronmboyd – the expected output is for the transfer URL to be included in the location header as with other resource creation requests that return a 201 HTTP status code.

Would you be able to share some examples of transfers that aren’t displaying this? Is it occurring consistently with all transfers?

It may take up to a second or a few for the transfer to show up in Sandbox. In production it should be less than a second.

@shreya Every transfer I create does this. The dwolla.Response object is exactly as I posted above previously:

{
  status: 201
  headers: {}
  body: {}
}

Got it. Would you be able to share your code for creating a transfer and printing the Dwolla response? I wonder if you’re using JSON.stringify() during parsing the response/headers. This renders the headers output to {}.

Another thing could be the casing - Location vs location.

Thank you, I will check whether I’m parsing the response as JSON.stringify before retrieving the headers.

Thanks, the JSON.stringify was the problem!

Thanks for the update, Aaron!