ShortQuery help needed

For requests or help with our API
Post Reply
osjaved
Posts: 9
Joined: Wed Sep 17, 2025 7:55 pm

ShortQuery help needed

Post by osjaved »

I am using PUT ShortQuery: https://api.opendental.com/api/v1/queries/ShortQuery

The following query does not return any results beyond 2020-09-26:
"SqlCommand": "SET @FromDate= '2020-04-29', @ToDate='2026-04-31'; select a.AptDateTime, p.FName, p.WirelessPhone FROM appointment a INNER JOIN patient p ON p.PatNum=a.PatNum WHERE a.AptDateTime BETWEEN @FromDate AND @ToDate"

I need it to return data in future i.e. pull patients with upcoming appointments (and not in the past)

So this does not return any results although there are appointments on 4/29/2026
"SqlCommand": "SET @FromDate= '2026-04-29', @ToDate='2026-04-31'; select a.AptDateTime, p.FName, p.WirelessPhone FROM appointment a INNER JOIN patient p ON p.PatNum=a.PatNum WHERE a.AptDateTime BETWEEN @FromDate AND @ToDate"

Can someone help with that please?

Thanks
Tom Zaccaria
Posts: 366
Joined: Mon Feb 25, 2008 3:09 am

Re: ShortQuery help needed

Post by Tom Zaccaria »

Use this in place of your from and to dates and just change the number of days you want to search past and present.

drtmz

(DATE(a.AptDateTime) BETWEEN curdate() AND curdate() +interval 10 day)
OR
(DATE(a.AptDateTime) BETWEEN curdate() AND curdate() -interval 10 day)
osjaved
Posts: 9
Joined: Wed Sep 17, 2025 7:55 pm

Re: ShortQuery help needed

Post by osjaved »

I tried that. It still does not pull appointments and patients (although there is an appointment on 4/29)
OD.jpg
OD.jpg (149.13 KiB) Viewed 1807 times
Tom Zaccaria
Posts: 366
Joined: Mon Feb 25, 2008 3:09 am

Re: ShortQuery help needed

Post by Tom Zaccaria »

Take 2:

select a.AptDateTime, p.FName, p.WirelessPhone
FROM appointment a
INNER JOIN patient p ON p.PatNum=a.PatNum WHERE
(DATE(a.AptDateTime)
BETWEEN Curdate()+Interval 2 Day AND Curdate()+Interval 2 Day) AND a.AptStatus IN (1,2,4)

You will have to manipulate the interval days.

drtmz
justine
Posts: 355
Joined: Tue Dec 28, 2021 7:59 am

Re: ShortQuery help needed

Post by justine »

osjaved wrote: Sat Apr 25, 2026 6:25 pm I am using PUT ShortQuery: https://api.opendental.com/api/v1/queries/ShortQuery

The following query does not return any results beyond 2020-09-26:
"SqlCommand": "SET @FromDate= '2020-04-29', @ToDate='2026-04-31'; select a.AptDateTime, p.FName, p.WirelessPhone FROM appointment a INNER JOIN patient p ON p.PatNum=a.PatNum WHERE a.AptDateTime BETWEEN @FromDate AND @ToDate"

I need it to return data in future i.e. pull patients with upcoming appointments (and not in the past)

So this does not return any results although there are appointments on 4/29/2026
"SqlCommand": "SET @FromDate= '2026-04-29', @ToDate='2026-04-31'; select a.AptDateTime, p.FName, p.WirelessPhone FROM appointment a INNER JOIN patient p ON p.PatNum=a.PatNum WHERE a.AptDateTime BETWEEN @FromDate AND @ToDate"

Can someone help with that please?

Thanks
Hello osjaved,

Your query is likely invalid because April 31st isn't a real day.

You could try something like this:

Code: Select all

SELECT
  a.AptDateTime,
  p.FName,
  p.WirelessPhone
FROM appointment a
INNER JOIN patient p
  ON p.PatNum = a.PatNum
WHERE a.AptDateTime >= '2026-04-29 00:00:00'
  AND a.AptDateTime <  '2026-04-30 00:00:00'
ORDER BY a.AptDateTime;
Thanks!
osjaved
Posts: 9
Joined: Wed Sep 17, 2025 7:55 pm

Re: ShortQuery help needed

Post by osjaved »

Tried this one and still getting the same result
OD2.jpg
OD2.jpg (194.68 KiB) Viewed 1532 times
osjaved
Posts: 9
Joined: Wed Sep 17, 2025 7:55 pm

Re: ShortQuery help needed

Post by osjaved »

Tried this one but still can't get results
Tom Zaccaria wrote: Mon Apr 27, 2026 6:35 am Take 2:

select a.AptDateTime, p.FName, p.WirelessPhone
FROM appointment a
INNER JOIN patient p ON p.PatNum=a.PatNum WHERE
(DATE(a.AptDateTime)
BETWEEN Curdate()+Interval 2 Day AND Curdate()+Interval 2 Day) AND a.AptStatus IN (1,2,4)

You will have to manipulate the interval days.

drtmz
RyanH
Posts: 69
Joined: Thu Dec 19, 2024 8:33 am

Re: ShortQuery help needed

Post by RyanH »

osjaved wrote: Mon Apr 27, 2026 3:16 pm Tried this one and still getting the same result
OD2.jpg
Hello osjaved,

Have you double checked that the authorization header is the same on both requests? It looks like the /appointments GET request has 8 headers, while the /queries/ShortQuery PUT request has 10 headers. After confirming that, can you test the result from the following command?

Code: Select all

SELECT AptDateTime from appointment WHERE AptNum=279;
osjaved
Posts: 9
Joined: Wed Sep 17, 2025 7:55 pm

Re: ShortQuery help needed

Post by osjaved »

Yes it was the incorrect header that was causing it. It works now. Thank you!
Post Reply