Node + OVH

Node.js + OVH API

The easiest way to use the OVH REST API in your Node.js applications.

Getting started

1

1. Install the official node-ovh using NPM

Please report any issues on Github.

$ npm install ovh
2

2. Create an application

Depending the API you plan yo use, you need to create an application on the below websites:

Once created, you will obtain an application key (AK) and an application secret (AS).

3

3. Authorize your application to access to a customer account

To allow your application to access to a customer account using an OVH API, you need a consumer key (CK).

Here is a sample code you can use to allow your application to access to a complete account.

Depending the API you want to use, you need to specify the below API endpoint:

  • OVH Europe: ovh-eu (default)
  • OVH North-America: ovh-ca
  • RunAbove: runabove-ca
  • SoYouStart Europe: soyoustart-eu
  • SoYouStart North-America: soyoustart-ca
  • Kimsufi Europe: kimsufi-eu
  • Kimsufi North-America: kimsufi-ca

var ovh = require('ovh')({
  endpoint: 'ovh-eu',
  appKey: 'YOUR_APP_KEY',
  appSecret: 'YOUR_APP_SECRET'
});

ovh.request('POST', '/auth/credential', {
  'accessRules': [
    { 'method': 'GET', 'path': '/*'},
    { 'method': 'POST', 'path': '/*'},
    { 'method': 'PUT', 'path': '/*'},
    { 'method': 'DELETE', 'path': '/*'}
  ]
}, function (error, credential) {
  console.log(error || credential);
});
$ node credentials.js
{ validationUrl: 'https://api.ovh.com/auth/?credentialToken=XXX',
  consumerKey: 'CK',
  state: 'pendingValidation' }

This consumer key can be scoped with a specific authorization. For example if your application will only send SMS:

ovh.request('POST', '/auth/credential', {
  'accessRules': [
    { 'method': 'POST', 'path': '/sms/*/jobs'},
  ]
}, function (error, credential) {
  console.log(error || credential);
});

Once the consumer key will be authorized on the specified URL, you'll be able to play with the API calls allowed by this key.

4

4. Let's play!

You are now be able to play with the API. Look at the examples below.

You can browse the API schemas using the web consoles of the APIs:

Examples

Node-ovh can be used in two ways, with or without Harmony Proxies. Each example below is written in the two ways.

All the examples have a node-ovh module instantiated as below:

var ovh = require('ovh')({
  endpoint: 'ovh-eu',
  appKey: APP_KEY,
  appSecret: APP_SECRET,
  consumerKey: APP_CONSUMER_KEY
});

1. Fetch the user information

Without harmony proxies:

ovh.request('GET', '/me', function (err, me) {
  console.log(err || me);
});
$ node me.js
{ firstname: 'Foo',
  country: 'FR',
  language: 'fr_FR',
  organisation: '',
  area: '',
  name: 'Bar',
  phone: '+33.XXXXXXXXX',
  email: 'user@domain.tld',
  city: 'Foo',
  zip: '42000',
  fax: '',
  nichandle: 'aaXXXXXX-ovh',
  address: '42 rue bar',
  legalform: 'individual' }

With harmony proxies:

ovh.me.$get(function (err, me) {
  console.log(err || me);
});
$ node --harmony-proxies me.js
{ firstname: 'Foo',
  country: 'FR',
  language: 'fr_FR',
  organisation: '',
  area: '',
  name: 'Bar',
  phone: '+33.XXXXXXXXX',
  email: 'user@domain.tld',
  city: 'Foo',
  zip: '42000',
  fax: '',
  nichandle: 'aaXXXXXX-ovh',
  address: '42 rue bar',
  legalform: 'individual' }

2. Fetch the bill list and their summaries then print the PDF urls

Without harmony proxies:

var async = require('async');

ovh.request('GET', '/me/bill', function (err, bills) {
  if (err) { throw err; }
  async.map(
    bills,
    function (bill, callback) {
      ovh.request('GET', '/me/bill/' + bill, callback);
    },
    function (err, bills) {
      if (err) { throw err; }
      bills.forEach(function (bill) {
        console.log(bill.pdfUrl);
      });
    }
  );
});
$ node bills.js
https://www.ovh.com/cgi-bin/order/bill.pdf?reference=FRXXXXXXX&passwd=xxxx
https://www.ovh.com/cgi-bin/order/bill.pdf?reference=FRXXXXXXX&passwd=xxxx
https://www.ovh.com/cgi-bin/order/bill.pdf?reference=FRXXXXXXX&passwd=xxxx
[...]

With harmony proxies:

var async = require('async');

ovh.me.bill.$get(function (err, bills) {
  if (err) { throw err; }
  async.map(
    bills,
    function (bill, callback) {
      this[bill].$get(callback);
    }.bind(this),
    function (err, bills) {
      if (err) { throw err; }
      bills.forEach(function (bill) {
        console.log(bill.pdfUrl);
      });
    }
  );
});
$ node --harmony-proxies bills.js
https://www.ovh.com/cgi-bin/order/bill.pdf?reference=FRXXXXXXX&passwd=xxxx
https://www.ovh.com/cgi-bin/order/bill.pdf?reference=FRXXXXXXX&passwd=xxxx
https://www.ovh.com/cgi-bin/order/bill.pdf?reference=FRXXXXXXX&passwd=xxxx
[...]

3. Send a SMS

Without harmony proxies:

ovh.request('POST', '/sms/{serviceName}/jobs', {
  serviceName: 'sms-aaXXXXX-1',
  message: 'Hello World!',
  sender: 'Foo',
  receivers: ['0033600000000']
 }, function (err, result) {
  console.log(err || result);
});
$ node sms.js
{ totalCreditsRemoved: 1, ids: [ 42 ] }

With harmony proxies:

ovh.sms['sms-aaXXXXX-1'].jobs.$post({
  message: 'Hello World!',
  sender: 'Foo',
  receivers: ['0033600000000']
}, function (err, result) {
  console.log(err || result);
});
$ node --harmony-proxies sms.js
{ totalCreditsRemoved: 1, ids: [ 42 ] }

Developing with node-ovh

API schemas checks

During development, you can ensure that the calls you use are still in beta or in production. You just need to declare the list of the APIs you are using:

var ovh = require('node-ovh')({
  appKey: APP_KEY,
  appSecret: APP_SECRET,
  consumerKey: APP_CONSUMER_KEY,
  apis: ['me', 'sms']
});

ovh.me.foo.$get(function (err, result) {});
ovh.sms['sms-aaXXXXX-1'].histories.$get(function (err, result) {});
$ node --harmony-proxies dev.js
[OVH] Your call /me/foo was not found in the API schemas.
[OVH] Your API call /sms/sms-aaXXXXX-1/histories is tagged DEPRECATED since 2013-07-31T10:00:00+01:00 and will deleted on 2013-09-01T10:00:00+01:00. You can replace it with /sms/{serviceName}/outgoing/{id}

Debug mode

You can active the debug mode to log all the HTTP requests and responses:

var ovh = require('node-ovh')({
  appKey: APP_KEY,
  appSecret: APP_SECRET,
  consumerKey: APP_CONSUMER_KEY,
  debug: true
});

ovh.domains.$get(function (err, domains) {});
$ node --harmony-proxies domains.js
[OVH] API call: GET /1.0/domains
[OVH] API response to GET /1.0/domains : ["foo.com", "bar.fr"]

License

node-ovh is freely distributable under the terms of the MIT license.

Copyright (c) 2014 OVH SAS
Copyright (c) 2012 - 2013 Vincent Giersch

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of OVH and or its trademarks shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from OVH.