1

I'm trying to use VersionOne JS SDK in Node.js (https://github.com/versionone/VersionOne.SDK.JavaScript). I'm simply downloading whole library, placing it alongside with my js file:

var v1 = require('./v1sdk/v1sdk.js');
var V1Server = v1.V1Server;
console.log(v1);
console.log(V1Server);

Unfortunately something seems wrong, the output I get after calling

node app.js

is:

{}
undefined

Can somebody point me what I'm doing wrong or check whether the sdk is valid. Thanks!

Jakub Krawczyk
  • 103
  • 1
  • 8

2 Answers2

2

You can see in the source where V1Server is defined, that it's a class with a constructor. So you need to use the new keyword and pass the arguments for your environment.

https://github.com/versionone/VersionOne.SDK.JavaScript/blob/master/client.coffee#L37

var server = new V1Server('cloud'); //and more if you need

danlash
  • 678
  • 1
  • 6
  • 13
  • But here comes the problem with getting to V1Server. V1Server is exported and what I understand is that before calling constructor I must 'import' it as a variable. Apparently that is not working for me, I get undefined obj. When trying to instantiate server I get: TypeError: undefined is not a function. – Jakub Krawczyk Oct 24 '13 at 09:13
  • Jakub, if you want some more assistance with this, you can come see us in our public HipChat room at: http://www.hipchat.com/grNeYfSGw. Also, I'd be happy to get on a GoToMeeting call with you and help you figure it out. It's been a while since we've done anything with the JS SDK, but since you are attempting to use it, we'd love to help you out. – JoshGough Nov 01 '13 at 14:27
  • The HipChat link changed to http://www.hipchat.com/gwVRHWbnY ... Not sure if there's a way to make that persist or not. – JoshGough Jan 21 '14 at 15:22
2

Can you try the sample.js script that I just updated from here:

https://github.com/versionone/VersionOne.SDK.JavaScript/blob/master/sample.js

It pulls in the two modules like this:

var  V1Meta = require('./v1meta').V1Meta;
var  V1Server = require('./client').V1Server;

var hostname = "www14.v1host.com"; 
var instance = "v1sdktesting";
var username = "api";
var password = "api";
var port = "443";
var protocol = "https";

var server = new V1Server(hostname, instance, username, password, port, protocol);

var v1 = new V1Meta(server);

v1.query({
    from: "Member",
    where: {
        IsSelf: 'true'
    },
    select: ['Email', 'Username', 'ID'],
    success: function(result) {
        console.log(result.Email);
        console.log(result.Username);
        console.log(result.ID);
    },    
    error: function(err) { // NOTE: this is not working correctly yet, not called...
        console.log(err);
    }
});

You might have to get the latest and build the JS from CoffeeScript.

I think I was trying out "browserify" last year and that's how the "v1sdk.js" file got generated. But I'm not sure if that's the best approach if you're using node. It's probably better just to do it the way the sample.js file is doing it.

However, I did also check in a change to v1sdk.coffee which property exports the two other modules, just as a convenience. With that, you can look at sample2.js. The only different part there is this, which is more like you were trying to do with your example:

var  v1sdk = require('./v1sdk');

var hostname = "www14.v1host.com"; 
var instance = "v1sdktesting";
var username = "api";
var password = "api";
var port = "443";
var protocol = "https";

var server = new v1sdk.V1Server(hostname, instance, username, password, port, protocol);

var v1 = new v1sdk.V1Meta(server);
JoshGough
  • 964
  • 1
  • 8
  • 16
  • Note: you might also be interested in our newer endpoint: http://community.versionone.com/Developers/Developer-Library/Recipes/Tour_of_query.v1 – JoshGough Nov 01 '13 at 22:45