crisp-im / node-crisp-api

:zap: Crisp API Node Wrapper
https://docs.crisp.chat/guides/rest-api/
MIT License
99 stars 39 forks source link

issue with filterDateStart and filterDateEnd #34

Closed spidIslem closed 2 years ago

spidIslem commented 2 years ago

the API list conversations with search is not reachebal from my code when using filter by date. The issue is related to time value when i omit it and work whith just date it works

eliottvincent commented 2 years ago

Hey there, could you please post a snippet of your code + the you're expecting and the results you actually have?

spidIslem commented 2 years ago

CrispClient.websiteConversations.findWithSearch(websiteId,0,{filterDateStart:"2021-09-01T07:50:14.395Z", filterDateEnd:"2021-09-11T07:50:14.395Z"}) .then(res=>console.log(res)) .catch(er=>console.log(er)) all data is returned, not only data that matches my filter, when i debug it, crisp add '%' in the time value and that is why it didn't work . when i try with only date value it works Le lun. 4 oct. 2021 à 22:47, Eliott Vincent @.***> a écrit :

Hey there, could you please post a snippet of your code + the you're expecting and the results you actually have?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/crisp-im/node-crisp-api/issues/34#issuecomment-933881664, or unsubscribe https://github.com/notifications/unsubscribe-auth/AV32CHVSWNKKIS4V36E3TQTUFIOITANCNFSM5FEF2EXQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

eliottvincent commented 2 years ago

Ok the thing is that there is no "search" in your request. You're basically searching for nothing. You must provide a searchQuery and searchType when using this method (remember, it's called findWithSearch 😉). Otherwise, the query will search for nothing and will ignore all filters as well (that's why your date filters are ignored).

For example, this code will return valid results:

CrispClient.websiteConversations.findWithSearch(websiteId, 0, {
  filterDateStart: "2021-09-11T07:50:14.395Z",
  filterDateEnd: "2021-09-29T07:50:14.395Z",
  searchQuery: "test",
  searchType: "text"
})
  .then((result) => {
    result.forEach(conversation => {
      console.log(conversation.session_id + " " + new Date(conversation.created_at));
    });
  })
  .catch(err => {
    console.log(err);
  });

Please have a look at the API reference for more information: https://docs.crisp.chat/api/v1/#website-website-conversations