Open ChazUK opened 1 year ago
You've probably already figured it out, but for anyone else who has this question, the types files are a good source of documentation. You can start with the PlainClientAPI
type (node_modules/contentful-management/dist/typings/plain/common-types.d.ts
) to see what methods to use, what their required arguments are, and what they return, and then follow the types trail to get additional information.
For example, by looking at the PlainClientAPI
type and the entry
property, you can see that we have methods like create()
and publish()
, and what arguments we need to provide to use them:
const newBook = await cmaClient.entry.create(
{ contentTypeId: "book" },
{
fields: {
author: { "en-US": "Dr. Seuss" };
title: { "en-US": "Cat in the Hat" };
}
}
);
await cmaClient.entry.publish({ entryId: newBook.sys.id }, newBook);
I agree they're a start, but can also be dense.
The above did not work for me, but was a great start. I had to explicitly set the environment params, so for your example the first object needed to consist of the spaceId
,environmentId
, and contentTypeId
. Posting here in case someone else spends ages stumbling through this.
I've been trying to use the API to manage an import from another site but am having trouble finding documentation for the plain API. Is there any? All I can find is the then chaining examples.