Is any way to update createdAt, publishedAt dates using POST query

System Information
  • ** “@strapi/strapi”: “4.2.3”**:
  • Mac OS:
  • sqlite3:

During a migration from very old keystone, try to do something like that

await axios.post('http://localhost:1337/api/posts', {
  data: {
     content: posts[89].en.contentHtml,
     createdAt: posts[89].publishDate,
      updatedAt: posts[89].publishDate,
      publishedAt: posts[89].publishDate
  }
}).catch(error => console.error('error axios', error.response));

or

data: {
   content: posts[89].en.contentHtml
 },
createdAt: posts[89].publishDate,
updatedAt: posts[89].publishDate,
publishedAt: posts[89].publishDate

Anyway get in strapi this dates from time of code running, date format is “2018-12-04T00:00:00.000Z”

You have to use unix date format, try something like

Date.parse(posts[89].publishDate)

Thanks a lot! This solve my problem

Hi,
I’m in the same situation…
I want to create a new content “overriding” the creation/update date (I’m migrating an old site)
This is the request’s body

{
  "data": {
    "title": "Hello",
    "slug": "hello11",
    "createdAt": "818035920000",
    "updatedAt": "818035920000",
    "publishedAt": "818035920000",
    
  }
}

The entry is created but with a “current” datetime and not the “old one”.
Any ideas?

Did you solve it? If yes, do you mind sharing?