using Newtonsoft.Json.Linq;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.Collections.Generic;
const string clientId = "your-clientId";
const string familyName = "your-familyName";
const string qpushmeName = "your-qpush-name-here";
const string qpushcode = "your-qpush-code-here";
const string baseAddress = "https://rebooking.appointments.api.cp1.homeaffairs.gov.au/v1/";
const string qpushBaseAddress = "https://qpush.me/pusher/";
public static async Task Main()
var login = await Login.LogMeIn(clientId, familyName);
var tomorrow = DateTime.Today.AddDays(1).ToString("yyyy-MM-dd");
var currentAppointment = login.Appointments.FirstOrDefault();
var appointmentDay = currentAppointment.AppointmentDate.ToString("yyyy-MM-dd");
var availability = CheckForAvailability.Check(login.token, tomorrow, appointmentDay, currentAppointment.AppointmentID);
if (availability != null)
var message = $"Found a day {availability.Day.ToString("yyyy-MM-dd")} available({availability.Availability.available_times_count}): {string.Join(",", availability.Availability.times)}";
Push.SendPush(message, qpushmeName, qpushcode);
public static class CheckForAvailability
public static AvailabilityResult Check(string token, string tomorrow, string appointmentDay, string appointmentId)
var client = new HttpClient();
client.BaseAddress = new Uri(baseAddress);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var url = $"calendars?AppointmentID={appointmentId}&FromDate={tomorrow}&ToDate={appointmentDay}";
var response = client.GetAsync(url).Result;
var results = response.Content.ReadAsStringAsync().Result;
JObject parsedResults = JsonConvert.DeserializeObject<JObject>(results);
foreach (var result in parsedResults)
var day = DateTime.Parse(result.Key);
var availability = JsonConvert.DeserializeObject<Availability>(result.Value.ToString());
if (availability.available_times_count > 0)
return new AvailabilityResult{Day = day, Availability = availability};
public class AvailabilityResult
public DateTime Day { get; set; }
public Availability Availability { get; set; }
public DateTime Day { get; set; }
public Availability Availability { get; set; }
public class Availability
public int available_times_count { get; set; }
public string[] times { get; set; }
public string token { get; set; }
public Appointments[] Appointments { get; set; }
public static async Task<Login> LogMeIn(string clientId, string familyName)
var creds = JsonConvert.SerializeObject(new Creds()
{clientId = clientId, familyName = familyName});
var stringContent = new StringContent(creds, Encoding.UTF8, "application/json");
var client = new HttpClient();
client.BaseAddress = new Uri(baseAddress);
var response = await client.PostAsync(url, stringContent);
var results = await response.Content.ReadAsStringAsync();
var login = JsonConvert.DeserializeObject<Login>(results);
public static void SendPush(string msg, string name, string code)
var client = new HttpClient();
client.BaseAddress = new Uri(qpushBaseAddress);
var dict = new Dictionary<string, string>()
{{"name", name}, {"code", code}, {"msg[text]", msg}};
var formContent = new FormUrlEncodedContent(dict);
var result = client.PostAsync("push_site/", formContent).Result;
public class Appointments
public Venue Venue { get; set; }
public string AppointmentID { get; set; }
public string AppointmentType { get; set; }
public DateTimeOffset AppointmentDate { get; set; }
public string Address { get; set; }
public string clientId { get; set; }
public string familyName { get; set; }