Contentful logo

Contentful Community

Creating entry with associated resource specified

Alright, so I have two content models. For this example one is an ‘Instructor’ and the other is a ‘Practitioner’. So, a practitioner holds a reference to a set of instances of an instructors. I want to create an instance of a practitioner and specify this relationship. It’s not clear in the API documentation how to do this.

So, I thought maybe I’d follow the JSON structure seen when performing a GET on Practitioner. That doesn’t work however. I get a non-descript error.

Please advise!

Have you created the content types you describe? Is there a multi reference field on the practitioner for the instructors?

Have you created entries of both the practitioner and instructor content types?

Are you creating the entries using the web app or solely via the API?

Hi Charlie,

So, I had screenshots to share showing the details of the answers to all your questions! However, Discourse would only let me upload one and not more and it felt out of context to just have one.


Have you created the content types you describe?

YES


Is there a multi reference field on the practitioner for the instructors?

YES


Have you created entries of both the practitioner and instructor content types?

YES - only through the web CMS interface but with these references specified pointing to other existing entities.


Are you creating the entries using the web app or solely via the API?

I can create an entry via the API if I don’t include the reference.

------- OK, what I believe I need ------

Is just an example of a JSON structure for a CREATE post of an entity that include a reference to another existing entity. Is that anywhere in your documentation?

I haven’t been able to find it. I can also add the screenshots I mentioned if you can change my Discourse profile to allow it.

Thank you!

1 Like

I resolved this by bringing in the ‘en-US’ for the key to the array.

Sounds like you got it figured out but just for reference and for anyone who might find this page on the future, here is the documentation on references or links: https://www.contentful.com/developers/docs/concepts/links/

Just a heads up Charlie… that documentation doesn’t cover the CREATE call and the JSON structure that’s expected. What threw me off was the still specifying a key of ‘US-en’ even when you’re pointing to an array as a value. Initially looking at the documentation… I thought that was only required for string values. (That’s how I’ve worked with localization in the past.

Here’s my JSON that got it working:

Thanks Julie, this is what I was looking for. I feel missing the documentation on how to write JSON for the createEntry()