I am trying to get specific data filtered on an API call. The objects are not iterable and I have tried a million different ways to get the specific data I need.
So...I need to filter out tip_money
and return only that data instead of the full response.
Here is the call
router.get('/', auth, (req, res) => {
try {
apiInstance.listPayments(opts).then(function (payments) {
res.send(payments)
})
} catch (error) {
console.error(error)
}
});
and here is the response (partially):
{
"payments": [
{
"id": "rt6Q8LL3XrCLGltl3bBhazMF",
"created_at": "2019-11-12T23:34:03.012Z",
"updated_at": "2019-11-12T23:53:45.481Z",
"amount_money": {
"amount": 13080,
"currency": "USD"
},
"total_money": {
"amount": 14047,
"currency": "USD"
},
"processing_fee": [
{
"effective_at": "2019-11-13T01:53:44.000Z",
"type": "INITIAL",
"amount_money": {
"amount": 375,
"currency": "USD"
}
}
],
"status": "COMPLETED",
"source_type": "CARD",
"card_details": {
"status": "CAPTURED",
"card": {
"card_brand": "VISA",
"last_4": "",
"exp_month": ,
"exp_year": ,
"cardholder_name": "",
"fingerprint": "",
"bin": ""
},
"entry_method": "EMV",
"cvv_status": "CVV_NOT_CHECKED",
"avs_status": "AVS_NOT_CHECKED",
"auth_result_code": "009208",
"application_identifier": "A0000000031010",
"application_name": "CITI VISA",
"application_cryptogram": "6b7992ab9fba75fe",
"verification_method": "SIGNATURE",
"verification_results": "UNKNOWN",
"statement_description": ""
},
"location_id": "",
"order_id": "",
"employee_id": "DrU-af4--DVfMCkl2z73"
},
any help in the right direction would be appreciated!
See if something like this works for you
router.get('/tips', auth, (req, res) => {
try {
apiInstance.listPayments(opts).then(function (payments) {
const tips = payments.map(payment => payment.tip_money).filter(tip => tip != undefined);
res.send(tips);
})
} catch (error) {
console.error(error)
}
});
Remove the .filter at the end if you also want the endpoint to return the undefined tips since it doesn't seem like all the payments have tips on them.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments