const OCCASION_ENDPOINT = 'https://fp.trafikverket.se/boka/occasion-bundles' const OCCASION_TEMPLATE = { "bookingSession": { "socialSecurityNumber": "", "licenceId": 4, "bookingModeId": 0, "ignoreDebt": false, "ignoreBookingHindrance": false, "examinationTypeId": 0, "excludeExaminationCategories": [], "rescheduleTypeId": 0, "paymentIsActive": true, "paymentReference": null, "paymentUrl": null, "searchedMonths": 0 }, "occasionBundleQuery": { "startDate": "1970-01-01T00:00:00.000Z", "searchedMonths": 0, "locationId": 1000060, "nearbyLocationIds": [], "languageId": 13, "vehicleTypeId": 1, "tachographTypeId": 1, "occasionChoiceId": 1, "examinationTypeId": 50 } } // "nearbyLocationIds": [1000121, 1000302, 1000047, 1000009, 1000096, 1000122, 1000066, 1000139, 1000077, 1000138, 1000317, 1000123, 1000069, 1000334, 1000106, 1000103, 1000012, 1000078, 1000318, 1000038, 1000005, 1000087, 1000130, 1000144], async function getOccasionEndpoint(req, res) { // Check for the required parameters if (!req.body || !req.body.licenceId || !req.body.ssn || !req.body.locationId || !req.body.examType) { res.status(400).json({ message: 'Missing required parameters' }); return; } let ssn = req.body.ssn; let licenceId = req.body.licenceId; let locationId = req.body.locationId; let nearbyIds = req.body.nearbyIds; let examType = req.body.examType; if (!locationId.length > 0) { res.status(400).json({ message: 'Missing required parameters' }); return; } let body = OCCASION_TEMPLATE body.bookingSession.socialSecurityNumber = ssn body.bookingSession.licenceId = licenceId body.occasionBundleQuery.locationId = locationId body.occasionBundleQuery.nearbyLocationIds = nearbyIds body.occasionBundleQuery.examinationTypeId = examType console.log(body) let response = await fetch(OCCASION_ENDPOINT, { method: 'POST', headers: { 'Content-Type': 'application/json', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36' }, body: JSON.stringify(body), }) if (!response.ok) { res.status(500).json({ message: 'Something went wrong' }); return; } let json = await response.json() // console.log(json) res.json(json) } module.exports = getOccasionEndpoint;