Skip to content

Instantly share code, notes, and snippets.

@phillipharding
Created February 12, 2020 15:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipharding/37734a814002b8b30f4ee3679d53a1ac to your computer and use it in GitHub Desktop.
Save phillipharding/37734a814002b8b30f4ee3679d53a1ac to your computer and use it in GitHub Desktop.
//import { sp, Site, spGet, SharePointQueryable } from "@pnp/sp/presets/all";
import { sp } from "@pnp/sp";
import { Site } from "@pnp/sp/sites";
import "@pnp/sp/sites";
import { IFetchOptions } from "@pnp/common";
console.clear();
(async () => {
// get site using PnPJs
const web1 = await sp.site.select("Id,RootWeb/Id,RootWeb/Title").expand("RootWeb")();
console.log("Root Web: ", web1);
// get site using v2 sites API
let options = {
method: "GET",
credentials: "include",
};
let response = await fetch("https://platinumdogsconsulting.sharepoint.com/_api/v2.0/sites/platinumdogsconsulting.sharepoint.com:/sites/edwardsfssopdev", options);
console.log("Site response: ", response);
let responseBody = await response.json();
console.log("Site response json: ", responseBody);
// get site drive item using v2 sites API and convert to PDF
try {
let options = {
"redirect": "follow",
"method": "GET",
};
response = await fetch("https://platinumdogsconsulting.sharepoint.com/_api/v2.0/sites/platinumdogsconsulting.sharepoint.com,1592023b-9916-48c5-90e8-f32410113a53,b2223894-e7b6-442c-8f37-eca09f759e6e/drives/b!OwKSFRaZxUiQ6PMkEBE6U5Q4IrK25yxEjzfsoJ91nm4nmmbiqWWORrDPrC3tYsNA/root:/whizz-tube-16178-plan-186.docx:/content?format=PDF", options);
console.log("Convert item response:", response);
console.log("Redirect url:", response.url);
} catch (e) {
console.log("Convert error: ", e);
}
// download the convert item using the redirected URL
try {
let options = {
"redirect": "follow",
"method": "GET",
};
response = await fetch(response.url, options);
console.log("Get converted content response: ", response);
let blobData = await response.arrayBuffer();
console.log("Get converted content response data: ", blobData);
} catch (e) {
console.log("Get converted content error: ", e);
}
})().catch(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment