Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

contentful-management

Package Overview
Dependencies
Maintainers
6
Versions
590
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contentful-management

Client for Contentful's Content Management API

  • 11.39.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
504K
decreased by-3.13%
Maintainers
6
Weekly downloads
 
Created

What is contentful-management?

The contentful-management npm package is a JavaScript client for the Contentful Content Management API. It allows developers to manage content, assets, and other resources within a Contentful space programmatically.

What are contentful-management's main functionalities?

Create an Entry

This code sample demonstrates how to create a new entry in a Contentful space. You need to provide your access token and space ID, and specify the content type and fields for the new entry.

const contentfulManagement = require('contentful-management');

contentfulManagement.createClient({
  accessToken: 'your-access-token'
}).then(client => {
  return client.getSpace('your-space-id')
    .then(space => space.createEntry('contentType', {
      fields: {
        title: {
          'en-US': 'Hello, World!'
        }
      }
    }))
    .then(entry => console.log(entry))
    .catch(console.error);
});

Update an Entry

This code sample shows how to update an existing entry in a Contentful space. You need to provide your access token, space ID, and the ID of the entry you want to update. The example updates the title field of the entry.

const contentfulManagement = require('contentful-management');

contentfulManagement.createClient({
  accessToken: 'your-access-token'
}).then(client => {
  return client.getSpace('your-space-id')
    .then(space => space.getEntry('entry-id'))
    .then(entry => {
      entry.fields.title['en-US'] = 'Updated Title';
      return entry.update();
    })
    .then(entry => console.log(entry))
    .catch(console.error);
});

Delete an Entry

This code sample demonstrates how to delete an entry from a Contentful space. You need to provide your access token, space ID, and the ID of the entry you want to delete.

const contentfulManagement = require('contentful-management');

contentfulManagement.createClient({
  accessToken: 'your-access-token'
}).then(client => {
  return client.getSpace('your-space-id')
    .then(space => space.getEntry('entry-id'))
    .then(entry => entry.delete())
    .then(() => console.log('Entry deleted'))
    .catch(console.error);
});

Upload an Asset

This code sample shows how to upload an asset to a Contentful space. You need to provide your access token, space ID, and the path to the file you want to upload. The example also processes and publishes the asset.

const contentfulManagement = require('contentful-management');
const fs = require('fs');

contentfulManagement.createClient({
  accessToken: 'your-access-token'
}).then(client => {
  return client.getSpace('your-space-id')
    .then(space => space.createAssetFromFiles({
      fields: {
        title: {
          'en-US': 'My Asset'
        },
        file: {
          'en-US': {
            contentType: 'image/jpeg',
            fileName: 'my-asset.jpg',
            file: fs.createReadStream('path/to/your/file.jpg')
          }
        }
      }
    }))
    .then(asset => asset.processForAllLocales())
    .then(asset => asset.publish())
    .then(asset => console.log(asset))
    .catch(console.error);
});

Other packages similar to contentful-management

FAQs

Package last updated on 21 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc