Contentful logo

Contentful Community

Processing asset is failing; cannot publish

I am trying to migrate assets from one environment to another in the same space.

I’m using the createAssetWithId method from the Contentful Management API to migrate the asset with its ID from the source environment to the target environment.

However, I’m getting this error when publishing:

ValidationFailed: {
  "status": 422,
  "statusText": "Unprocessable Entity",
  "message": "Validation error",
  "details": {
    "errors": [
      {
        "name": "badFileUrl",
        "path": [
          "fields",
          "file",
          "en-US",
          "url"
        ],
        "details": "Invalid asset URL"
      }
    ]
  },
  "request": {
    "url": "assets/5KRzAvo7a4xq7iuLuuQ9B3/published",
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Content-Type": "application/vnd.contentful.management.v1+json",
      "X-Contentful-User-Agent": "sdk contentful-management.js/5.28.0; platform node.js/v10.16.2; os Windows/10.0.18362;",
      "Authorization": "Bearer ...fbbFQ",
      "user-agent": "node.js/v10.16.2",
      "Accept-Encoding": "gzip",
      "X-Contentful-Version": 2
    },
    "method": "put",
    "payloadData": null
  },
  "requestId": "f77f2c74115b8bf071fd58455f26bd27"
}

This is the code for creating and processing the asset. The publishing part comes after that.

await cmaClient.getSpace(spaceId)
        .then(async (space) => await space.getEnvironment(environmentId))
        .then(async (environment) => await environment.createAssetWithId(assetItem.sys.id, { fields: assetItem.fields }))
        .then(async (asset) => await asset.processForAllLocales({ processingCheckWait: 5000, processingCheckRetries: 25 }))
        .then(customLogger.success(`Asset '${assetItem.sys.id}' has been created.`))
        .catch(customLogger.error)

assetItem.fields has the following properties:

{ title: { 'en-US': 'image title' },
  description: { 'en-US': ' ' },
  file:
   { 'en-US':
      { fileName: '',
        contentType: 'image/jpeg',
        upload:
         'https://images.ctfassets.net/<space_id>/<asset_id>/2hj84bce4dedcfc78654b98hhhr452t7/image.jpg' } } }

The asset gets created but the image doesn’t appear and doesn’t get processed and therefore published.