Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
Convertir solicitud CURL a Axios

Por favor, ¿cómo puedo convertir esta solicitud de curl a su equivalente axios?

 curl -X POST https://api.pinterest.com/v5/oauth/token --header "Authorization: Basic {base64 encoded string made of client_id:client_secret}" --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'grant_type=authorization_code' --data-urlencode 'code={YOUR_CODE}' --data-urlencode 'redirect_uri=http://localhost/'

He pasado varias horas en esto solo para seguir recibiendo

 {"code":1,"message":"Invalid request body"}

Esto es lo que probé:

 const redirectUrl = process.env.PINTEREST_OAUTH_CALLBACK_URL; const clientId = process.env.PINTEREST_APP_ID; const clientSecret = process.env.PINTEREST_APP_SECRET; let url = 'https://api.pinterest.com/v5/oauth/token'; let accessTokenRequestBody = { code: code, grant_type: "authorization_code", redirect_uri: redirectUrl }; const clientIdAndSecretBase64 = Buffer.from(`${clientId}:${clientSecret}`).toString('base64'); axios(url, { method: 'post', url: url, data: accessTokenRequestBody, headers: { "Content-Type": 'application/application/x-www-form-urlencoded; charset=UTF-8', "Authorization": `Basic ${clientIdAndSecretBase64}` } }).then((response) => { let responseData = response.data; let accessToken = module.exports.encodePayloadIntoJWT(responseData); console.log(`Pinterest ResponseData = ${JSON.stringify(responseData, null, 2)}`); }).catch((e) => { console.log(`${JSON.stringify(e.response.data)}`); });

Estaría muy agradecido a cualquier ayuda ya que esto me ha hecho perder mucho tiempo. Actualmente estoy retrasado en la fecha límite... Gracias.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe codificar en urlen los parámetros en lugar de pasar un objeto como datos.

 const params = new URLSearchParams(); params.append('redirect_uri', process.env.PINTEREST_OAUTH_CALLBACK_URL) // do the same for other parameters // ... // make post
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!