Reputation: 27257
I'm trying to update a field of an entry in contentful, but this error is thrown each time:
java.lang.IllegalArgumentException: entry must have a space associated. at com.contentful.java.cma.AbsModule.getSpaceIdOrThrow(AbsModule.java:87) at com.contentful.java.cma.ModuleEntries.update(ModuleEntries.java:345) at com.contentful.java.cma.ModuleEntries$Async$14.method(ModuleEntries.java:700)
I am building the client and providing the spaceId:
@Bean
CMAClient cmaClient() {
return new CMAClient.Builder()
.setAccessToken(contentManagementToken)
.setSpaceId(spaceId)
.setEnvironmentId("master")
.build();
}
and this is where the error is being thrown:
CMAEntry entry = new
CMAEntry().setSystem(sys)
.setId(response.items().get(i).id())
.setField("questionText", "en-US", question.getQuestionText()));
cmaClient.entries().update(entry);
If I do set the space id for the entry like this:
CMAEntry entry = new CMAEntry().setSystem(sys)
.setId(response.items().get(i).id())
.setSpaceId(spaceId)
.setField("questionText", "en-US", question.getQuestionText());
cmaClient.entries().update(entry);
I get a different error message:
FAILED ErrorBody { details = Details { errors = [Error { details = The property "space" is not allowed here., name = unknown,....
I've turned the Internet upside down to find a solution to this and documentation for Java doesn't provide a solution.
Upvotes: 0
Views: 87
Reputation: 27257
Okay so I was doing it all "wrong".
I had read somewhere in the documentation that when updating an entry, you need to provide all the fields for that entry else the missing fields would be deleted. With that in mind, I tried to build the entry with a local entry (from a local db) hence the missing parameters.
To update an entry, you need to retrieve that entry by its ID, edit the field you need to and then save it.
All I had to do was:
final CMAEntry entry =
cmaClient.entries()
.fetchOne(response.items().get(i).id());
entry.setField("saved", "en-US", true);
cmaClient.entries().update(entry);
Upvotes: 0