• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Node.js wrapper for REST APIs

Adobe Employee ,
Aug 15, 2023 Aug 15, 2023

Copy link to clipboard


If folks are interested, I've got a Node.js *opinionated* wrapper for the REST APIs. It does a few things I particularly like:


* Combines the upload process into one call 

* Can poll a job (currently hard coded at two seconds)

* Can download when a job is done (ie, poll until done, then save)


You can find the source here: https://github.com/cfjedimaster/document-services-demos/tree/main/serviceswrapper


I'm only "officially" supporting Extract, but I've got a few other endpoints in there as well that I want to change the method signature on a bit. 


Here's a full example where I call Extract on a PDF and read the JSON:


const ServicesWrapper = require('./ServicesWrapper');

let sw = new ServicesWrapper(process.env.CLIENTID, process.env.CLIENTSECRET);

(async () => {
	let filePath = '../source_pdfs/schoolcalendar.pdf';
	let mediaType = 'application/pdf';

	let asset = await sw.upload(filePath, mediaType);
	console.log('PDF uploaded');

	let job = await sw.createExtractJob(asset);
	console.log('Extract job started.');

	let result = await sw.pollJob(job);
	console.log('Job done');

	One example, download the json, or you can download the zip at result.resource.downloadUri...
	await sw.downloadFile(result.content.downloadUri, './extract.json');
	But instead, let's just fetch the json direct.
	let jsonReq = await fetch(result.content.downloadUri);
	let json = await jsonReq.json();
	console.log(JSON.stringify(json.extended_metadata, null, '\t'));

PDF Extract API , PDF Services API , REST APIs






Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation