1

I'm trying to import entries with an Asset inside a subfolder. Since I don't know what the new Craft subfolder ID will be for each Asset I tried to use the folderPath property from Craft's Asset element class:

[
{
    "@model": "barrelstrength\\sproutimport\\importers\\elements\\Entry",
    "attributes": {
        "sectionId": 2,
        "typeId": 2,
        "authorId": 1,
        "slug": "my-sample-document",
        "postDate": "2017-11-09 13:06:00",
        "expiryDate": null,
        "enabled": true
    },
    "content": {
        "title": "My Sample Document",
        "fields": {
            "description": "<p>Nulla sit amet est. In hac habitasse platea dictumst. Pellentesque ut neque.</p>"
        },
        "related": {
            "documentFile": {
                "@model": "barrelstrength\\sproutimport\\importers\\elements\\Asset",
                "params": {
                    "filename": ["my-sample-document.pdf"],
                    "volumeId": 9,
                    "folderPath": "documents/pdfs/"
                }
            }
        }
    }
}
]

However the import fails with this error:

[error][sprout-import] Setting unknown property: craft\elements\db\AssetQuery::folderPath

I don't get an error when I use the folderId property. Can I only use properties that correspond with database columns? Is there any way to do this if I don't know the subfolder ID for every asset I'm importing?

  • Craft 3.0.26.1
  • Sprout Import 1.0.0-beta.14
1

folderPath is not supported when relating an asset to an Entry but there is a workaround. In your generation script you can call the code below to get the folderId with the given path:

$folderId = \craft\records\VolumeFolder::find()
->where(['path' => 'documents/pdfs/'])
->scalar();
| improve this answer | |
  • Where is my "generation script"? – kmgdev Oct 16 '18 at 17:48
  • @kgrote that is the script you created for the import json data format. – Dale Ramirez Oct 17 '18 at 13:31
  • I didn't create a script. I just exported data in JSON format from ExpressionEngine and imported it to Sprout Import. – kmgdev Oct 17 '18 at 18:46
  • Where in the docs does it talk about how to use an import script? – kmgdev Oct 18 '18 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.