pcloud-sdk-js icon indicating copy to clipboard operation
pcloud-sdk-js copied to clipboard

Calling any client method generates error "Error ReferenceError: locationid is not defined"

Open jleeothon opened this issue 4 years ago • 7 comments

After updating to v2.0.0, my minimal script (in Node):

const pcloudSdk = require('pcloud-sdk-js');
const client = pcloudSdk.createClient(process.env.MY_ACCESS_TOKEN);

async function run() {
	const root = await client.listfolder(0);
	console.log(root);
}

run().catch(error => console.error('Error', error));

Running it with:

node test.js

Getting:

Error ReferenceError: locationid is not defined
    at ApiMethod (/Users/othon/dev/pcloud-scripts/node_modules/pcloud-sdk-js/lib/api/ApiMethod.js:42:21)
    at Object.api (/Users/othon/dev/pcloud-scripts/node_modules/pcloud-sdk-js/lib/client/createClient.js:51:35)
    at Object.listfolder (/Users/othon/dev/pcloud-scripts/node_modules/pcloud-sdk-js/lib/client/methods/listfolder.js:24:19)
    at run (/Users/othon/dev/pcloud-scripts/test.js:5:28)
    at Object.<anonymous> (/Users/othon/dev/pcloud-scripts/test.js:9:1)
    at Module._compile (internal/modules/cjs/loader.js:1200:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    at Module.load (internal/modules/cjs/loader.js:1049:32)
    at Function.Module._load (internal/modules/cjs/loader.js:937:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)

Indeed in ApiMethod.js a variable locationid is used but never defined.

jleeothon avatar Aug 20 '20 11:08 jleeothon

@sich @Moonick There is a bug in the src/api/ApiMethod.js How is this supposed to work?

edtechd avatar Oct 24 '20 23:10 edtechd

You need to add a global variable locationid. value can be either 1 or 2. global.locationid = 1;

meaning:

var locations = {
  1: "api.pcloud.com",
  2: "eapi.pcloud.com"
};

k8188219 avatar Aug 10 '21 06:08 k8188219

I am still getting this issue. Any help?

@k8188219 is that suggestion you posted meant to be used by the code doing calls with the pCloud client?

sergioeliot2039 avatar Aug 17 '21 01:08 sergioeliot2039

@jleeothon @edtechd @hbi99 @k8188219 @sergioeliot2039 this may be a case of incomplete documentation, but you can get some context here: https://github.com/pCloud/pcloud-sdk-js/commit/682ed7cf484e5034bbcd1efe46723a00b8681892

See the examples.

compwright avatar Aug 17 '21 18:08 compwright

I am still getting this issue. Any help?

@k8188219 is that suggestion you posted meant to be used by the code doing calls with the pCloud client?

Hello @sergioeliot2039, I fixed this problem by changing:

var requestUrl = _url.default.format({
  protocol: apiProtocol,
  host: locations[locationid] || apiServer,
  pathname: method,
  query: params
});

to:

var requestUrl = _url.default.format({
  protocol: apiProtocol,
  host: locations[2] || defaultApiServer,
  pathname: method,
  query: params
});

File is located in pcloud-sdk-js\lib\api\ApiMethod.js

I2rys avatar Feb 06 '22 12:02 I2rys

I'm trying to use it with Quasar, Vite and Vue 3. So far, the following configuration hacks are needed: in quasar.config.js, extendViteConfig

viteConf.define.global = {}
viteConf.define.ENV = 'window'

This works during development.

Running the code after publishing the app still results in ReferenceError: locationid is not defined. This is solved by adding window.locationid = 2 in a script tag.

alensiljak avatar Sep 09 '22 13:09 alensiljak

I can confirm this does work:

global.locationid = 1;    
const authToken = await getAuth();  // Calls userinfo
const client = pcloudSdk.createClient(authToken, 'pcloud', false);

I just would rather pass in locationid under ApiMethod or on the client level if possible.

There should be a better way of setting the locationid. I wouldn't know to set locationid when I don't use the built in oauth functions.

Example:

const locationid = 1; // Which translates to "api.pcloud.com"
const client = pcloudSdk.createClient(authToken, 'oauth', locationid);

Sometimes I've got a node server that already has an authentication token and doesn't need to prompt for another authToken.

The error I get is: ReferenceError: locationid is not defined at ApiMethod

digitalepicfury avatar Dec 08 '22 06:12 digitalepicfury