Lovey
Lovey

Reputation: 930

Slack's chat.scheduleMessage API keeps throwing Epoch time error

I am trying to use chat.scheduleMessage from Slack API (https://api.slack.com/methods/chat.scheduleMessage). However, I keep getting the error time_too_far.

Request:

curl --location --request POST 'https://slack.com/api/chat.scheduleMessage' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer XXXX' \
--data-raw '{
    "channel":"#test_channel",
    "text":"Sample message",
    "post_at":"1596647160000"
}'

Response:

{
    "ok": false,
    "error": "time_too_far",
    "warning": "missing_charset",
    "response_metadata": {
        "warnings": [
            "missing_charset"
        ]
    }
}

As per the developer documentation, it says, You will only be able to schedule a message up to 120 days into the future. If you specify a post_at timestamp beyond this limit, you’ll receive a time_too_far error response.. However, in this case, I am just scheduling the message for tomorrow.

Not sure if I am missing something.

Upvotes: 2

Views: 504

Answers (1)

Jacob Lee
Jacob Lee

Reputation: 86

The timestamp you're providing is a JavaScript timestamp (milliseconds since epoch), while Slack's scheduled message API takes a Unix timestamp (seconds since epoch). Dividing by 1000 should fix the error.

Upvotes: 3

Related Questions