Possible to change owner/publish time for native comments?

Moving a site from Wordpress to hosted ghost.

The built-in comment system looks good visually, but I can’t find a way to import comments from the old Wordpress site.
Not the end of the world if that’s indeed so, worst case I can set aside a few hours copy-pasting the comments manually.
I have added members to ghost for all the users that created comments in the old Wordpress site.

BUT I then need to
a) change the user of the comment to the correct user.
b) change the date of the comment so it matches the original date from the Wordpress site.

Is a & b possible using today’s ghost?
Current version is 5.29.0

Thx

The built in commenting system creates comments like this on the /members/api/comments/ endpoint:

{
html: "<p>this is another comment!</p>"
post_id: "63b95d863fdfa4003dabcfb9"
status: "published"
}

It determines who is commenting from the logged in user.

More promising is this endpoint: /ghost/api/admin/comments , used to hide comments. A PUT there takes:

{comments: [{id: "63c18ccd3dd8d5003daba86e", status: "hidden"}]}

I think the odds are pretty good that it’ll also take the other fields in comments! Try it!

Here’s the comments object Ghost returns when you visit a page with comments - that gives you the field names Ghost wants, which can probably be used at that admin endpoint above:

{
  "comments": [
    {
      "id": "63c18ccd3dd8d5003daba86e",
      "status": "hidden",
      "html": null,
      "created_at": "2023-01-13T16:54:37.000Z",
      "edited_at": null,
      "member": {
        "id": "63bec12abc71c1003de57b11",
        "uuid": "a7c5a097-2520-4021-96a9-d2dd5fec7386",
        "name": "Trialing member",
        "expertise": null,
        "avatar_image": "https://www.gravatar.com/avatar/b8d37e3eaee25bf0fb8617ed9edf089e?s=250&r=g&d=blank"
      },
      "replies": [],
      "liked": false,
      "count": {
        "replies": 0,
        "likes": 0
      }
    },
    {
      "id": "63c18b7e3dd8d5003daba86d",
      "status": "published",
      "html": "<p>this is another comment!</p>",
      "created_at": "2023-01-13T16:49:02.000Z",
      "edited_at": null,
      "member": {
        "id": "63bb62f6756b27003d3c1c0a",
        "uuid": "2e69ea47-26a8-4a91-bd1c-71834ffcb6d0",
        "name": "My paid user",
        "expertise": "I have some expertise!",
        "avatar_image": "https://www.gravatar.com/avatar/915c787bf1ec21f92d29a1b35df4535a?s=250&r=g&d=blank"
      },
      "replies": [],
      "liked": false,
      "count": {
        "replies": 0,
        "likes": 0
      }
    },
    {
      "id": "63c18b5f3dd8d5003daba86c",
      "status": "published",
      "html": "<p>I'm making a comment here!</p>",
      "created_at": "2023-01-13T16:48:31.000Z",
      "edited_at": null,
      "member": {
        "id": "63bb62f6756b27003d3c1c0a",
        "uuid": "2e69ea47-26a8-4a91-bd1c-71834ffcb6d0",
        "name": "My paid user",
        "expertise": "I have some expertise!",
        "avatar_image": "https://www.gravatar.com/avatar/915c787bf1ec21f92d29a1b35df4535a?s=250&r=g&d=blank"
      },
      "replies": [],
      "liked": false,
      "count": {
        "replies": 0,
        "likes": 0
      }
    }
  ],
  "meta": {
    "pagination": {
      "page": 1,
      "limit": 5,
      "pages": 1,
      "total": 3,
      "next": null,
      "prev": null
    }
  }
}

Yeah, some analysis of the traffic from ghost can certainly be useful to figure out not-so-documented features.
I haven’t found any docs relating to API mgmt of comments. Could be a case of bad Google karma today tho…

Downside of using undocumented features is that they may change, of course. Shouldn’t matter in this case as I am looking at a one-time import/edit of comments.

Will hack away on this when I get a chance, reverse engineering is always fun :blush:

Unfortunately, it looks like the SDK hasn’t been updated, but nothing prevents you from writing raw fetch calls. Except having to deal with authentication…

1 Like

I’ve now tried using the ghost/api/admin/comments/<comment-id> endpoint to update comments, no luck.

Seems that the only thing that can be updated is the status, with valid values published/hidden/deleted.
Changing those values using that endpoint works fine, but I fail to update any other fields.

Nah this looks like a dead end.

I’ll spin up a local ghost instead, import the Wordpress site there, then script the import of comments into the MySql db.
Hopefully it’s then possible to update ownership/creation dates of comments via direct db manipulation.

Finally move the local ghost instance to a hosted ditto.

Pretty sure it can be made to work, but it feels like waaaay more work than it should be. Oh well, it’ll be a good exercise i guess.

Forgot:

I had a look at the JSON file that’s the result of an export from the Labs section of ghost’s settings page. I thought that maybe comments could be added there and the JSON then imported into a new ghost instance…

Looks like comments aren’t included in the exported JSON.
Which is rather surprising. Ok, it’s a Labs feature and subject to change etc, but clearly it’s not a complete export of contents. Posts, member data, general settings of all kinds are exported, but not comments it seems.

Oh, interesting. Too bad they’re not in the JSON export. So you’re going to have to import the DB into MySQL on the hosting environment if you go that route. That rules out this working on Ghost Pro hosting.

Yeah, as it stands now I’ve not found a working way to migrate existing comments to ghost Pro native comments.

I tried injecting new/modifying existing comments in the MySQL db that backs a test ghost instance locally here, that works. But then it’s back to self-hosting - which is what I wanted to get away from to begin with. Oh well.