Remote update of a DB table

Hi all,
I am trying to remotely update a DB table created on a website.
This DB table should only have one entry so an update is required and not an Insert.

I have created a DB that looks like this:

and at the backend section I have created a file called http-functions.js containing the following:

‘use strict’;
import {ok, response, badRequest} from ‘wix-http-functions’;
import wixData from ‘wix-data’; // To use wixData functions we need to import this
export function post_tabledata(request) {
return request.body.json()
.then(body => {
let dataInsert = {

“Date”: body.Date,
“DiscountPercent”: body.DiscountPercent,
“DiscountDueDate”: body.DiscountDueDate,
“FullPrice”: body.FullPrice,
“DiscountedPrice”: body.DiscountedPrice,
“ButtonURL”: body.ButtonURL
};
return wixData.insert(‘ChallengeDates’, dataInsert)
.then(result => ok({body: JSON.stringify(result)}))
. catch (err => response({status: 501, body: err}));
}
);
}

$w(‘ChallengeDates’).onRowSelect( (event) => {
let rowData = event.rowData;
console.log(rowData);
//wixLocation.to(rowData.imageUrl);
});

Now I am trying to send a message using Integromat using this format:

when sending the JSON to the site I get a 500 error

When looking at the log I get this message:

tails"root": { “insertId”:“f10f4225-5aea-4d8f-bc34-b8519836b93b”“timestamp”:“2019-10-23T15:07:05.257Z”“labels”: { “siteUrl”:“https://www.beitlali.com/_functions/tabledata”“revision”:“2568"“namespace”:“Corvid”“tenantId”:“f55db345-61ca-481c-a65a-1b39e5dc29ec”“viewMode”:“Site” } “sourceLocation”: { “file”:“backend/http-functions.js”“line”:24"column”:3 } “operation”: { “id”:“1571843225.2086912017012469"“producer”:“backend” } “jsonPayload”: { “message”:”[“Error loading web module backend/http-functions.js: $w is not defined”]" } “severity”:“ERROR”“receiveTimestamp”:“2019-10-23T15:07:05.517Z” }

Can anyone please assist with figuring out what am I doing wrong?
Thanks so much!
Lior

anyone?

Database Field Key and Field Name is different. The DiscountPercent you are using is probably discountPercent with a lowercase alphabet in the beginning.

Try this code in your ’ http-functions.js ’ backend file

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

export function post_tabledata(request) {
 let options = {
 "headers": {
 "Content-Type": "application/json"
        }
    };
 return request.body.json()
    .then( (body) => {
 return createLine(body, options);
    })
    .catch( (error) => {
        options.body = {
 "error": error
        };
 return serverError(options);
    });
}

function createLine(body, options) {
 let dataInsert = {
 "date": body.Date,  
 "discountPercent": body.DiscountPercent,    
 "discountDueDate": body.DiscountDueDate,
 "fullPrice": body.FullPrice,
 "discountedPrice": body.DiscountedPrice,
 "buttonURL": body.ButtonURL 
    };
 return wixData.insert('ChallengeDates', dataInsert)
    .then( (result) => {
 let item = result;
        options.body = {
 "status": 200,
 "response": item
        };
 return created(options);
    });
}

And remove the following code

$w('ChallengeDates').onRowSelect( (event) => {  let rowData = event.rowData;         console.log(rowData);  //wixLocation.to(rowData.imageUrl);     }); 

This above code should be in the page only.

Shan, you are the man! issue is solved
Thanks so much!
Lior