Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jleeothon opened this issue Aug 20, 2020 · 7 comments

Comments

@jleeothon
Copy link
Contributor

jleeothon commented Aug 20, 2020

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.

@edtechd
Copy link

edtechd commented Oct 24, 2020

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

hbi99 added a commit to hbi99/pcloud-sdk-js that referenced this issue Nov 23, 2020
@k8188219
Copy link

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"
};

@sergioeliot2039
Copy link

sergioeliot2039 commented Aug 17, 2021

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?

@compwright
Copy link

@jleeothon @edtechd @hbi99 @k8188219 @sergioeliot2039 this may be a case of incomplete documentation, but you can get some context here: 682ed7c

See the examples.

@I2rys
Copy link

I2rys commented Feb 6, 2022

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

@alensiljak
Copy link

alensiljak commented Sep 9, 2022

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.

@digitalepicfury
Copy link

digitalepicfury commented Dec 8, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants