Calling any client method generates error "Error ReferenceError: locationid is not defined"
jleeothon opened this issue · 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.
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"
};
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?
@jleeothon @edtechd @hbi99 @k8188219 @sergioeliot2039 this may be a case of incomplete documentation, but you can get some context here: 682ed7c
See the examples.
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
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.
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