HTTP function throwing error 500.

Hi, I’m exuasted after spending days trying to fix this with no luck as im creating new endpoint for API.

I’m confused, all other endpoints work fine. I even tried pasting jsw code directly into function, still no luck.

I’ve been trying to call this function successfully:

//function
export function post_formapi(request) {

inapi(request)

} 
//jsw
export const inapi = async (request) => {
        return request.body.json()
  .then( (body) => {
  wixData.query("dclicks")
  .eq('key', body.key)
  .ge("_createdDate", new Date(Date.now() - 30 * 86400000))
  .find()
  .then( (results) => {
  let count = String(results.totalCount);

     wixData.query("Plans")
  .eq('key',  body.key)
  .find()
  .then( (results) => {
       let firstItem = results.items[0]; //see item below
       let plan = firstItem["plan"];
     if (plan === 'Basic')  {
if (Number(count) > 100) {
        }
        else {
screenshot(body.screenofpage, body.key, body.input1, body.input3, body.input5, body.input2, body.starrating)
    
        // Sample options value:
let options = {
         "variables": {
     "Email": String(body.input1),
     "Page": String(body.input3),
     "Type": String(body.input5),
     "Message": String(body.input2),
  }
}

pushmail(body.key, options)

    
let insrt = {
     "input1": String(body.input1),
     "input2": String(body.input2),
     "input3": String(body.input3),
     "input5": String(body.input5),
     "key": body.key
}
wixData.insert("dclicks2", insrt);

    
  }
}

    
    else if (plan === 'Pro') {
        if (Number(count) > 500) {
        }
        else {
screenshot(body.screenofpage, body.key, body.input1, body.input3, body.input5, body.input2, body.starrating)
    
        // Sample options value:
let options = {
         "variables": {
     "Email": String(body.input1),
     "Page": String(body.input3),
     "Type": String(body.input5),
     "Message": String(body.input2),
  }
}

pushmail(body.key, options)

    
let insrt = {
     "input1": String(body.input1),
     "input2": String(body.input2),
     "input3": String(body.input3),
     "input5": String(body.input5),
     "key": body.key
}
wixData.insert("dclicks2", insrt);

    
  }
}
        
    else if (plan === 'Business') {
        if (Number(count) > 10000) {
        }
        else {
screenshot(body.screenofpage, body.key, body.input1, body.input3, body.input5, body.input2, body.starrating)
    
        // Sample options value:
let options = {
         "variables": {
     "Email": String(body.input1),
     "Page": String(body.input3),
     "Type": String(body.input5),
     "Message": String(body.input2),
  }
}

pushmail(body.key, options)

    
let insrt = {
     "input1": String(body.input1),
     "input2": String(body.input2),
     "input3": String(body.input3),
     "input5": String(body.input5),
     "key": body.key
}
wixData.insert("dclicks2", insrt);

        
        }
  }
        
    
    else if (plan === 'Enterprise') {
        if (Number(count) < 100000) {
        }
        else {
screenshot(body.screenofpage, body.key, body.input1, body.input3, body.input5, body.input2, body.starrating)
    
        // Sample options value:
let options = {
         "variables": {
     "Email": String(body.input1),
     "Page": String(body.input3),
     "Type": String(body.input5),
     "Message": String(body.input2),
  }
}

pushmail(body.key, options)

    
let insrt = {
     "input1": String(body.input1),
     "input2": String(body.input2),
     "input3": String(body.input3),
     "input5": String(body.input5),
     "key": body.key
}
wixData.insert("dclicks2", insrt);

    
        
        }
    
    }
            });
    });
  });
}

Yeah, i know thats a mouthful. That extra code is in place to prevent users from exceeding monthly usage.
Any ideas on why http function is not working? i kind of need to know soon as this is for a live app.

I haven’t gone over your code, but some errors just popped up:
You forgot to put a return before all the Promises.

  • you don’t return any http response.
    Please fix it, and then if it’s still doesn’t work, post the fixed code.

fixed now