Adonis request methods failing


I came across an issue where for some reason the request.body, request.all(), request.only() wouldn’t work for a POST request. The only request method that works is request.raw(). This happened after a push to git and this is my code:

async createBilling({ request, auth, response }) {
        POST: v1/tickets/billing
        creates a billing ticket
        try {
            let ticketRawData = request.raw()
            let ticketData = JSON.parse(ticketRawData); 
            const user = await auth.getUser()
            const rules = {
                invoice_date: 'required',
                description: 'required'

            let validation = await validateAll(ticketData, rules);
            if (validation.fails()) {
                return response.status(400).json({error: "Data missing"});

Whenever I do ticketData = request.body or ticketData.only(['someField', 'someOtherField']) the data isn’t there. Event when I console.log(request); the body, all() methods are empty.

Any reason why all these methods would just stop working?



I tired your codes in my local environment but everything is looking right. Can you provide more information to us such as routes.js.

1 Like