Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Axios Authentication WP-API #73

Open
techhjork opened this issue Mar 13, 2022 · 0 comments
Open

Axios Authentication WP-API #73

techhjork opened this issue Mar 13, 2022 · 0 comments

Comments

@techhjork
Copy link

techhjork commented Mar 13, 2022

Trying WP API by Nodejs by Axios but getting Authentication issue

curl -i  -X POST \ -H --user admin:pass -H "Content-Type: application/json" -d '{"title":"POST TWO","content":"Two","status":"publish"}' http://www.test.localhost/?rest_route=/wp/v2/projects

Code in Image
image

const express = require("express")
const axios = require("axios")
const app = express()
axios.defaults.baseURL = 'http://www.test.localhost/?rest_route=';
app.get("/",(req,res)=>{
	axios({
		method:"POST",
		headers:{
			'Content-Type': 'application/json;charset=utf8',
      		'Authorization':'Basic YWRtaW46cGFzcw=='
  		},
		url:'/wp/v2/projects',
		data:{"title":"POST three","content":"Two","status":"publish"},

	}).then(data=>{
		res.send(data)
	}).catch(err=>{
		console.log(err)
		res.send(err)
	})
})
app.listen(8000,()=>{
	console.log(`localhost:8000`)
})

working on CURL
image

working on POSTMAN
image

Getting this error

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'ClientRequest'
    |     property 'socket' -> object with constructor 'Socket'
    --- property '_httpMessage' closes the circle
    at JSON.stringify (<anonymous>)
    at stringify (/home/tech/Desktop/Project/role/node_modules/express/lib/response.js:1128:12)
    at ServerResponse.json (/home/tech/Desktop/Project/role/node_modules/express/lib/response.js:260:14)
    at ServerResponse.send (/home/tech/Desktop/Project/role/node_modules/express/lib/response.js:158:21)
    at /home/tech/Desktop/Project/role/index.js:18:7
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant