1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Error [AxiosError]: Request failed with status code 400

1
Posted at

はじめに

記事ブログの作成中にエラーになりました。

問題

axiosとあるので、URLの記載が間違っているかと調査していました。

page
async function FetchBlog({ params }: { params: Promise<Params> }) {
    "use cache";
    const id = await params
    const response = await axios.get<MicroCMSArticle>(
        `https://[あなたのドメイン].microcms.io/api/v1/blogs/${id}`,
        {
            headers: {
                "X-MICROCMS-API-KEY": `${process.env.MICROCMS_API_KEY}`,
            },
        }
    )
    const article = response.data;

解決方法

URLの記載方法が間違っていました。

page
async function FetchBlog({ params }: { params: Promise<Params> }) {
    "use cache";
    const id = await params
    const response = await axios.get<MicroCMSArticle>(
        `https://[あなたのドメイン].microcms.io/api/v1/blogs/${id,id}`,
        {
            headers: {
                "X-MICROCMS-API-KEY": `${process.env.MICROCMS_API_KEY}`,
            },
        }
    )
    const article = response.data;

と記載を変更しました。

オブジェクトの分解の記述が不足していたためエラーになっていました。
const { id } = await params;でも可能です。

おわりに

つぎにいきます。

参考文献

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?