Setting first_published_at / last_published_at using REST API

I’m using the REST Api to migrate some existing data and was wondering how to populate the first_published_at and last_published_at attributes.

I tried using first_published_at and got the following error (I’m using the Ruby gem):

Status: 422
Response:
{
  "data": [
    {
      "id": "86a89e",
      "type": "api_error",
      "attributes": {
        "code": "INVALID_ATTRIBUTES",
        "details": {
          "extraneous_attributes": [
            "first_published_at"
          ]
        }
      }
    }
  ]
}
1 Like

Hello @zaid !

The first_published_at and last_published_at attributes are meant to be internal fields that cannot be modified. They are not editable as they are internal fields that we expose for your convenience. You can use them as meta fields or you can ignore them if you need to edit them.

If you want to have an editable field you should add an extra date-time field (or two of them) that you can use as you like.

Hello @mat_jack1,

Thank you for the quick reply! We had the publishing functionality in our previous CMS so we were hoping to use the same fields in Dato (to store the published_at time).

Is there a way to trigger certain fields to update once a record is published?

To do that you can leverage the webhooks but you should write yourself something like a lambda function that needs to update the fields.

So, not internally in DatoCMS, but you can do that yourself in that way.

1 Like