Wastewater-based epidemiology is an innovative approach that uses the analysis of human excretion products in wastewater to obtain information about exposure to drugs in defined population groups. We developed and validated an analytical method for the simultaneous determination of opioids (morphine, oxycodone, hydrocodone, oxymorphone and hydromorphone), and cannabinoids (Δ9-tetrahydrocannabinol, 11-nor-9-carboxy-tetrahydrocannabinol (THCCOOH) and THCCOOH-glucuronide) in raw-influent wastewater samples by ultra-high performance liquid chromatography-tandem mass spectrometry. Method validation included linearity (5–1 000 ng/L for opioids, 10–1 000 ng/L for cannabinoids), imprecision (<21.2%), accuracy (83%–131%), matrix effect (from –35.1% to –14.7%) and extraction efficiency (25%–84%), limit of detection (1–5 ng/L) and quantification (5–10 ng/L) and auto-sampler stability (no loss detected). River and wastewater samples were collected in triplicate from different locations in New York City and stored at −20 °C until analysis. Water from sewage overflow location tested positive for morphine (10.7 ng/L), oxycodone (4.2–23.5 ng/L), oxymorphone (4.8 ng/L) and hydromorphone (4.2 ng/L). Raw influent wastewater samples tested positive for morphine (133.0–258.3 ng/L), oxycodone (31.1–63.6 ng/L), oxymorphone (16.0–56.8 ng/L), hydromorphone (6.8–18.0 ng/L), hydrocodone (4.0–12.8 ng/L) and THCCOOH (168.2–772.0 ng/L). This method is sensitive and specific for opioids and marijuana determination in wastewater samples.