【Bluesky API】「BadRequestError createdAt must be an valid atproto datetime (both RFC-3339 and ISO-8601)」の対処法

起きていた事象

Blueskyに対してAPIで投稿を行っているBotがあるのですが、それが最近こけ始めました。

エラー内容を見てみると、リクエスト時に指定しているcreatedAtというパラメータが不正とのこと。

 {
  "error": "InvalidRequest",
  "message": "Invalid app.bsky.feed.post record: createdAt must be an valid atproto datetime (both RFC-3339 and ISO-8601)"
}

対処法

以下の形式でcreatedAt を設定するとエラーなくAPIにリクエストが送信できました

import datetime
datetime.datetime.now(tz=datetime.timezone.utc).replace(tzinfo=None).isoformat(timespec="milliseconds") + "Z"

原因

API側のcreatedAt に対するバリデーションに引っかかっていた。

↓エラー内容的にはここ。

https://github.com/bluesky-social/atproto/blob/5038b50428be04b40a772f20fc0ee481c13676cd/packages/pds/src/repo/prepare.ts#L147

↓具体的には、ここに記載されているDatetimeの形式に合わせてあげる必要があります

https://github.com/bluesky-social/atproto/blob/main/packages/syntax/src/datetime.ts#L4

参考

BadRequestError createdAt must be an valid atproto datetime (both RFC-3339 and ISO-8601) · Issue #192 · MarshalX/atproto
I have started to get the following error whenever I try to post anything at all. I have not made any change in the code...

コメント

タイトルとURLをコピーしました