Only GET requests work after update to 2.1

Hi there

I am having some major issues after updating to version 2.1. I can only make GET requests.

Any POST or PUT request returns: “No record(s) detected in request.” error code 400 - these are the same requests that worked before the update many times.

I get the same error when using an external tool or the API Docs…

All GET requests return as normal.

I am using MySQL as the DreamFactory database and as the service database.

On the API Docs page I get an error: "{“schemaValidationMessages”:[{“level”:“error”,“message”:“Can’t read from file http://api.**********.co.za/api/v2/api_docs”}]}"
I am not sure if this is at all related

Any help with this would be much appreciated.

edit: I did make a backup of my htdocs before the update however my attempt to go back to it was not fruitful

edit 2: I have now managed to POST to my API again but I am not sure if its working as desired. Before I was able to send the request raw body as:
{
“title”: “Test title”,
“content”: “some content”
}

Now I am only able to post if the format is like this:
{
“resource”: [
{
“title”: “Test tile”,
“content”: “some content”
}
]
}

Is there anything I can do to get the original way to work again? I would like my application to work again before I can make the change throughout… Thanks in advance

I got my backup to work but I am still a bit confused about the change in required format. Not sure if that is how it is meant to be or if I just did something stupid :slight_smile:

You know, after upgrading to 2.1 I also had to rewrite some of my scripts (all of them, actually). The need of a nested “resource”:[] array is something I noticed, although I didn’t see any warning about this change anywhere in the wiki but in swagger docs. This is why you got the “No records detected in request” error.

Now the correct way to pass parameters is to include them in a “resource” array.

2 Likes

Cool, thanks for the info!

I’m also going to need to rewrite some scripts

Were you able to figure out why you are getting the ’ http://api.**********.co.za/api/v2/api_docs’ error?

I am getting the same error on a fresh bitnami install and when upgrading from 2.0 to 2.1.

Another set of users is getting the same error, but the resolution was installing V8JS. I have installed two different versions, and haven’t had any luck.

Same error Post:

Hi lftc

Yes, I was able to POST to the server and get proper responses if I wrapped the post body in a resource array.

Like this: {“resource”: [{“title”: “Test”}]}

Instead of this: {“title”: “Test”}

This also happened to me. Thanks guys for figuring it out.

I also had to rewrite my scripts. One thing that helped was including var_dump(event) to review the new object and object array structures around the request and response to see what had changed.

1 Like

I found that I could use the following function and reference it in the create() for each factory resource.

function wrapResource(data){        
    switch(typeof(data)){
        case "string":
            return '{"resource": '+data+'}';
            break;
        case "object":
            var d = angular.isArray(data) ? data : [data];
            angular.forEach(d,function(value, key){
                if (value.id === null || value.id === ""){
                    //console.log("found null id");
                    delete value.id;
                }
            });
            return '{"resource": '+angular.toJson(d)+"}";
            break;
    }
    return data;
}

Then in the factory, include this function as the transformRequest:

// Contacts factory to fetch contacts data from dreamfactory services.
.factory('Contacts', [
    '$resource',

    function ($resource) {
        return $resource('/api/v2/db/_table/contact/:id', { id: '@id' }, {
            query: {
                method: 'GET',
                isArray: false
            },
            create: {
                method: 'POST',
                transformRequest: wrapResource       // <<<<<<<<< added just this line
            },
            update: {
                method: 'PUT'
            },
            remove: {
                method: 'DELETE'
            }
        });
    }
])