debpu06 / gittalk-blog-comments

Stores comments for development blog via GitTalk
0 stars 0 forks source link

Contentful Most Frequently Asked Questions #34

Open debpu06 opened 2 years ago

debpu06 commented 2 years ago

https://davidboland.site/blog/contentful-most-frequently-asked-questions

There are many general questions that get asked over and over regarding Contentful. Since they keep getting asked, I figure the answers aren't the easiest to find online. This post is an effort to get those answers out there.

Gitalk_contentful-most-frequently-asked-questions

PavithraSridharan02 commented 2 years ago

Hi i want to move a specific content alone from one environment to another. Can you please tell me?

debpu06 commented 2 years ago

@pav342 Hi i want to move a specific content alone from one environment to another. Can you please tell me?

Did you look into the Contentful CLI and import/export functionality? There is some good documentation here: https://www.contentful.com/developers/docs/tutorials/cli/import-and-export/ It does include a --query-entries option which should allow you to only export specific instances of content. Then you can import it into the other environment. Would that be what you are looking for?

PavithraSridharan02 commented 2 years ago

Yes i tried it. It takes all the content types and assets. I want a particular content from a specific content model and migrate the content alone with assest,etc to another environment

debpu06 commented 2 years ago

@pav342 Yes i tried it. It takes all the content types and assets. I want a particular content from a specific content model and migrate the content alone with assest,etc to another environment

Hey @pav342,

That should be feasible. You have to look into that --query-entries option. If you write it out in JS it would look something like the following:

const contentfulExport = require('contentful-export')

const options = {
  spaceId: '<space_id>',
  managementToken: '<content_management_api_key>',
  queryEntries: [
    'content_type=<content_type_id>',
    'sys.id=<entry_id>'
  ]
}

contentfulExport(options)
...

Where in your query entries parameter you are passing the content_type_id, which filters by specific content type. And you can pass sys.id, which can allow you to filter on specific entries. You can also use the other flags like --content-only so that it only exports the entries and assets, not the content model.

Once that data is exported into a file, when you run an import with that specific file into a new environment, it will only move those entries. Here is some more documentation on the details of the queries: https://github.com/contentful/contentful-export#querying https://github.com/contentful/contentful-export#queryentries-array

And here is someone who had a similar question in Contentful forums:

https://www.contentfulcommunity.com/t/copy-content-entry-to-another-space/1166

PavithraSridharan02 commented 2 years ago

First of all thank you for your help.

  1. I have two environment “brandpage” and “aus”. Brandpage environment is empty and aus environment have 10+ content model. And it has five entries ( from 3 content types). And two assets. This is all I have.

  2. I have already tried the code you have sent me. File name- contentmigrate.js.

  3. In the code query entries I gave only one content type id “headline” and sys.id

  4. Headline content type has only 3 entries.

  5. When I run this code “contentful space export contentmigrate.js —content-only it takes all the 5 entries (from 3 content types) and it takes tags which I didn’t give.

I tried my very best and it still takes all the content type entries.