Register now - Learn how Tecovas roped in success with Sanity and Shopify 🤠

Error importing data into Sanity via CLI due to malformed data and internal server error.

14 replies
Last updated: Nov 7, 2023
I’m trying to import data into Sanity via the CLI but I’m getting the following error:
sanity dataset import ../json/ndjson/sources.ndjson production --replace
✔ [100%] Fetching available datasets
✔ [100%] Reading/validating data file (96ms)
✖ [  0%] Importing documents (2.92s)

Error: Mutation failed: Internal server error:
- Internal server error
    at onResponse (~/.nvm/versions/node/v18.6.0/lib/node_modules/@sanity/cli/lib/_chunks/loadEnv-6ca0aa8a.js:1234:13)
    at applyMiddleware (~/.nvm/versions/node/v18.6.0/lib/node_modules/@sanity/cli/node_modules/get-it/dist/index.cjs:59:13)
    at onResponse (~/.nvm/versions/node/v18.6.0/lib/node_modules/@sanity/cli/node_modules/get-it/dist/index.cjs:103:22)
    at ~/.nvm/versions/node/v18.6.0/lib/node_modules/@sanity/cli/node_modules/get-it/dist/index.cjs:130:55
    at callback (~/.nvm/versions/node/v18.6.0/lib/node_modules/@sanity/cli/node_modules/get-it/dist/index.cjs:485:46)
    at ~/.nvm/versions/node/v18.6.0/lib/node_modules/@sanity/cli/node_modules/get-it/dist/index.cjs:548:14
    at DestroyableTransform.<anonymous> (~/.nvm/versions/node/v18.6.0/lib/node_modules/@sanity/cli/node_modules/get-it/dist/index.cjs:261:13)
    at Object.onceWrapper (node:events:627:28)
    at DestroyableTransform.emit (node:events:525:35)
    at endReadableNT (~/.nvm/versions/node/v18.6.0/lib/node_modules/@sanity/cli/node_modules/readable-stream/lib/_stream_readable.js:1010:12)
Nov 7, 2023, 3:35 AM
At first I thought that it was because my data was malformed since I was trying to import new data. So then I tried exporting the data that was already in Sanity via the CLI. That worked correctly. Then I made some small change to a title field and tried importing it and it gave me the same error:
Mutation failed: internal server error
Nov 7, 2023, 3:37 AM
So even the exported data couldn’t be imported.
Nov 7, 2023, 3:38 AM
Then I thought that maybe it was because I had made changes locally in my Sanity studio that had not been deployed. Surely it was that. So I deployed and tried again and received the same error.
Nov 7, 2023, 3:39 AM
Then I thought to check the sanity status page and I saw this:
Nov 7, 2023, 3:41 AM
It does mention
so I thought it could be related. But on the other hand it doesn’t seem like it is related and it says that this issue is already resolved.
Nov 7, 2023, 3:42 AM
It’s not giving me much indication of what the error is. Just
Internal server error
Nov 7, 2023, 3:42 AM
Is it a permissions issue?
Nov 7, 2023, 3:42 AM
I just checked the billing details of my plan. I’m on the free plan and it said that I should add billing details just incase there are overages. I added my billing details and tried the import again, which is just 2 records, and I’m still getting the same error.
Nov 7, 2023, 3:46 AM
I’m running
"sanity": "^3.19.1"
and I have
installed globally at
Nov 7, 2023, 3:47 AM
It seems that my data the I’m trying to import is malformed or has some character in it that is causing the error.
Nov 7, 2023, 4:14 AM
Still trying to find the exact cause.
Nov 7, 2023, 4:14 AM
Ok, I found the error: I had made new
fields for each entry based off of an existing string field in the incoming data. One record had a
(period) in it and that is not allowed to be in the
field. After I fixed that everything imported just fine.
Nov 7, 2023, 4:25 AM
Nov 7, 2023, 4:25 AM
It also appears that there were two records that had malformed dates.
Nov 7, 2023, 4:29 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?

Categorized in