Contentful logo

Contentful Community

Check if content type exists?

Hi!
Im doing this:
const cte = await environment.getContentType(‘input’);
if (cte) {
console.log(‘actions’);
}
To see if a content type exists, but I’m getting an error 400 because it doesn’t exists
Do you know how could this be done ? without getting error ?

Thanks!! :slight_smile:

RESOLVED

await environment
.getContentType(‘input’)
.then(response => {
return response.unpublish();
})
.then(response => {
return response.delete();
})
.catch(err => console.log(‘No content type found…’));

Just in case someone need it.