Git Product home page Git Product logo

node-ovh's Introduction

Node.js Wrapper for OVH APIs

The easiest way to use the OVH.com APIs in your node.js applications.

NPM Version Build Status Coverage Status

// Create your first application tokens here: https://api.ovh.com/createToken/?GET=/me
var ovh = require('ovh')({
  appKey: process.env.APP_KEY,
  appSecret: process.env.APP_SECRET,
  consumerKey: process.env.CONSUMER_KEY
});

ovh.request('GET', '/me', function (err, me) {
  console.log(err || 'Welcome ' + me.firstname);
});

You can also use the promised version like this:

ovh.requestPromised('GET', '/me')
  .then(function (response) {
    //Do what you want
  })
  .catch(function (err) {
    //Return an error object like this {error: statusCode, message: message}
  });

Installation

The easiest way to get the latest stable release is to grab it from the npm registry.

$ npm install ovh

Alternatively, you may get latest development version directly from Git.

$ npm install git://github.com/ovh/node-ovh.git

Example Usage

Login as a user

1. Create an application

Depending the API you plan to 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).

2. 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 US: ovh-us
  • OVH North-America: ovh-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.

3. Let's play!

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

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

Migration from 1.x.x to 2.x.x without Proxy support

For example if you use the OVH Europe API, you'll have to check on https://eu.api.ovh.com/console/ the endpoints available for your feature.

In order to have the informations about the bill with id "0123".

  • Before in 1.x.x with Proxy:
ovh.me.bill["0123"].$get(function (err, billInformation) {

});
  • Now in 2.x.x with promise:
ovh.requestPromised('GET', '/me/bill/0123') //This route has been found at https://eu.api.ovh.com/console/
  .then(function (billInformation) {

  })
  .catch(function (err) {

  });

Full documentation and examples

The full documentation is available online: https://ovh.github.io/node-ovh.

Hacking

Get the sources

git clone https://github.com/ovh/node-ovh.git
cd node-ovh

You've developed a new cool feature? Fixed an annoying bug? We'd be happy to hear from you!

Run the tests

Tests are based on mocha. This package includes unit and integration tests.

git clone https://github.com/ovh/node-ovh.git
cd node-ovh
npm install -d
npm test

Integration tests use the OVH /domain/zone API, the tokens can be created here.

export APP_KEY=xxxxx
export APP_SECRET=yyyyy
export CONSUMER_KEY=zzzzz
export DOMAIN_ZONE_NAME=example.com
npm run-script test-integration

Documentation

The documentation is based on Github Pages and is available in the gh-pages branch.

Supported APIs

OVH Europe

OVH US

OVH North America

SoYouStart Europe

SoYouStart North America

Kimsufi Europe

Kimsufi North America

Related links

node-ovh's People

Contributors

antleblanc avatar bitdeli-chef avatar bnjjj avatar clovel avatar frenautvh avatar gierschv avatar mortonfox avatar naholyr avatar rbeuque74 avatar tadhglewis avatar trixterthetux avatar vincentcasse avatar yadutaf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-ovh's Issues

ovh sms node js : Got error 403: 'This call has not been granted'.

Create app key, app secret key and consumer key and configured then cal this function i got error
403: 'This call has not been granted'.

var ovh = require('ovh')({
  appKey: 'your_app_key',
  appSecret: 'your_app_secret',
  consumerKey: 'your_consumer_key'
});

 // Get the serviceName (name of your sms account)
ovh.request('GET', '/sms', function (err, serviceName) {
  if(err) {
    console.log(err, serviceName);
  }
  else {
    console.log("My account SMS is " + serviceName);

    // Send a simple SMS with a short number using your serviceName
    ovh.request('POST', '/sms/' + serviceName + '/jobs', {
      message: 'Hello World!',
      senderForResponse: true,
      receivers: ['0033600000000']
    }, function (errsend, result) {
      console.log(errsend, result);
    });
  }
});

Build fail for node < 4

Build fails on old version of node.
Mocha doesn't support node < 6 now but still works in v4.

I'll push a PR to update travis to drop tests on node < 4

POST on storage/access give a 403 ERROR

I do this:

var ovh = require('ovh')({
  endpoint: 'ovh-eu',
  appKey: 'myAK',
  appSecret: 'mySK',
  consumerKey: 'myCK'
});

ovh.requestPromised('GET', '/me')
.then(function (response) {
console.log('spit it out!: ', response)
})
.catch(function (err) {
console.log('ERROR!: ', err.error, err.message)
});
  
ovh.requestPromised('GET', '/cloud/project/myServiceName/storage/access')
.then(function (response) {
console.log('spit it out!: ', response)
})
.catch(function (err) {
console.log('ERROR!: ', err.error, err.message)
});

ovh.requestPromised('POST', '/cloud/project/myServiceName/storage/access')
.then(function (response) {
console.log('spit it out!: ', response)
})
.catch(function (err) {
console.log('ERROR!: ', err.error, err.message)
});


OUTPUT:

ERROR!:  403 This call has not been granted
spit it out!:  { ...me output...}
spit it out!:  { token: 'etc..........', endpoints: etc.}

So somehow the POST on storage/access give a 403 ERROR. Why is that?

Unable to fetch OVH API time

Hello
When I try to call the API, I have the message 'Unable to Fetch OVH API time'.

The appKey, appSecret and ConsumerKey are good.

I use the framework Gatsby.

Thank you for your help

Default to ES6

Si c'est pour apporter une version es6 (ce qui est parfait) et en profitant de la version majeure 2.0 (qui 'autorise' le breaking change), pourquoi ne pas l'avoir utilisée par défaut ?

Une bonne pratique reste pour les library es6 de laisser le transpilage/babel à l**'application layer** qui souhaitera l'utiliser (ou non) .

Example for instance creation from another backup image

I am using your API in order to automate our systems setup process, I have
run into an issue. I seem to be unable to figure out how to make a call to
this endpoint:
POST /cloud/project/{serviceName}/instance
If you could provide me with an example, that would be great.
I am using OVH- NodeJS as the use case requires it to be in JavaScript.
For the example, we need to be able to create an instance from the backup
of another instance. and we need automated backups on.
here is what I have done so far, but a 400 gets returned!
return new Promise((resolve,reject) =>
{
ovh.request('POST', '/cloud/project/'+config.ovh_service_name+
'/instance', {
flavorId: "4d4fd037-9493-4f2b-9afe-b542b5248eac",
imageId: "309e9cc9-8318-49a0-9c41-6d9b7ec1f071",
sshKeyId: "51326c68636d4675",
monthlyBilling: false,
name:"name",
region: "ovh-eu",
autobackup:{rotation:7,cron:"0 0 * * *"}
}, function (err, result) {
if(err)
reject(err)
else
resolve(result);
});

mocks

Is there a way to mock the api ?

Proxy.create is not a function with nodeJS v6

The callstack

    return Proxy.create(handler);
                 ^

TypeError: Proxy.create is not a function
    at Ovh.createRootProxy (/Users/user/Projects/xxxx/node_modules/ovh/lib/ovh.js:226:18)
    at new Ovh (/Users/user/Projects/xxxx/node_modules/ovh/lib/ovh.js:89:19)
    at module.exports (/Users/user/Projects/xxxx/node_modules/ovh/lib/ovh.js:658:12)
    at Object.<anonymous> (/Users/user/Projects/xxxx/service/helper/ovh/mailingList.js:7:25)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Module.require (module.js:466:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/user/Projects/xxxx/service/helper/ovh/mailingLists.js:3:15)
    at Module._compile (module.js:541:32)
    at Object.Module._e

Can't add a wildcard email redirection

Hi,

As asked by an user, I'm currently fixing a Node.JS app using the Node OVH API so it can allow an user to use a wildcard email redirection (*@domain.tld). However, when it comes to sending the request via the API, the answer is:

{ message: 'Invalid email address: *@domain.tld }

Is it even possible to add this kind of redirection? If not, why? I have a lot of friends using other email hosting who use a wildcard alias all the time...

P.S.: I'm not sure here's the right place to ask this question. If not, could you please redirect it to the right person? I may have a few cookies left as a thank-you gift.

ERR_UNESCAPED_CHARACTERS

I got this kind of error :

ovh_dns    | TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters
ovh_dns    |     at new ClientRequest (_http_client.js:151:13)
ovh_dns    |     at Object.request (https.js:310:10)
ovh_dns    |     at Ovh.request (/app/node_modules/ovh/lib/ovh.es5.js:380:23)
ovh_dns    |     at /app/node_modules/ovh/lib/ovh.es5.js:457:23
ovh_dns    |     at Promise._execute (/app/node_modules/bluebird/js/release/debuggability.js:384:9)
ovh_dns    |     at Promise._resolveFromExecutor (/app/node_modules/bluebird/js/release/promise.js:518:18)
ovh_dns    |     at new Promise (/app/node_modules/bluebird/js/release/promise.js:103:10)
ovh_dns    |     at Ovh.requestPromised (/app/node_modules/ovh/lib/ovh.es5.js:456:14)
ovh_dns    |     at Task.execution (/app/src/index.js:43:31) {
ovh_dns    |   code: 'ERR_UNESCAPED_CHARACTERS'
ovh_dns    | }

My code is pretty simple :

try {
    const [record, ip] = await Promise.all([getRecord(zone, params), publicIp.v4()]);

    if (record.target === ip) {
      console.log('Already good ip, do nothing')
      return
    }

    console.log(`Changing ip from ${record.target} to ${ip}`);

    const putRequest = await ovh.requestPromised('PUT', `/domain/zone/${zone}/record/${record.id}`, {
      target: ip
    });

    const refresh = await ovh.requestPromised('POST', ` /domain/zone/${zone}/refresh`);

} catch (e) {   
  console.error(e)
}

Task.execution (/app/src/index.js:43:31 indicate that it's the line :

const refresh = await ovh.requestPromised('POST', /domain/zone/${zone}/refresh);

X-Ovh-Signature only sent to /auth

Requests are not signed because of Line 366 in ovh.es5.js :
if (path.indexOf('/auth') < 0) {

That 'if' shouldn't exist at all, right?

Library treats parameters equal to 0 as null and does not send them

I am executing the following call in order to add a firewall rule on the IP:

await ovh.requestPromised('POST', '/ip/' + encodeURIComponent(ipblock) + '/firewall/' + ip + '/rule', ruleObj);

Consider the following ruleObj:

ruleObj = {
    action: 'permit',
    destinationPort: null,
    protocol: 'udp',
    sequence: 0,
    source: '8.8.8.8/32',
    sourcePort: 53,
    tcpOption: null
};

This will fail with error: error=400, message=Missing sequence parameter while calling creation handler

However, when I use the following, it works!:

ruleObj = {
    action: 'permit',
    destinationPort: null,
    protocol: 'udp',
    sequence: new String(0),
    source: '8.8.8.8/32',
    sourcePort: 53,
    tcpOption: null
};

It seems like the ovh library is treating numeric 0 as null and not sending it, while a String of 0 is properly sent. Other numbers work as expected when sent as Numbers.

Typescript support

Are there any plans to provide type definitions for typescript? It is one of the key things preventing us from making the move from python.

events api not working

Hello,
I wanted to test the events api to receive ringing events and others but I can't seem to receive anything, here is what I tried the following to create a new token:

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

var params = {
  expiration: "1 day"
}
ovh.request('POST', '/telephony/XXX/service/XXX/eventToken', params, (err, token) => {
  console.log(err || token);
})

And then called https://events.voip.ovh.net/?token=<TOKEN> but when I call my ovh number (with an X-Lite registered on it) I receive nothing and the call eventually timeout.

Do I need to activate anything to use the events api ?

Thanks for any help

validationUrl issue

Hi,
I am starting using node-ovh and put following code:

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

ovh.request('POST', '/auth/credential', {
    'accessRules': [
      { 'method': 'GET', 'path': '/*'},
      { 'method': 'POST', 'path': '/*'},
      { 'method': 'PUT', 'path': '/*'},
      { 'method': 'DELETE', 'path': '/*'}
    ]
  }, function (error, credential) {
    console.log('OVH: ', error || credential)
  })

This gives me:

{ validationUrl:
   'https://eu.api.ovh.com/auth/?credentialToken=_removed_',
  consumerKey: '_removed_',
  state: 'pendingValidation' }

So I go to such validationUrl, but this gives me the following error page

image

I am doing something wrong?
I tried to reach same url but with my OVH account already logged in another tab (session opened) but issue is then.

I hope you guys can help.
Thank you
Fabrice

Impossible to generate my 'Consumer Key' : Error : invalid account / password.

Hello

My problem is in the title.

I follow the first steps here : https://docs.ovh.com/gb/en/api/first-steps-with-ovh-api/
I created my app via https://eu.api.ovh.com/createApp/ (no problem here)
But when I try to generate my CK via https://eu.api.ovh.com/createToken/ I get the "Error : Invalid account / password. But it is not invalid.

Tell me if you need more informations.

I hope someone can help me here.
Thank you
Romain

Cors issue when call api

Hello
I have a cors issue when I call the api :

Access to fetch at 'https://eu.api.ovh.com/1.0/me' from origin 'http://localhost:8081' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

appKey, appSecret and consumerKey are ok.
How can I enable it ? I use nuxt.js. Thanks

is it possible to create vps via api in ovh

Bad Request (400)
{ "message": "Custom field vps_ssd_datacenter is mandatory for product ssd_model1_2018v1\nCustom field vps_ssd_os is mandatory for product ssd_model1_2018v1" }

i get this error when i try to validate my shopping and create order , is there is an option to add OS in post request or it's not possible to create vps with this api ?

HTTPS proxy support

For the poor guys and girls among us who have to deal with HTTPS proxies, a way to tell the ovh module that the .request method should attempt to access the OVH HTTPS API through a proxy would be great :)

AFAICT, the proper way to have HTTP/HTTPS requests go through a proxy is to pass an instance of https.Agent ( https://nodejs.org/api/https.html#https_class_https_agent ) as 'agent' property of the 'options' argument to https.request().
One of the ways to create such agents is https://www.npmjs.com/package/tunnel-agent , which has the same API as https://www.npmjs.com/package/tunnel .

I could attempt to contribute a patch by myself, but I'd rather discuss the direction with the maintainer up front. I can see at least three reasonable ways to pass the agent to an instance of the ovh module for .request() to use (.loadSchemasRequest() already takes options passed directly to https.get()):

  1. at initialization time, require('ovh')({ ...}) - less flexible IMO;
  2. at any point, through a setter which would apply to future invocations of the .request() method;
  3. at request time, through a new argument to e.g. ovh.request();
    and at least a dirty way: pass the agent through a specially-named property of the 'params' argument to ovh.request(), which is probably what I'll attempt to use for my own purposes, as a temporary measure.
    Your preference may not match mine, and might not even be listed here :)

error on npm update

Hi, I've just updated my project and now, something not work, on ovh module, the error is :

TypeError : Proxy.create is not a function
refer to : ovh.js on line 226

Someone ever had this error?

Access to 'GET /auth/currentCredential' route

Hi there from Toulouse ;).

I just started playing around with the Node API wrapper. I got my consumer key and validated it online.
Then I wanted to access GET /auth/currentCredential route and got the following response:

{ error: 401, message: 'You must login first' }

Now I noticed that path check for setting the X-Ovh-Consumer header which obviously returns false for a request to any /auth/* route. I think that it is the culprit, as commenting out the check, for test purposes, seemed to work, and I got my expected response:

{ ovhSupport: false,
  status: 'validated',
  applicationId: 38683,
  credentialId: 116223292,
  rules: 
   [ { method: 'GET', path: '/domain/zone/*' },
     { method: 'POST', path: '/domain/zone/*' },
     { method: 'PUT', path: '/domain/zone/*' },
     { method: 'DELETE', path: '/domain/zone/*' } ],
  expiration: '2017-07-12T08:08:44+02:00',
  lastUse: null,
  creation: '2017-07-11T08:07:49+02:00' }

Checking out the code for the PHP, there doesn't seem to be such a condition for setting the Consumer and Signature headers. Shouldn't the check on path be more specific? Or am I getting something wrong?

Not sure how to use

Hi,

I'm not really sure how to use your module from headless app? I mean kind of application which has no GUI. Do You have full usage example (with obtaining and consuming CK key) for this kind of scenario?

Where to find the parameters definitions ?

Hello, i'm trying to use your API but I can't find the type definition of the parameters.

For exemple :

Endpoint :  post /order/cart/{cartId}/webHosting 

duration: Duration
planCode: string;
pricingMode: string;
quantity: long;

Where am I supposed to find the expected value for pricingMode | planCode | duration ?

Thank you and have a good day

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.