# http-functions,  backend functions, get endpoint returning nulls



**URL:** <https://forum.wixstudio.com/t/http-functions-backend-functions-get-endpoint-returning-nulls/10359>\
**Category:** Ask the community\
**Tags:** wix-members-area, code, question\
**Created:** [June 1, 2023, 4:01pm UTC](https://forum.wixstudio.com/t/http-functions-backend-functions-get-endpoint-returning-nulls/10359 "2023-06-01T16:01:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![amna-ahmad-ch](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/amna-ahmad-ch/32/37548_2.png) [@amna-ahmad-ch](https://forum.wixstudio.com/u/amna-ahmad-ch)\
**Post date:** [June 1, 2023, 4:01pm UTC](https://forum.wixstudio.com/t/http-functions-backend-functions-get-endpoint-returning-nulls/10359/1 "2023-06-01T16:01:54Z")

</div>

Hello. I am trying to make an API that returns all the emails of members subscribed to a particular pricing plan. Below is my code which first gets all the orders and then for each order gets the member email. This code runs perfectly fine if I try it in $w.on Ready(function ()). But when I try the same code in an API it somehow doesnt wait for the promise to finish and returns nulls instead

```javascript
const myListOrdersFunction = require('backend/test').myListOrdersFunction;
const myGetMemberFunction = require('backend/getMember').myGetMemberFunction;

$w.onReady(function () {
    const response = {
        "headers": {
            "Content-Type": "application/json"
        }
    }; 
    return test()
        .then(result => {
            console.log("final", result);
            console.log("Type of result:", JSON.stringify(result));
            response.body = {
                "emails": result
            };
            //return ok(response); 
            console.log("response", response);
        })
        .catch(error => {
            console.log(error);
        });
});

async function test() {
    return new Promise((resolve, reject) => {
        const promises = [];
        myListOrdersFunction()
            .then(listedOrders => {
                const emailPromises = listedOrders.map(order => {
                    const loginEmails = [];
                    return myGetMemberFunction(order.buyer.memberId)
                        .then(member => {
                            loginEmails.push(member.loginEmail);
                            return loginEmails;
                        })
                        .catch(error => {
                            console.log(error);
                        });
                });

                Promise.all(emailPromises)
                    .then(results => {
                        const flattenedEmails = results.flat();
                        resolve(flattenedEmails);
                    })
                    .catch(error => {
                        console.log(error);
                        reject(error);
                    });
            })
            .catch(error => {
                console.log(error);
                reject(error);
            });
    });
}

```

```javascript
output from API
{"emails":"[null,null]"}

output if I run it in some page
final 
Array(2)jsonTableCopy JSON
0: "premium2@g mail. com"
1: "amna.ahmad.ch@ gmail. com"

```

What am I doing wrong. Plz help
