Hi @dennisedson ,
Yes, I didn’t send all but keep the main function I used on the different part(vue.js and serverless)
Vue js part:
mounted(){
let requestRowToDelete =
“https://api.hubapi.com/cms/v3/hubdb/tables/xxxxxxx/rows?hapikey=” +APIKEY ;
;
axios.all([requestRowToDelete, requestRowToUpdate])
.then(axios.spread((…responses) => {
this.dataToDeleteJson= responses[0].data.results;
}
var dataToDeleteString = “”;
for (const dataof this.dataToDeleteJson){
dataToDeleteString += '"' + data.id + '",';
}
dataToDeleteString = dataToDeleteString.slice(0, -1));
this.dataToDeleteFormatted = dataToDeleteString;
},
methods: {
onUpdate: function(){
const data = {
"inputs": this.dataToDeleteFormatted
};
const requestOptions = {
'method': 'POST',
'headers': {
'Content-Type': "application/json",
},
"body": JSON.stringify(data),
};
fetch("/\_hcms/api/delete-rows-batch", requestOptions)
.then(response => response.text())
.then(result =>{
var parsedResult = JSON.parse(result);
console.log(result);
}
})
.catch(error => console.log('error update', error));
},
serverless.json
{
“runtime”: “nodejs12.x”,
“version”: “1.0”,
“environment”: {},
“secrets”: [“API_KEY”],
“endpoints”: {
“delete-rows-batch”: {
“method”: “POST”,
“file”: “delete-rows-batch.js”
},
And finally the delete-rows-batch.js function:
// Require axios library to make API requests
const axios = require(‘axios’);
// This function is executed when a request is made to the endpoint associated with this file in the serverless.json file
exports.main = ({ body }, sendResponse) => {
const apikey = process.env.API_KEY;
let requestBody = {};
requestBody[“inputs”] = body.inputs;
const API_HUBDB_BASE = ‘https://api.hubapi.com/cms/v3/hubdb/tables/xxxxxxx/rows/draft/batch/purge’;
const DELETE_TABLE_API_URI =
API_HUBDB_BASE + ‘?hapikey=’ + apiKey;
// Use axios to make a delete request to the API
axios
.post(DELETE_TABLE_API_URI, requestBody)
.then(function(response) {
console.log(‘HubDB rows deleted’);
console.log(response.data);
console.log(response.status);// sendResponse is what you will send back to services hitting your serverless function
sendResponse({
body: {
response: ‘Delete Successful’,
success: true
},
statusCode: 200,
});
})
.catch(function(error) {
// Handle error
console.log(‘Failed to delete HubDB rows data’);
console.log(error.response.data);
console.log(error.response.status);
sendResponse({
body: {
error: error.message,
success: false
},
statusCode: 500 });
});
};