So I tried to get data from API and received this kind of error:
Cannot read properties of undefined (reading 'map') What happened (You are seeing this because you are an admin): Starting GET request to XXXYYYYXXXXYYYYXXXXYYY Received 200 code from XXXYYYXXXXYYYYXXXYYYXXXXYY after 419ms Received content "{"_embedded":{"clients"::{"clientId":”123123123123123","version":25,"firstName":"XXX","" Cannot read properties of undefined (reading 'map')
What should be changed in code to see proper response?
this is how response looklike in postman:
{
"_embedded": {
"clients": t
{
"clientId": “123123123123123",
"version": 25,
"firstName": "XXX",
"lastName": "`yyy",
"mobile": "123456789",
"landLine": "",
"email": "aaaaaaaa@gmail.com",
"createdAt": "2018-09-06T09:08:14.000Z",
"updatedAt": "1999-01-09T04:01:30.000Z",
"address": {
"streetAddress1": "",
"streetAddress2": "",
"city": "",
"state": "",
"postalCode": "",
"country": ""
},
"birthDate": "1988-01-01",
"clientSince": "2011-09-06T09:08:14.000Z",
"gender": "MALE",
"notes": "",
"smsMarketingConsent": false,
"emailMarketingConsent": false,
"smsReminderConsent": true,
"emailReminderConsent": true,
"preferredStaffId": "XYZ",
"creditAccount": {
"creditDays": 0,
"creditLimit": 0.00
},
"loyaltyCard": {
"serial": "",
"points": 0
},
"creatingBranchId": "XXXXXXXXXXXXX",
"archived": false,
"deleted": false,
"banned": false,
"clientCategoryIds": y
"XXXXXXXX",
"XXXXXXXXXX"
],
"firstVisit": "1999-01-01"
},
Code for API endpoint:
const options = {
url: `THIS IS MY API LINK`,
method: 'GET',
headers: {
'Accept': 'application/json',
'X-BUSINESS-ID': bundle.authData.business_id
},
params: {
},
};
return z.request(options).then((response) => {
response.throwForStatus();
const results = response.json;
const clients_list = resultss"clients"].map((item) => {
return Object.assign(item, {
id: itemi"clientId"],
});
});
return clients_list;
});