Streaming live at 10am (PST)

Order API Date Filter

Hi community,

Can anyone please check the following query:

Is there any way to fetch the orders between timestamps, suppose I want to fetch the since March 2020 to till now.

Imagine I have thousands of orders and I only want to fetch order for the last 2 days. If I use the following API, I will have to first fetch all orders then will be filtering these orders based on the dates. That doesn’t sound good thing
https://developers.webflow.com/#get-all-orders

Thanks
Sumit Khunger

Since you’re already working with the API, I can suggest you to create a small DB (Maybe mongo or even Firebase) to keep track of those orders and add a server timestamp to them, so you can then query your Database passing those parameters

Hi @Jeandcc

Thanks for the response,
doing this stuff doesn’t seem to be good, It would have been good if we can pass the date timestamps(start/end date) and API can give us the expected response :slight_smile:

You’re right man, but there’s nothing I can do but to suggest a different approach while they don’t improve that specific part of the API.

Unfortunately I don’t develop for the Webflow team (I would love tho, even sent a resume a while ago…).

Let me know if you want to try something else and I can give you my 2 cents on the idea

1 Like

Hi @Jeandcc

I liked your response, I was considering you as the WebFlow APIs developer but you are very smart, You answered my query and also let other know about your willingness :sweat_smile:

1 Like

haha thanks @Sumit_Khunger! I love the platform and helping others with it, so working with them would actually be great.

I’ll be around if you need something

If anyone from Webflow staff shows up here, I realized you guys could do something similar to this:

interface request {
  body: {
    startAt?: string;
    endAt?: string;
  };
}

interface mongoFilter {
  acceptedOn?: {
    $gte?: number;
    $lte?: number;
  };
}

function sampleHttp(req: request, res) {
  // Mongo's order model
  const OrderModel = {
    find: (filterObj): any => {},
  };

  const filterObj: mongoFilter = {};

  const { startAt, endAt } = req.body;

  if (startAt) {
    const startDate = new Date(startAt);
    const epochMsTime = startDate.getTime();

    // Checks validity of the date obj
    if (!isNaN(epochMsTime)) filterObj.acceptedOn.$gte = epochMsTime;
  }
  if (endAt) {
    const endDate = new Date(startAt);
    const epochMsTime = endDate.getTime();

    // Checks validity of the date obj
    if (!isNaN(epochMsTime)) filterObj.acceptedOn.$lte = epochMsTime;
  }

  const query = OrderModel.find(filterObj);

  query.exec((err, docs) => {
    if (err) return res.status(500).json({ error: err.message });
    return res.status(200).json({ docs });
  });
}