Create business-critical documents like invoices, contracts, sales proposals, and work orders automatically.
Emit new event each time a new order is cancelled.
Emit new event for each new customer added to a store.
Emit new event for each new draft order submitted to a store.
import fs from "fs";
import axios from "axios";
import {
ServicePrincipalCredentials,
PDFServices,
MimeType,
DocumentMergeParams,
OutputFormat,
DocumentMergeJob,
DocumentMergeResult
} from "@adobe/pdfservices-node-sdk";
export default defineComponent({
props: {
adobe_document_generation_api: {
type: "app",
app: "adobe_document_generation_api",
}
},
async run({steps, $}) {
// Configuration constants
const PDF_SERVICES_CLIENT_ID = this.adobe_document_generation_api.$auth.client_id;
const PDF_SERVICES_CLIENT_SECRET = this.adobe_document_generation_api.$auth.client_secret;
try {
// Initial setup, create credentials instance
const credentials = new ServicePrincipalCredentials({
clientId: PDF_SERVICES_CLIENT_ID,
clientSecret: PDF_SERVICES_CLIENT_SECRET
});
// Creates a PDF Services instance
const pdfServices = new PDFServices({ credentials });
// Creates an asset(s) from source file(s) and upload
const response = await axios.get("https://developer.adobe.com/document-services/docs/receiptTemplate.docx", { responseType: 'stream' });
const readStream = response.data;
const inputAsset = await pdfServices.upload({
readStream,
mimeType: MimeType.DOCX
});
// Setup input data for the document merge process
const jsonDataForMerge = {
"author": "Gary Lee",
"Company": {
"Name": "Projected",
"Address": "19718 Mandrake Way",
"PhoneNumber": "+1-100000098"
},
"Invoice": {
"Date": "January 15, 2021",
"Number": 123,
"Items": [
{
"item": "Gloves",
"description": "Microwave gloves",
"UnitPrice": 5,
"Quantity": 2,
"Total": 10
},
{
"item": "Bowls",
"description": "Microwave bowls",
"UnitPrice": 10,
"Quantity": 2,
"Total": 20
}
]
},
"Customer": {
"Name": "Collins Candy",
"Address": "315 Dunning Way",
"PhoneNumber": "+1-200000046",
"Email": "cc@abcdef.co.dw"
},
"Tax": 5,
"Shipping": 5,
"clause": {
"overseas": "The shipment might take 5-10 more than informed."
},
"paymentMethod": "Cash"
};
// Create parameters for the job
const params = new DocumentMergeParams({
jsonDataForMerge,
outputFormat: OutputFormat.PDF
});
// Creates a new job instance
const job = new DocumentMergeJob({ inputAsset, params });
// Submit the job and get the job result
const pollingURL = await pdfServices.submit({ job });
const pdfServicesResponse = await pdfServices.getJobResult({
pollingURL,
resultType: DocumentMergeResult
});
// Get content from the resulting asset(s)
const resultAsset = pdfServicesResponse.result.asset;
const streamAsset = await pdfServices.getContent({ asset: resultAsset });
// Creates a write stream and copy stream asset's content to it
const outputFilePath = "/tmp/generatePDFOutput.pdf";
console.log(`Saving asset at ${outputFilePath}`);
return new Promise((resolve, reject) => {
const writeStream = fs.createWriteStream(outputFilePath);
streamAsset.readStream.pipe(writeStream);
writeStream.on('finish', () => resolve(outputFilePath));
writeStream.on('error', reject);
});
} catch(err) {
console.error('Error generating PDF:', err);
throw err;
}
},
})
The Shopify Admin REST & GraphQL API unleashes a myriad of possibilities to automate and enhance online store operations. It provides programmatic access to Shopify functionalities, allowing users to manage products, customers, orders, and more. Leveraging the Shopify Admin API within Pipedream, developers can create custom workflows that automate repetitive tasks, sync data across platforms, and respond dynamically to events in Shopify.
This integration can be used as a custom app on your store, or for automating actions on behalf of merchants through your Shopify app.
Looking for integrating into the Shopify Partner API for your apps, themes or referrals? Check out our Shopify Partner API integration.
import { axios } from "@pipedream/platform"
export default defineComponent({
props: {
shopify_developer_app: {
type: "app",
app: "shopify_developer_app",
}
},
async run({steps, $}) {
const data = {
"query": `{
shop {
id
name
email
}
}`,
}
return await axios($, {
method: "post",
url: `https://${this.shopify_developer_app.$auth.shop_id}.myshopify.com/admin/api/2024-04/graphql.json`,
headers: {
"X-Shopify-Access-Token": `${this.shopify_developer_app.$auth.access_token}`,
"Content-Type": `application/json`,
},
data,
})
},
})