Sppull library: download files returning empty array for sharepoint files - node.js

Code:
const context = {
siteUrl: 'https://<tenant>.sharepoint.com',
creds: {
username: "<username>#<tenant>.onmicrosoft.com",
password: "***",
online: true
}
};
const options2 = {
spRootFolder: "Shared%20Documents/docverify",
dlRootFolder: "./docverify"
};
SPPull.download(context, options2)
.then((downloadResults) => {
console.log("Files are downloaded", downloadResults);
console.log("For more, please check the results", JSON.stringify(downloadResults));
})
.catch((err) => {
console.log("Core error has happened", err);
});
Output:
Files are downloaded []
For more please check the results []
Attached screenshot of the file in sharepoint
enter image description here
Files to be downloaded

Related

How to create a Plaid LinkToken using Node JS?

I believe Plaid updated its createLinkToken documentation, but I can't seem to figure out what I'm doing wrong here. I'm taking a course, and here is the old code that worked in using a FirebaseFunction to create a link token with Plaid:
exports.createPlaidLinkToken = functions.https.onCall(async (data, context) => {
const customerId = context.auth.id;
const plaidClient = new plaid.Client({
clientID: functions.config().plaid.client_id,
secret: functions.config().plaid.secret,
env: plaid.environments.sandbox,
options: {
version: '2019-05-29',
},
});
return plaidClient.createLinkToken({
user: {
client_user_id: customerId,
},
client_name: "Bon Voyage",
products: ["auth"],
country_codes: ["US"],
language: "en"
}).then((apiResponse) => {
const linkToken = apiResponse.link_token;
return linkToken;
}).catch((err) => {
console.log(err);
throw new functions.https.HttpsError("internal", "Unable to create plaid link token: " + err);
});
});
I've tried a number of things. I know plaid.Client is now new.Configuration but I can't seem to figure out the rest. Any helpers?
You can see in the comments below what I've tried. I've modified the code as follows, and now receive Error status code 400.
const plaid = require('plaid');
const { Configuration, PlaidEnvironments, PlaidApi } = require("plaid");
exports.createPlaidLinkToken = functions.https.onCall(async (data, context) => {
const customerId = context.auth.uid;
const configuration = new Configuration({
basePath: PlaidEnvironments.sandbox,
baseOptions: {
headers: {
plaid_client_id: functions.config().plaid.client_id,
plaid_secret: functions.config().plaid.secret,
plaid_version: '2021-05-20'
},
},
});
const plaidClient = new PlaidApi(configuration);
return plaidClient.linkTokenCreate({
user: {
client_user_id: customerId,
},
client_name: "Bon Voyage",
products: ["auth"],
country_codes: ["US"],
language: "en"
})
.then((apiResponse) => {
const linkToken = apiResponse.data.link_token;
// const linkToken = response.link_token
return linkToken;
})
.catch((err) => {
console.log(err);
throw new functions.https.HttpsError(
"internal",
" Unable to create plaid link token: " + err
);
});
});
It's difficult to answer this question as you haven't mentioned what you've tried or what error you are experiencing. Have you reviewed the sample implementations in the docs that show how to do this, including the sample code in the Quickstart and Tiny Quickstart?
Off the top of my head, I do see that this sample code specifies an API version of 2019-05-29, which is not compatible with the latest version of the Node client library that uses new.Configuration.

How to make kuzzle-device-manager plugin API actions works?

I successfully installed and loaded kuzzle-device-manager in the backend file:
import { Backend } from 'kuzzle';
import { DeviceManagerPlugin } from 'kuzzle-device-manager';
const app = new Backend('playground');
console.log(app.config);
const deviceManager = new DeviceManagerPlugin();
const mappings = {
updatedAt: { type: 'date' },
payloadUuid: { type: 'keyword' },
value: { type: 'float' }
}
deviceManager.devices.registerMeasure('humidity', mappings)
app.plugin.use(deviceManager)
app.start()
.then(async () => {
// Interact with Kuzzle API to create a new index if it does not already exist
console.log(' started!');
})
.catch(console.error);
But when i try to use controllers from that plugin for example device-manager/device with create action i get an error output.
Here is my "client" code in js:
const { Kuzzle, WebSocket } = require("kuzzle-sdk")
const kuzzle = new Kuzzle(
new WebSocket('KUZZLE_IP')
)
kuzzle.on('networkError', error => {
console.error('Network Error: ', error);
})
const run = async () => {
try {
// Connects to the Kuzzle server
await kuzzle.connect();
// Creates an index
const result = await kuzzle.query({
index: "nyc-open-data",
controller: "device-manager/device",
action: "create",
body: {
model: "model-1234",
reference: "reference-1234"
}
}, {
queuable: false
})
console.log(result)
} catch (error) {
console.error(error.message);
} finally {
kuzzle.disconnect();
}
};
run();
And the result log:
API action "device-manager/device":"create" not found
Note: The nyc-open-data index exists and is empty.
We apologize for this mistake in the documentation, the device-manager/device:create method is not available because the plugin is using auto-provisioning until the v2.
You should send a payload to your decoder, the plugin will automatically provision the device if it does not exists https://docs.kuzzle.io/official-plugins/device-manager/1/guides/decoders/#receive-payloads

File not found google drive API

I am trying to list files and trash some file from it but the update API throwing error file not find. Though list API is returning me the result and I am passing the same file id to the update API.
drive.files.list(
{
q:
"mimeType='application/zip' and name = '" +
prevFileName +
"' and '" +
parent +
"' in parents",
fields: "files(kind,id,name,mimeType,teamDriveId,parents,createdTime)",
corpora: "drive",
includeTeamDriveItems: true,
supportsTeamDrives: true,
teamDriveId: teamDriveId
},
(err, res) => {
if (err) {
console.log("Error listing files ", err.message);
} else {
const prevFiles = res && res.data && res.data.files;
console.log("prevFiles : ", prevFiles);
if (prevFiles && prevFiles[0] && prevFiles[0].name === prevFileName) {
drive.files.update(
{
fileId: prevFiles[0].id
},
{ resource: { trashed: true } },
(err, result) => {
if (!err) {
console.log("Prev file successfully deleted : ", result);
resolve("File upload SuccessFully: ", file.data);
} else {
console.error("Error removing prev file :: ", err);
}
}
);
}
}
}
);
Here I am getting a file with some json response
[ { kind: 'drive#file',
id: 'ksnadoasjndajn12n1n212',
name: 'xxx_x_x.zip',
mimeType: 'application/zip',
parents: [ 'xxxx-sandadaadakmke' ],
createdTime: '2021-07-14T06:12:11.169Z',
teamDriveId: 'xxxonaijsojxxx' } ]
But when I am passing this id in update API it is throwing error.
My Auth scopes are
var SCOPES = [
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/drive.appdata",
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/drive.readonly",
"https://www.googleapis.com/auth/drive.metadata.readonly",
"https://www.googleapis.com/auth/drive.metadata",
"https://www.googleapis.com/auth/drive.photos.readonly"
];
Please help me out in this.
Thanks.
Since your drive.files.list request contains includeTeamDriveItems: true and supportsTeamDrives: true, you should specify the respective option for drive.files.update
By default supportsAllDrives is set to false unless you explicitly set it to true.
Thuss, files located on a team drive will not be found.
Note: supportsTeamDrives is deprecated, setting supportsAllDrives to true is enough.

create theme on shopify using api

I am trying to create an app and within the app the user can install a theme, however, I can't seem to work out why the theme is not being created. It keeps pulling the themes already installed on my store to the console, my code doesn't seem to create a theme that would show up on my shopify store.
server.js
router.post('/api/theme', async (ctx) => {
try {
const results = await fetch("https://" + ctx.cookies.get('shopOrigin') + "/admin/themes.json", {
headers: {
'X-Shopify-Access-Token': ctx.cookies.get('accessToken')
},
})
.then(response => response.json())
.then(json => {
console.log("https://" + ctx.cookies.get('shopOrigin') + "/admin/api/2020-01/themes.json", json);
});
ctx.body = {
data: results
};
} catch (err) {
console.log(err)
}
});
frontend .js file
async function getUser() {
var url = `/api/theme`;
var method = 'post';
const theme = {
theme: {
name: "Lemongrass",
src: "https://codeload.github.com/Shopify/skeleton-theme/zip/master"
}
};
const data = JSON.stringify(theme);
fetch(url, { method: method, body: data})
}
In order to create a theme you need a zip archive of the theme you like to create.
The end point should be /admin/api/2020-01/themes.json and the body should be something like this:
{
"theme": {
"name": "Theme name",
"src": "http://themes.shopify.com/theme.zip",
"role": "unpublished"
}
}
Please refer to https://shopify.dev/docs/admin-api/rest/reference/online-store/theme#create-2020-01 for more information.
At the moment from your code I don't see neither the correct POST request, neither the archive file.

Automatic download of files from sharepoint with nodejs

I am new on javascript and I am trying to automate download of files from sharepoint with nodejs. The code is the following one:
const { sppull } = require("sppull");
const context = {
siteUrl: "xxx",
creds: {
username: "xxx",
password: "xxx"
}
};
const options = {
spRootFolder: "Shared%20Documents/SSC%20Projection/ZIP",
dlRootFolder: "W:\\SCM\\RawData\\SSC_Proj"
};
sppull(context, options)
.then((downloadResults) => {
console.log("Files are downloaded");
console.log("For more, please check the results", JSON.stringify(downloadResults));
})
.catch((err) => {
console.log("Core error has happened", err);
});
However,the engine is showing the following error message:
Folders proceeding: 0 out of 0 [recursive scanning...]
Error in getFolderContent: Cannot read property 'Folders' of undefined
Core error has happened Cannot read property 'Folders' of undefined
Process finished with exit code 0

Resources