Getting 403 for Unlike a post by the user

AI-generated summary

User @Vishal_Kaushik is trying to use the Discourse API to unlike a post, but is getting a 403 error response saying “You are not permitted to view the requested resource.” Vishal_Kaushik has tried sending the request with Node.js and also directly from Postman, but is still getting the same error. jesus2099 suggests that the issue is due to trying to unlike a post that is too old, as there is a time limit for canceling likes. Vishal_Kaushik confirms that this is the reason. Chaboi_3000 explains that the time limit can be changed in the “post undo action window mins” site setting, which is set to 10 minutes by default.

I am trying to hit the unlike API on discourse with HTTP, Node.js. I am sending the particular payload :

      host: discourseHost,
      port: discoursePort,
      path: '/post_actions/' + parseInt(req.params.post_id),
      method: 'DELETE',
      headers: {
        'Content-Type': 'application/json',
        'Content-Length': Buffer.byteLength(data),
        'Api-Key': DISCOURSE_API_KEY,
        'Api-Username': userData.discourse_username,
        'Accept': 'application/json'
      }

But I am getting this as response :

STATUS: 403
BODY: {“errors”:[“You are not permitted to view the requested resource.”]}

Can anyone suggest me what I need to change in my payload/request.

I tried to hit the discourse API /post_actions/{id} directly from postman, with the following headers :

Content-Type:application/x-www-form-urlencoded
Api-Key:blah blah
Api-Username:eluser2019522
Accept:application/json

Still I am getting the response as :

{
    "errors": [
        "You are not permitted to view the requested resource."
    ]
} 

I am stuck here. Any help will be fine.

You can cancel a like heart :heart: only within a limited time span.

Maybe you are trying to unlike a too old like.

Oh yeah, Thanks a lot. That was the reason. @jesus2099 .

From where I can change this? Can i change this from the admin portal by any chance?

You can change it in the post undo action window mins site setting located here: http://forum.example.com/admin/site_settings/category/all_results?filter=post%20undo%20action%20window%20mins. By default, it should be 10 minutes.