Update Blocks in structured text

Hi,

I am trying to write a migration to change a field from a number field to a text field in a block which is used in many different structured text fields.

I thought I could just do this:

// create size_temp field on breakpoint block

for await (const record of client.items.listPagedIterator({ filter: { type: 'breakpoint' }, nested: true }, {})) {
    // Update block so the existing size is copied over to the new field
    await client.items.update(record.id, {
      ...record,
      size_temp: `${record.size}`
    });
  }

// Delete the old size field and rename size_temp.

The issue I have is doing this results in a 404 for some reason even though I can see the record exists when I log it out?

{
  "data": [
    {
      "id": "302048",
      "type": "api_error",
      "attributes": {
        "code": "NOT_FOUND",
        "details": {}
      }
    }
  ]
}

I also tried to modify the field and convert it from numeric to a string but you can’t do that either…

{
            "id": "398f8d",
            "type": "api_error",
            "attributes": {
              "code": "INVALID_FIELD",
              "details": {
                "field": "field_type",
                "code": "INVALID_FORMAT",
                "message": "Cannot be converted into string"
              }
            }
          }

Also just on this it would be nice too be able to get all items using the CMA based on field type.

@david.hewitt,

Hmm… I’m sorry, but there isn’t quite enough information to say at a glance what might be happening.

Could you please email us at support@datocms.com with the code for the entire script you’re trying to run, the project you’re trying to run it on, and the last 4 characters of the API key you’re using (just in case it’s a roles/permissions issue)?

My guess is that it might be a nested property that’s maybe being missed by a level or two, but hard to tell without more logging.

I’ll try to replicate and debug this for you once we get the info. (And just FYI, if you haven’t already, you can also turn on LogLevel.BODY_AND_HEADERS to get more debug info on your own, if you’d like).

Thank you and sorry about that!

Hey @roger

Thanks for getting back to me!

Yeah this does seem like a strange one I’ll reach out via the support email thanks :slight_smile: