GET request to jsw file resulting in 404, file not found

I am trying to access a database in my Wix site from an external web app I made. All of my requests to the file’s pathname result in a 404 file not found. I want to know if my URL for the request is correct.

Here is the formatting for the URL I am sending my requests to:
https://www.mysite.com/_functions/get_myAPI

I created the .jsw file by clicking on the Public & Backend button and then creating the file within Backend. Is the URL I am requesting the correct way of accessing this file?

Here is how the code looks in my .jsw file. This is for accessing a table in my database and sending it to an external website:
import { ok , created , notFound , serverError } from ‘wix-http-functions’ ;
import wixData from ‘wix-data’ ;

export async function get_myAPI( request ) {
const options = {
“suppressAuth” : true ,
“suppressHooks” : true
};

**try**  { 
    const  results  =  **await**  wixData . query ( "TableName" ). find ( options ); 
    const  dataSet  =  results . items . map ( item  => { 
        **return**  { 
            firstName :  item . firstName , 
            lastName :  item . lastName , 
            phone :  item . phone , 
            email :  item . email , 
            streetAddress :  item . streetAddress , 
            city :  item . city , 
            regionStateProvince :  item . regionStateProvince , 
            country :  item . country , 
            postalZipCode :  item . postalZipCode , 
            longAnswerField :  item . paragraphField , 
            shortAnswerField :  item . shortAnswerField 
        }; 
    }); 

    const  response  =  ok ({  body : {  dataSet  } }); 
    response . headers  = { 
        "Content-Type" :  "application/json" , 
        "Access-Control-Allow-Origin" :  "https://example.io" ,  
        "Access-Control-Allow-Headers" :  "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With" ,  
        "Access-Control-Allow-Methods" :  "GET, POST, OPTIONS" 
    }; 

    **return**  response ; 
}  catch  ( error ) { 
    console . error ( error ); 
    const  response  =  serverError ({  body : {  error :  error . message  } }); 
    response . headers  = { 
        "Content-Type" :  "application/json" , 
        "Access-Control-Allow-Origin" :  "https://example.io" ,  
        "Access-Control-Allow-Headers" :  "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With" ,  
        "Access-Control-Allow-Methods" :  "GET, POST, OPTIONS" 
    }; 

    **return**  response ; 
} 

}

Hi there!

Just to verify, what is the name of the file that contains this function?

If you would like to make an external API using http functions , it must be contained within http-functions.js.

You can create it by clicking on Public & Backend > Backend > Expose site API

If this is resolved, verify that the path you are making the GET request to is correct. Assuming you have connected your own domain, the path should be (based on your function get_myAPI):

https://www.mysite.com/_functions/myAPI

Thank you, so I moved my code from get_stylistsAPI.jsw to http-functions.js and it now is giving me better results. I am now getting 500 internal server telling me “The Stylists collection was removed, so y…data, create a new collection with the same name.” The thing is I have a collection called Stylists and I have two submissions in that table. Here is how my http-functions.js file looks:
import { ok , serverError } from ‘wix-http-functions’ ;
import wixData from ‘wix-data’ ;

export async function get_stylists ( request ) {
const options = {
“suppressAuth” : true ,
“suppressHooks” : true
};

**try**  { 
    const  results  =  **await**  wixData . query ( "Stylists" ). find ( options ); 
    const  stylists  =  results . items . map ( item  => { 
        **return**  { 
            firstName :  item . firstName , 
            lastName :  item . lastName , 
            phone :  item . phone , 
            email :  item . email , 
            streetAddress :  item . streetAddress , 
            city :  item . city , 
            regionStateProvince :  item . regionStateProvince , 
            country :  item . country , 
            postalZipCode :  item . postalZipCode , 
            longAnswerField :  item . paragraphField , 
            shortAnswerField :  item . shortAnswerField 
        }; 
    }); 

    **return**  ok ({ 
        headers : { 
            "Content-Type" :  "application/json" , 
            "Access-Control-Allow-Origin" :  "https://example.io" , 
            "Access-Control-Allow-Headers" :  "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With" , 
            "Access-Control-Allow-Methods" :  "GET, POST, OPTIONS" 
        }, 
        body : { 
            stylists 
        } 
    }); 
}  catch  ( error ) { 
    console . error ( error ); 

    **return**  serverError ({ 
        headers : { 
            "Content-Type" :  "application/json" , 
            "Access-Control-Allow-Origin" :  "https://example.io" , 
            "Access-Control-Allow-Headers" :  "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With" , 
            "Access-Control-Allow-Methods" :  "GET, POST, OPTIONS" 
        }, 
        body : { 
            error :  error . message 
        } 
    }); 
} 

}