The Contentful documentation is pretty sparse. I want to update a field on an entry that is a Link to another entry ("Reference" is what they call it in the CMS UI).
Does anyone know what format they want this in when using the Contentful Management API?
type ||= @mgmt.content_types.find(
ENV['CONTENTFUL_SPACE_ID'], 'comments'
)
entry = type.entries.create(
title: params[:title],
article: params[:article]
)
Where :article
is the entry ID as a string. This returns:
undefined method `id' for "7L4IpEtsdffds8EsmoWMGIgy":String
Extracted source (around line #74):
#72 case field.type
#73 when ContentType::LINK then
*74 { sys: { type: field.type, linkType: field.link_type, id: attribute.id } } if attribute
#75 when ContentType::ARRAY then
#76 parse_fields_array(attribute)
#77 when ContentType::LOCATION then
I've also tried to replace params[:article]
with @client.entry(params[:article])
thinking they may want the whole object but it returns the same error only it sees the same argument as an empty string.
I have also tried this upon @DavidLitvak's suggestion:
link = Contentful::Management::Link.new({
sys: {
type: 'Link',
linkType: 'Entry',
id: params[:article]
}
})
entry = type.entries.create(
title: params[:title],
article: link
)
And although this does not throw an error, the article field shows up without an entry while the title field is populated.
Also note that I am using the Ruby gem: contentful-management
.