Transfer information is not coming accurately

client = $dwolla.auths.client
mass_payment = "mass-payments", request_body, headers
mass_payment_url = mass_payment.response_headers[:location]   # value ""
mass_payment_items = client.get "#{mass_payment_url}/items" 
transfer_urls = [];
mass_payment_items._embedded.items.each do |item|
        transfer_urls << item._links["transfer"]["href"]

I need the value of the array of transfer_urls. I did this job after requesting for a mass_payment. I need all the transfers details to save in my database. but problem is sometimes the transfer details is missing in the response. then this line item._links["transfer"]["href"] throws error. and background retries to fetch the data. then it got the correct response. but what is the reason? I am giving the response of a failed case.

Transfer key missing response for a item:

{"_links"=>{"self"=>{"href"=>"", "type"=>"application/vnd.dwolla.v1.hal+json", "resource-type"=>"mass-payment-item"}, "mass-payment"=>{"href"=>"", "type"=>"application/vnd.dwolla.v1.hal+json", "resource-type"=>"mass-payment"}, "destination"=>{"href"=>"", "type"=>"application/vnd.dwolla.v1.hal+json", "resource-type"=>"customer"}}, "id"=>"9a337477-47ce-4a56-a1dd-337b30e68641", "status"=>"pending", "amount"=>{"value"=>"0.25", "currency"=>"USD"}, "metadata"=>{"investment_id"=>"278", "unsecure_repayment_id"=>"99"}, "clearing"=>{"destination"=>"next-available"}, "created"=>2021-12-15 16:05:46 UTC}

Transfer key present in the response:

{"_links"=>{"self"=>{"href"=>"", "type"=>"application/vnd.dwolla.v1.hal+json", "resource-type"=>"mass-payment-item"}, "mass-payment"=>{"href"=>"", "type"=>"application/vnd.dwolla.v1.hal+json", "resource-type"=>"mass-payment"}, "destination"=>{"href"=>"", "type"=>"application/vnd.dwolla.v1.hal+json", "resource-type"=>"customer"}, "transfer"=>{"href"=>"", "type"=>"application/vnd.dwolla.v1.hal+json", "resource-type"=>"transfer"}}, "id"=>"e3f2852c-c340-4016-ae39-9ab24adf299e", "status"=>"success", "amount"=>{"value"=>"0.25", "currency"=>"USD"}, "metadata"=>{"investment_id"=>"278", "unsecure_repayment_id"=>"98"}, "clearing"=>{"destination"=>"next-available"}, "created"=>2021-12-15 16:05:46 UTC}

Hi @todor – once a masspayment is created via the API, we run the masspayment job which parses through each item and creates a transfer resource for each successful item. We recommend waiting for the "mass_payment_completed" or "customer_mass_payment_completed" webhook before making the GET call to "#{mass_payment_url}/items"

If you notice the status of the first item, it says pending which denotes that the related transfer hasn’t yet been created.

The second item which has a transfer associated with it, has a status of success.

Hope that helps! Here’s also a guide where we provide some best practices when creating a masspayment. Let us know if you have any questions!