Ember Data 2.4 with new JSON:API specification

Trying to call an API that is returning me JSON. I am getting the following error

Error while processing route: treatment Assertion Failed: normalizeResponse must return a valid JSON API document:
	* One or more of the following keys must be present: "data", "errors", "meta". Error: Assertion Failed: normalizeResponse must return a valid JSON API document:
	* One or more of the following keys must be present: "data", "errors", "meta".

Is there a way in Ember to get around this or do I need to have the API team change the way the JSON response is coming back? Thanks

1 Like

You can change your application adapter to expect REST instead:

DS.RESTAdapter

If not, you’ll have to stick with JSON API. You can read http://jsonapi.org/ to learn more.

3 Likes

So I changed adapters/application.js to the following:

import DS from 'ember-data';

export default DS.RESTAdapter.extend({
  namespace: 'Service.svc'
});

I am still getting the same error

1 Like

That’s weird. We’re using the latest Ember and Ember Data in a project using REST without any trouble, and those error’s clearly point to the JSON not being conform JSON API.

Can you post what the server response looks like when you hit the API directly?

Here is a sample

{
  "ArgumentErrors": null,
  "ErrorCode": 0,
  "ErrorMessage": null,
  "IsSuccess": true,
  "Services": [
     {
        "AllowCustomers": true,
        "Name": "John Smith Service"
     },
    {
        "AllowCustomers": false,
        "Name": "John Apples Service"
    }
  ]
}

Do you have any Model specific Adapters defined (and its type JSONAPIAdapter) ???

Does that fit the format the REST adapter expects as described here?

So I had to serialize the return coming in the API after switching to a REST adapter. Thanks