How to use ‘undo change timestamp’ custom rake task?

How to run this in detail? I’m not familiar rake task.

I encountered this problem:

-bash: cd: /var/www/discourse: No such file or directory

You need to do it inside the container.

cd /var/discourse
./launcher enter app

If you can do it from the UX instead as one of the above posts suggests, that’s what I would recommend.

You also need to create a file with that code in it, with nano, perhaps.

1 Like

Thank you, I will try it later.

I just tried the API way.

https://docs.discourse.org/#tag/Topics/operation/updateTopicTimestamp

But I get 400 error, saying that

{ errors: [ 'param is missing or the value is empty: timestamp' ] }

Here is my code

changeTimestamp(935, 1694291380);

async function changeTimestamp(topicId, timestamp) {
  const endpoint = `/t/${topicId}/change-timestamp`;
  const payload = {
    timestamp: timestamp,
  };
  put(endpoint, payload);
}

async function put(endpoint, payload) {
  const response = await fetch(DISCOURSE_ADDRESS + endpoint, {
    method: "PUT",
    headers: {
      "Content-Type": "application/json",
      "Api-Key": DISCOURSE_API_KEY,
      "Api-Username": API_USERNAME,
      body: JSON.stringify(payload),
    },
  });
  const result = await response.json();
  if (!response.ok) {
    console.log("put failed");
    console.log(result);
  } else {
    console.log("put success");
  }
}

You put body inside headers. It’s not a header but an option. See the documentation below:

2 Likes