Import cli, import external assets into new asset field

Hi,

The goal is to export my posts from Medium and import them into Contentful.

  1. I already have the exported Medium posts in HTML format and have created a script to convert the content I want into markdown.
  2. I already setup the content models in Contentful.
  3. I created a fake post in Contentful then exported it to see how the JSON structure looks. From here, I duplicated this and imported it to see if it worked, and it worked!
  4. I formatted my real content, in the JSON structure that was exported from contentful. Everything works except for creating new assets. For example, I have an external image link, that I want to import and store in my content type’s ‘blogPostImage’ field, how do I do this?

Here is an example of what I tried… I tried several different iterations of this:

This snippet contains several variables, notice that blogHeroImage is an external image link (https://).

          "blogHeroImage": {
            "en-US": {
              "type": "Asset",
              "createdBy": {
                "sys": {
                  "type": "Link",
                  "linkType": "User",
                  "id": "....."
                }
              },
              "publishedVersion": 4,
              "publishedCounter": 1,
              "version": 5,
              "updatedBy": {
                "sys": {
                  "type": "Link",
                  "linkType": "User",
                  "id": "....."
                }
              },
              "publishedBy": {
                "sys": {
                  "type": "Link",
                  "linkType": "User",
                  "id": "...."
                }
              },
              "fields": {
                "title": {
                  "en-US": title
                },
                "file": {
                  "en-US": {
                    "url": blogHeroImage,
                  }
                }
              }
            },
          }

Hey @gainor,

Not sure if this will answer your questions - but url for image/assets needs to be from Contentful’s server. Hence, you will need to create, process, and publish your assets programmatically using Management API. https://www.contentful.com/developers/docs/references/content-management-api/#/reference/assets/asset

Cheers,
Fanny from Contentful’s Support team