Exposing API Delete HTTPS Function

So I have looked at the wix documentation and have attempted to write two functions to run a query on my contacts in my database and delete a contact in my database. I’ve gotten the first to work but not sure I understand how to pass the data in the delete function or how to build the endpoint, any help is appreciated. Also the paths don’t understand how that works.

import { created , serverError , ok , badRequest , notFound } from ‘wix-http-functions’ ;
import wixData from ‘wix-data’ ;

export function get_myFunction ( request ) {
//URL is : https://brandywinetechsrvllc.wixsite.com/velo/_functions/myFunction/get
let options = {
“headers” : {
“Content-Type” : “application/json”
//“Access-Control-Allow-Origin”: “*”
},
}

let dataOptions = {
“suppressAuth” : true ,
“suppressHooks” : false
};
// query a collection to find matching items
return wixData . query ( “PhoneBook” )
// .eq(“firstName”, request.path[0]).eq(“lastName”, request.path[1])
. find ( dataOptions )
. then ( ( results ) => {
console . log ( request . path [ 0 ]); // your site/velo/_functions/request.path[0]/request.path[1]

console . log ( results ); 
  // matching items were found 
  if ( results . items . length  >  0 ) { 
    options . body  = { 
      "items" :  results . items 
    }; 
    **return**  ok ( options ); 
  } 
  // no matching items found 
  options . body  = { 
    //"error": `'${request.path[0]} ${request.path[1]}' was not found` 
            "error" :  `'it went wrong` 

  }; 
  **return**  notFound ( options ); 
} ) 
// something went wrong 
. catch ( ( error ) => { 
  options . body  = { 
    "error" :  error 
  }; 
  **return**  serverError ( options ); 
} ); 

}

export function delete_myFunction ( request ) {
const id = request . path [ 0 ];

//URL may be: brandywinetechsrvllc.wixsite.com/velo/_functions/myFunction/delete/{4f0df655-6644-4955-a249-9ae90e4dbbd4}
let options = {
“headers” : {
“Content-Type” : “application/json”
}
};

// delete the item from a collection
return wixData . remove ( “PhoneBook” , id )
. then ( ( results ) => {

  options . body  = { 
    "deleted" :  results 
  }; 
  **return**  ok ( options ); 
} ) 
// something went wrong 
. catch ( ( error ) => { 
  options . body  = { 
    "error" :  error 
  }; 
  **return**  serverError ( options ); 
} ); 

}

Your code for the delete function looks OK. A few comments:

  1. Make sure the collection permissions lets everyone the permission to delete.

  2. The request headers should include a user-specific authorization key to make sure that users won’t be able to delete each other info by making a call with the wrong id. Compare the auth key with the id and if they are not match - return forbidden() and do no not delete;

P.S. and you’re better use a different function name (I mean the part after the underline).

All looks good, have u tried on postman? I dont see any issue with this.

this was my response

{
“deleted” : null
}

I got a 200

will use your suggestions, thanks

I am also trying to filter on get call using
.eq(“firstName”, request.path[0]) .eq(“lastName”, request.path[1]) and i get
{“name”:“Error”,“errorGroup”:“User”,“code”:“WD_VALIDATION_ERROR”}}

same with trying to delete using request.path
return wixData.remove(“myUserCollection”, request.path[1])