0
[RESOLVED]
I made a simple Node server to test the Pagseguro API and am having problems with error 401.
In a video I saw that to make requests for the Pagseguro API it is necessary to have an SSL certificate, so I deploy to Heroku
As in the image above, the lock is closed and the URL starts with https://
which means that the address has an SSL certificate, but even so the API is giving error.
I have tried to solve this problem in a number of ways, including using Cors-Anywhere both online and locally and it also didn’t work.
I made a request using the desktop application Postman and in it the request returned status 200
In the Postman request I did not set any header, I just selected the option x-www-form-urlencoded
and put the information [email, token]
Information:
- Credentials [email, token] are correct
- deploy contains no errors
Below is the Node server code:
require('dotenv').config()
const fetch = require('node-fetch')
const Headers = fetch.Headers
const express = require('express')
const app = express()
app.get('/', (req, res) => {
res.send('working pgs')
})
app.get('/teste', async (req, res) => {
const r = await fetch('https://ws.sandbox.pagseguro.uol.com.br/sessions/', {
method: 'post',
headers: new Headers({"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"}),
body: {
email: encodeURIComponent(process.env.PGS_EMAIL),
token: encodeURIComponent(process.env.PGS_TOKEN)
}
})
const t = await r.text()
console.log(r)
res.send(`teste ${JSON.stringify(r)}`)
})
app.listen(process.env.PORT || 3333)
I hope I have synthesized my doubt in an easy way to be understood if by chance some information is missing please let me know that I put here.
There is no need to indicate in the text of the question that the problem has been solved. Just accept an answer that we will already know.
– tvdias