Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the javascript/React equivalent code for this curl code – Capital.com API (React.js)

I have a curl code I took from the capital.com website regarding their API but they do not have docs for node.js and I have no clue what curl code is so I do not understand it, Can anyone tell me the js equivalent assuming I am using axios to make the request.

curl -L -X POST 'https://api-capital.backend-capital.com/api/v1/session' \
-H 'X-CAP-API-KEY: evSl********S26P' \
-H 'Content-Type: application/json' \
--data-raw '{
 "encryptedPassword": "false", 
 "identifier": "test@gmail.com",
 "password": "Xxxx9999_"
}'

I tried this below but gave me a error Status 400

const loginHandler = () => {
    axios.post("https://api-capital.backend-capital.com/api/v1/session", {
      'X-CAP-API-KEY': "tL0xi4wvz5X8uHaD",
      'Content-Type': 'application/json',
      'data-raw': {
        'encryptedPassword': false,
        "identifier": "hadwe",
        'password': '88asc'
      }
    }).then(res => {
      console.log(res.data)
    })
  }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

--data-raw is the body.

const response = await axios.post(
  'https://api-capital.backend-capital.com/api/v1/session',
  {
    'encryptedPassword': 'false',
    'identifier': 'test@gmail.com',
    'password': 'Xxxx9999_'
  },
  {
    headers: {
      'X-CAP-API-KEY': 'evSl********S26P',
      'Content-Type': 'application/json'
    }
  }
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading