0

I'm trying to access the API of Codeship in js but it gives the code in cURL

This is it in curl:

curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" --user '<your email>:<your password>' https://api.codeship.com/v2/auth

I'm not sure how to pass in the arguments or user

This is the api docs if you needed it https://apidocs.codeship.com/v2

Thanks for any help on this.

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
RadiantMin3
  • 103
  • 1
  • 8

1 Answers1

1

If you're asking how to do this in node.js, here's an example using the commonly used axios http-request library:

const axios = require('axios');

async function sendRequest() {

    const requestConfig = {
        method: 'post',
        url: 'https://api.codeship.com/v2/auth',
        headers: {
            'Content-Type': 'application/json'
        },
        auth: {
            username: 'your-user',
            password: 'your-password'
        }
    };

    try {
        const response = await axios(requestConfig);
        console.log(JSON.stringify(response.data));
        return response;    
    } catch (error) {
        console.log(error);
    }
}
eol
  • 23,236
  • 5
  • 46
  • 64