# Response does not have an id and your record does not either

**URL:** <https://discuss.emberjs.com/t/response-does-not-have-an-id-and-your-record-does-not-either/12951>\
**Category:** Ember Data\
**Created:** [May 8, 2017, 8:28pm UTC](https://discuss.emberjs.com/t/response-does-not-have-an-id-and-your-record-does-not-either/12951 "2017-05-08T20:28:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kamillacrozara](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/kamillacrozara/32/17149_2.png) [@kamillacrozara](https://discuss.emberjs.com/u/kamillacrozara)\
**Post date:** [May 8, 2017, 8:28pm UTC](https://discuss.emberjs.com/t/response-does-not-have-an-id-and-your-record-does-not-either/12951/1 "2017-05-08T20:28:41Z")

</div>

I’m working on a project with Ember and a Python back-end. At the back-end I’m working with the marshmallow-jsonapi to provide a JSON API-compliant response. At the ‘motoristas/new’ route I’m sending a POST request that gets as response an object with the response code and the following body:

```
{  
   'data':[  
      {  
         'id':'145',
         'attributes':{  
            'titulo-eleitor':'2132.1321.3213',
            'nome-mae':'asdasda',
            'identidade':'131231',
            'naturalidade':'Amapá',
            'cpf':'123.213.213-12',
            'enderecos':{  
               'data':[  
                  {  
                     'id':'112',
                     'attributes':{  
                        'estado':'AP',
                        'motorista-id':'145',
                        'cidade':'asdsadsa',
                        'logradouro':'asdsadsa',
                        'cep':'12.321-321',
                        'bairro':'asdasdsa'
                     },
                     'type':'enderecos_motorista'
                  }
               ]
            },
            'data-admissao':'2017-05-08T03:00:00+00:00',
            'nome':'asdsada',
            'nome-pai':'sdasdsa',
            'email':'holanda.kamilla@gmail.com',
            'pis-pasep':'212.32131.23-2',
            'cnh':{  
               'data':[  
                  {  
                     'id':'119',
                     'attributes':{  
                        'motorista-id':'145',
                        'categoria':'D',
                        'numero':'12321321321',
                        'data-vencimento':'2017-05-08 03:00:00'
                     },
                     'type':'cnh_motorista'
                  }
               ]
            },
            'matricula':'12312',
            'carteira-trabalho':'2312321321',
            'telefones':{  
               'data':[  
                  {  
                     'id':'111',
                     'attributes':{  
                        'motorista-id':'145',
                        'numero':'21313-1213',
                        'ddd':'111',
                        'tipo-telefone':'Residencial'
                     },
                     'type':'telefones_motorista'
                  }
               ]
            },
            'cargo-id':'131',
            'orgao-emissor-id':'SSPDF',
            'escolaridade':'Ensino Fundamental',
            'nome-conjuge':None,
            'estado-id':'130',
            'data-emissao-ct':'2017-05-08 03:00:00',
            'estado-civil':'Solteiro(a)',
            'conta-bancaria':{  
               'data':[  
                  {  
                     'id':'114',
                     'attributes':{  
                        'tipo-conta':'Conta Corrente',
                        'banco':'001',
                        'motorista-id':'145',
                        'agencia':'12321321',
                        'numero-conta':'21321321'
                     },
                     'type':'conta_bancaria_motorista'
                  }
               ]
            }
         },
         'type':'motoristas'
      }
   ]
}

```

But I’m getting this error message: **“Assertion Failed: ‘motorista’ was saved to the server, but the response does not have an id and your record does not either.”**

I’m using the JSONAPIAdapter since I’m supposed to get a JSON API format compliant response:

```
import DS from 'ember-data';
import Ember from 'ember';
import ENV from 'sistran-frontend/config/environment';

export default DS.JSONAPIAdapter.extend({
  namespace: ENV.APP.namespace,

  pathForType(modelName) {
    if (modelName === 'ordem-de-servico') {
      return 'ordens-de-servico';
    }

    if (modelName === 'veiculo') {
      return 'veiculos';
    }

    if (modelName === 'motorista') {
      return 'motoristas';
    }
  },
});

```

I’m not sure why I’m getting this message because I have the **id field** on the response. What is wrong with the response that I’m sending to the Ember app? I have the ‘motoristas/index’ route that gets the same response object with the same body format and It’s working.

---

<div class="post-metadata">

**Author:** ![nerdyworm](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/nerdyworm/32/3860_2.png) [@nerdyworm](https://discuss.emberjs.com/u/nerdyworm)\
**Post date:** [May 9, 2017, 8:04pm UTC](https://discuss.emberjs.com/t/response-does-not-have-an-id-and-your-record-does-not-either/12951/2 "2017-05-09T20:04:12Z")

</div>

The only hunch that I have is the response is returning a `data: []` when it should be returning a `data: {}`. Other than that everything looks about right… 😕

---

<div class="post-metadata">

**Author:** ![kamillacrozara](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/kamillacrozara/32/17149_2.png) [@kamillacrozara](https://discuss.emberjs.com/u/kamillacrozara)\
**Post date:** [May 10, 2017, 6:23pm UTC](https://discuss.emberjs.com/t/response-does-not-have-an-id-and-your-record-does-not-either/12951/3 "2017-05-10T18:23:41Z")

</div>

Thank you for your answer! Turns out it was an api problem. I was really returning an array. I just changed it to return only one registry and everything works fine now!

---

<div class="post-metadata">

**Author:** ![belgoros](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/belgoros/32/16101_2.png) [@belgoros](https://discuss.emberjs.com/u/belgoros)\
**Post date:** [April 10, 2018, 8:58am UTC](https://discuss.emberjs.com/t/response-does-not-have-an-id-and-your-record-does-not-either/12951/4 "2018-04-10T08:58:50Z")

</div>

I have the similar problem when using Rails 5 API on the backend. I also have the same data structure in post response:

```auto
{
	"data": [{
		"id": "419",
		"type": "languages",
		"attributes": {
			"tag": "ru-RU"
		}
	}, {
		"id": "374",
		"type": "languages",
		"attributes": {
			"tag": "nl-BE"
		}
	}, {
		"id": "245",
		"type": "languages",
		"attributes": {
			"tag": "fr-FR"
		}
	}]
}

```

And [JSONLint](https://jsonlint.com/) validates it with no problem. So, I don’t think it to be an API problem. Any other tips or solutions to fix it ? Thank you.

---

<div class="post-metadata">

**Author:** ![mattmcmanus](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/mattmcmanus/32/13776_2.png) [@mattmcmanus](https://discuss.emberjs.com/u/mattmcmanus)\
**Post date:** [April 10, 2018, 12:57pm UTC](https://discuss.emberjs.com/t/response-does-not-have-an-id-and-your-record-does-not-either/12951/5 "2018-04-10T12:57:10Z")

</div>

@belgoros What are you using for that model’s serializer? Either that specific model or your applications’s serializer looks like it needs to be JSONAPI. Here is more information in the docs: [Customizing Serializers - Models - Ember Guides](https://guides.emberjs.com/v3.0.0/models/customizing-serializers/)

---

<div class="post-metadata">

**Author:** ![belgoros](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/belgoros/32/16101_2.png) [@belgoros](https://discuss.emberjs.com/u/belgoros)\
**Post date:** [April 10, 2018, 1:25pm UTC](https://discuss.emberjs.com/t/response-does-not-have-an-id-and-your-record-does-not-either/12951/6 "2018-04-10T13:25:53Z")

</div>

I use [AMS](https://github.com/rails-api/active_model_serializers) gem. I returned an array from the Rails controller:

```auto
def create
    @shop.languages << @language
    json_response @shop.languages, :created
end

```

After changing to return a created language, it works as needed:

```auto
  def create
    @shop.languages << @language
    json_response @language, :created
  end

```

I have no custom serializer defined in Ember app.

---

<div class="post-metadata">

**Author:** ![mattmcmanus](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/mattmcmanus/32/13776_2.png) [@mattmcmanus](https://discuss.emberjs.com/u/mattmcmanus)\
**Post date:** [April 10, 2018, 2:32pm UTC](https://discuss.emberjs.com/t/response-does-not-have-an-id-and-your-record-does-not-either/12951/7 "2018-04-10T14:32:51Z")

</div>

That makes sense. Your `create`s should return a single model, not an array of them.
