stuart-client
TypeScript icon, indicating that this package has built-in type declarations

1.3.2 • Public • Published

Codeship Status for StuartApp/stuart-client-js

Stuart JS Client

For a complete documentation of all endpoints offered by the Stuart API, you can visit Stuart API documentation.

Install

$ npm install stuart-client-js --save

Usage

Initialize HTTP client

const {
  Authenticator,
  Environment,
  ApiResponse,
  HttpClient
} = require('stuart-client-js')

const environment = Environment.SANDBOX()
const api_client_id = 'c6058849d0a056fc743203acb8e6a850dad103485c3edc51b16a9260cc7a7689' // can be found here: https://admin-sandbox.stuart.com/client/api
const api_client_secret = 'aa6a415fce31967501662c1960fcbfbf4745acff99acb19dbc1aae6f76c9c618' // can be found here: https://admin-sandbox.stuart.com/client/api
const auth = new Authenticator(environment, api_client_id, api_client_secret)

const httpClient = new HttpClient(auth)

Custom requests

Example: create a job

const job = {
  job: {
    transport_type: "bike",
    pickups: [
      {
        address: "46 Boulevard Barbès, 75018 Paris",
        comment: "Wait outside for an employee to come.",
        contact: {
          firstname: "Martin",
          lastname: "Pont",
          phone: "+33698348756'",
          company: "KFC Paris Barbès"
        }
      }
    ],
    dropoffs: [
      {
        address: "156 rue de Charonne, 75011 Paris",
        package_description: "Red packet.",
        client_reference: "12345678ABCDE", // must be unique
        comment: "code: 3492B. 3e étage droite. Sonner à Durand.",
        contact: {
          firstname: "Alex",
          lastname: "Durand",
          phone: "+33634981209",
          company: "Durand associates."
        }
      }
    ]
  }
}

httpClient.performPost('/v2/jobs', JSON.stringify(job))
  .then((apiResponse) => { console.log(apiResponse) })
  .catch((error) => { console.log(error) })

Example: get a list of jobs

httpClient.performGet('/v2/jobs')
  .then((apiResponse) => { console.log(apiResponse) })
  .catch((error) => { console.log(error) })

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.3.2
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.3.2
    1
  • 1.3.1
    0

Package Sidebar

Install

npm i stuart-client

Weekly Downloads

1

Version

1.3.2

License

MIT

Unpacked Size

301 kB

Total Files

11

Last publish

Collaborators

  • kasra.karami.kk