#404 error while api post

23 messages · Page 1 of 1 (latest)

jaunty spoke
#

Error adding data: AxiosError: Request failed with status code 404

serene peakBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

jaunty spoke
#

@Risky down under

surreal nebula
#

can you share what your request looks like (url and code) and what it is consuiming (ie the endpoint)

jaunty spoke
#

ok

#

import axios, { Axios } from 'axios';
import React from 'react'
const page = async () => {
const dataToSend =
{
"value1": "dhuvara",
"value2": "Solution",
"value3": "mani"
}

  axios.post('http://localhost:3000/pages/api/addpagecontents',dataToSend,
   {
    headers: {
      'Content-Type': 'application/json' 
    }
  })

.catch((error) => {
console.log("-----------------------------------------------------------------------------------------")
console.error('Error adding data:', error);
})
return (
<div>page</div>
)
}

export default page

#

this my code

surreal nebula
#

can you show a screenshot of your file tree (like side panel of vscode)

jaunty spoke
surreal nebula
#

ahh so your using app dir

#

so 2 problems i see

#
  1. your api route needs to be in a folder and end with route.ts
jaunty spoke
#

this is my error

surreal nebula
#

yeah because api routes syntax has changed in between app and pages dir

#

in app dir, you make the file end with route.ts and the folders are the pathname

jaunty spoke
#

to resolve this what should i do now

surreal nebula
#

edit your route file to have the addpagecontents.ts to be inside the folder named addpagecontents and have a file inside it with route.ts

surreal nebula
jaunty spoke
#

but excuted same code after the specifing it as client

#

but facing same error