Hi Yisrael,
Thanks for your response,
Defining a Goal for the API:
I took a look into how the results are supposed to be shown (JSON) from the external API. I attach the response of how the response should look like in the following code snippet. It creates one {} section for each specific appointment (in the below code block, there are two appointments), each appointment has a staff member assigned to it, the staff members are also displayed in my database called 'alloperations '.
[
{
"id": "dcd17f240492adff",
"title": "Half Day Laguna Madre Fishing Trip",
"client_id": "396ls8lh0yv4ehXX",
"staff_id": "thfa1bzg4qjmsnXX",
},
{
"id": "e1aee88d4921851d",
"title": "Half Day Laguna Madre Fishing Trip",
"client_id": "3e3c6lpt76npsrXX",
"staff_id": "thfa1bzg4qjmoyXX",
}
]
My objective is getting all the “staff_id” tags from each specific appointment (section of response) and then filtering them against my existing dataset (connected to my database) using the Wix API ‘not’ function to filter out the previously mentioned “staff_id” tags from the dataset.
Essentially, what I’m trying to achieve, is filtering out anyone (any item in the database) who has a specific appointment already assigned to them.
In three “simple” steps:
- Making the API call
- Get all “staff_id” tags from the JSON response of API call.
- Filter (cross filtering-like) using ‘not’ function to filter out any “staff_id” (staff member) that appears in the previous API call response from the dataset.
I browsed over a lot of information here on the forum, the API reference and StackOverflow and so on and so forth, as well as trying out a couple of ideas, but just couldn’t figure out how to complete the program that I have right now.
import {fetch} from 'wix-fetch';
export function box65_click(event, $w) {
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
return [year, month, day].join('-');
}
var updated_until = formatDate($w("#datePicker6").value);
var updated_since = formatDate($w("#datePicker5").value);
const call = {
url: 'https://api2.vcita.com/v2/appointments' + '?' + 'updated_since' + '=' + updated_since + 'T00:00:00.000+8:00' + '&' + 'updated_until' + '=' + updated_until + 'T00:00:00.000+8:00',
headers: {
'Authorization': 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
}
};
console.log(call);
return fetch(call, {
method: 'get'
})
.then(response => response.json());
}
I appreciate any help I can receive regarding this matter, and would really appreciate anyone’s help!
Thank you,
Sincerely!