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

AI-generated summary

A user, Dotila_Li, is seeking help with running the ‘undo change timestamp’ custom rake task. pfaffman advises running the task inside the container using cd /var/discourse and ./launcher enter app, and creating a file with the code.

Alternatively, Dotila_Li tries using the API, but encounters a 400 error due to a missing or empty ‘timestamp’ parameter. Arkshine points out the issue is caused by incorrectly placing the body option inside the headers object, and provides documentation to correct this.

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.

Thank you, I will try it later.

I just tried the API way.

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: