Set the date of a new topic via the API?

(Steve Kemp) #1

I’m importing a series of emails into a new discourse instance. Importing the messages is going well, however using the discourse_api gem I’m unable to set the date on a new post.

For example the following code imports a new post, using create_topic:

result = client.create_topic(
  :category => "foo",
  :title => "This is my descriptive title",
  :raw => "This is my long/interesting post..." )

As expected this creates the post with the post-date set to “now”. I tried adding created_at and posted_at fields which I’ve seen referred to in various places (but not the API gem), but these were ignored.

Is there any way to mangle the date of the new post, short of editing the database? (Bear in mind I’m importing thousand of new entries from mailman archives and a couple of other data-sources (including wordpress).

(Blake Erickson) #2

Currently I don’t think the discourse_api gem has support for this, but I can work on adding it soon.

Looks like you will have to create the topic, and then modify it with the change-timestamp method:

PUT http://localhost:3000/t/14/change-timestamp

Also I’ll look at how some of the importers work, but I don’t think they use exposed API methods.

(Régis Hanol) #3

The API does support setting the created_at date when creating a post/topic. If you want it to work when using the API gem, you should submit a PR @skx to make sure it’s listed as an optional parameter :wink:

How to hide timestamps in html mobile output?
(Blake Erickson) #4

so looking at the posts controller, the created_at isn’t a permitted parameter:

(Steve Kemp) #5

Thanks for the replies; I appreciate them all.

In short then it seems like there are two distinct issues here:

  • The discourse_api gem doesn’t allow an (optional) created_at field to be submitted.

  • Even if the API-gem did support such a thing, the receiver doesn’t accept it.

I’d be happy to create a pull request on the API-gem, but that seems a little futile if the parameter could be sent, but would still be ignored on the receiving side. (I guess a related problem is that there is zero documentation for the format of the created_at field, largely because it is neither sent nor consumed.)

(Régis Hanol) #6

Good point, we should allow it but only for API calls then.

@skx, if you’re up for 2 PRs, I’d happily merge them :wink:

(Steve Kemp) #7

I’ll submit a pull-request for editing the timestamp on topics tonight. I’ve now got something that is functional.

(Steve Kemp) #8

I’ve created a simple pull request for the client-API gem now:

I’ll look at the server side shortly, but not today.