-
Notifications
You must be signed in to change notification settings - Fork 7
Add canonical examples for the marketing SDK pages #509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jonesy464
wants to merge
3
commits into
main
Choose a base branch
from
rj/3646-canonical-examples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| // Create an Etch e-sign packet via the Anvil API and send it to a signer. | ||
| // Docs: https://www.useanvil.com/docs/api/e-signatures | ||
| // | ||
| // Run it from a project with @anvilco/anvil installed: | ||
| // ANVIL_API_KEY=yourKey node create-etch-packet.js your.real.email@example.com | ||
| // | ||
| // A signature request email is sent to the address you pass, so use your real | ||
| // email address. The new packet also appears in your dashboard's e-sign area. | ||
|
|
||
| import Anvil from '@anvilco/anvil' | ||
|
|
||
| // Your API key from your Anvil organization settings | ||
| const apiKey = process.env.ANVIL_API_KEY ?? '' | ||
|
|
||
| // A sample PDF template available to any account. See | ||
| // https://www.useanvil.com/help/tutorials/set-up-a-pdf-template to set up your own | ||
| const pdfTemplateID = '05xXsZko33JIO6aq5Pnr' | ||
|
|
||
| const signerName = 'Testy Signer' | ||
| const signerEmail = process.argv[2] ?? '' | ||
|
|
||
| if (!signerEmail) { | ||
| console.log('Enter your email address as the script\'s 1st argument') | ||
| process.exit(1) | ||
| } | ||
|
|
||
| async function createEtchPacket () { | ||
| const anvilClient = new Anvil({ apiKey }) | ||
|
|
||
| const { statusCode, data, errors } = await anvilClient.createEtchPacket({ | ||
| variables: { | ||
| // The packet is ready to send: an email goes to the first signer. | ||
| // Use isDraft: true to review it in the dashboard first | ||
| isDraft: false, | ||
|
|
||
| // Test packets use development signatures and do not count toward | ||
| // your billed packets | ||
| isTest: true, | ||
|
|
||
| // Set to true for interactive signing, where signers fill fields as they | ||
| // sign. Over the API that needs the Product pack or Enterprise plan | ||
| allowUpdates: false, | ||
|
|
||
| name: `Test Docs - ${signerName}`, | ||
| signatureEmailSubject: 'Custom email subject', | ||
| signatureEmailBody: 'Custom please sign these documents....', | ||
|
|
||
| files: [ | ||
| { | ||
| // Your own ID for referencing this file in `data` and `signers` below | ||
| id: 'sampleTemplate', | ||
| castEid: pdfTemplateID, | ||
| }, | ||
| ], | ||
|
|
||
| data: { | ||
| // This data fills the PDF before it is sent to any signers. IDs here | ||
| // match the fields configured on the PDF template | ||
| payloads: { | ||
| sampleTemplate: { | ||
| data: { | ||
| name: signerName, | ||
| email: signerEmail, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| signers: [ | ||
| // Signers sign in the order they are specified in this array | ||
| { | ||
| id: 'signer1', | ||
| name: signerName, | ||
| email: signerEmail, | ||
| signerType: 'email', | ||
|
|
||
| // The fields this signer clicks through, in this order | ||
| fields: [ | ||
| { | ||
| fileId: 'sampleTemplate', | ||
| fieldId: 'signature', | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
|
|
||
| if (errors) { | ||
| // GraphQL can return a 200 status code even when there are errors | ||
| console.log('There were errors:', statusCode, JSON.stringify(errors, null, 2)) | ||
| } else { | ||
| const packetDetails = data?.data?.createEtchPacket | ||
| console.log('Visit the new packet on your dashboard:', packetDetails?.detailsURL) | ||
| } | ||
| } | ||
|
|
||
| createEtchPacket().catch((error) => { | ||
| console.error(error) | ||
| process.exit(1) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| // Create an Etch e-sign packet via the Anvil API and send it to a signer. | ||
| // Docs: https://www.useanvil.com/docs/api/e-signatures | ||
| // | ||
| // Run it from a project with @anvilco/anvil installed: | ||
| // ANVIL_API_KEY=yourKey npx tsx create-etch-packet.ts your.real.email@example.com | ||
| // | ||
| // A signature request email is sent to the address you pass, so use your real | ||
| // email address. The new packet also appears in your dashboard's e-sign area. | ||
|
|
||
| import Anvil, { GraphQLResponse } from '@anvilco/anvil' | ||
|
|
||
| // Your API key from your Anvil organization settings | ||
| const apiKey = process.env.ANVIL_API_KEY ?? '' | ||
|
|
||
| // A sample PDF template available to any account. See | ||
| // https://www.useanvil.com/help/tutorials/set-up-a-pdf-template to set up your own | ||
| const pdfTemplateID = '05xXsZko33JIO6aq5Pnr' | ||
|
|
||
| const signerName = 'Testy Signer' | ||
| const signerEmail = process.argv[2] ?? '' | ||
|
|
||
| if (!signerEmail) { | ||
| console.log('Enter your email address as the script\'s 1st argument') | ||
| process.exit(1) | ||
| } | ||
|
|
||
| async function createEtchPacket () { | ||
| const anvilClient = new Anvil({ apiKey }) | ||
|
|
||
| const { statusCode, data, errors }: GraphQLResponse = await anvilClient.createEtchPacket({ | ||
| variables: { | ||
| // The packet is ready to send: an email goes to the first signer. | ||
| // Use isDraft: true to review it in the dashboard first | ||
| isDraft: false, | ||
|
|
||
| // Test packets use development signatures and do not count toward | ||
| // your billed packets | ||
| isTest: true, | ||
|
|
||
| // Set to true for interactive signing, where signers fill fields as they | ||
| // sign. Over the API that needs the Product pack or Enterprise plan | ||
| allowUpdates: false, | ||
|
|
||
| name: `Test Docs - ${signerName}`, | ||
| signatureEmailSubject: 'Custom email subject', | ||
| signatureEmailBody: 'Custom please sign these documents....', | ||
|
|
||
| files: [ | ||
| { | ||
| // Your own ID for referencing this file in `data` and `signers` below | ||
| id: 'sampleTemplate', | ||
| castEid: pdfTemplateID, | ||
| }, | ||
| ], | ||
|
|
||
| data: { | ||
| // This data fills the PDF before it is sent to any signers. IDs here | ||
| // match the fields configured on the PDF template | ||
| payloads: { | ||
| sampleTemplate: { | ||
| data: { | ||
| name: signerName, | ||
| email: signerEmail, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| signers: [ | ||
| // Signers sign in the order they are specified in this array | ||
| { | ||
| id: 'signer1', | ||
| name: signerName, | ||
| email: signerEmail, | ||
| signerType: 'email', | ||
|
|
||
| // The fields this signer clicks through, in this order | ||
| fields: [ | ||
| { | ||
| fileId: 'sampleTemplate', | ||
| fieldId: 'signature', | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
|
|
||
| if (errors) { | ||
| // GraphQL can return a 200 status code even when there are errors | ||
| console.log('There were errors:', statusCode, JSON.stringify(errors, null, 2)) | ||
| } else { | ||
| const packetDetails = data?.data?.createEtchPacket | ||
| console.log('Visit the new packet on your dashboard:', packetDetails?.detailsURL) | ||
| } | ||
| } | ||
|
|
||
| createEtchPacket().catch((error) => { | ||
| console.error(error) | ||
| process.exit(1) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Fill a PDF template with your data via the Anvil API. | ||
| // Docs: https://www.useanvil.com/docs/api/fill-pdf | ||
| // | ||
| // Run it from a project with @anvilco/anvil installed: | ||
| // ANVIL_API_KEY=yourKey node fill.js | ||
|
|
||
| import fs from 'fs' | ||
| import Anvil from '@anvilco/anvil' | ||
|
|
||
| // Your API key from your Anvil organization settings | ||
| const apiKey = process.env.ANVIL_API_KEY ?? '' | ||
|
|
||
| // A sample PDF template available to any account. See | ||
| // https://www.useanvil.com/help/tutorials/set-up-a-pdf-template to set up your own | ||
| const pdfTemplateID = '05xXsZko33JIO6aq5Pnr' | ||
|
|
||
| async function fillPDF () { | ||
| const anvilClient = new Anvil({ apiKey }) | ||
|
|
||
| const { statusCode, data, errors } = await anvilClient.fillPDF(pdfTemplateID, { | ||
| title: 'My PDF Title', | ||
| fontSize: 10, | ||
| textColor: '#333333', | ||
| // IDs here match the fields configured on the PDF template | ||
| data: { | ||
| shortText: 'Hello World!', | ||
| date: '2024-01-15', | ||
| name: { firstName: 'Robin', mi: 'W', lastName: 'Smith' }, | ||
| email: 'testy@example.com', | ||
| phone: { num: '5554443333', region: 'US', baseRegion: 'US' }, | ||
| usAddress: { | ||
| street1: '123 Main St #234', | ||
| city: 'San Francisco', | ||
| state: 'CA', | ||
| zip: '94106', | ||
| country: 'US', | ||
| }, | ||
| ssn: '456454567', | ||
| ein: '897654321', | ||
| checkbox: true, | ||
| decimalNumber: 12345.67, | ||
| dollar: 123.45, | ||
| integer: 12345, | ||
| percent: 50.3, | ||
| longText: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', | ||
| }, | ||
| }) | ||
|
|
||
| if (statusCode === 200 && data) { | ||
| // `data` is the filled PDF binary; save it with no encoding or the file | ||
| // will be corrupt | ||
| fs.writeFileSync('fill-output.pdf', data, { encoding: null }) | ||
| console.log('Filled PDF saved to fill-output.pdf') | ||
| } else { | ||
| console.log('Error filling PDF:', statusCode, JSON.stringify(errors, null, 2)) | ||
| } | ||
| } | ||
|
|
||
| fillPDF().catch((error) => { | ||
| console.error(error) | ||
| process.exit(1) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Fill a PDF template with your data via the Anvil API. | ||
| // Docs: https://www.useanvil.com/docs/api/fill-pdf | ||
| // | ||
| // Run it from a project with @anvilco/anvil installed: | ||
| // ANVIL_API_KEY=yourKey npx tsx fill.ts | ||
|
|
||
| import fs from 'fs' | ||
| import Anvil from '@anvilco/anvil' | ||
|
|
||
| // Your API key from your Anvil organization settings | ||
| const apiKey = process.env.ANVIL_API_KEY ?? '' | ||
|
|
||
| // A sample PDF template available to any account. See | ||
| // https://www.useanvil.com/help/tutorials/set-up-a-pdf-template to set up your own | ||
| const pdfTemplateID = '05xXsZko33JIO6aq5Pnr' | ||
|
|
||
| async function fillPDF () { | ||
| const anvilClient = new Anvil({ apiKey }) | ||
|
|
||
| const { statusCode, data, errors } = await anvilClient.fillPDF(pdfTemplateID, { | ||
| title: 'My PDF Title', | ||
| fontSize: 10, | ||
| textColor: '#333333', | ||
| // IDs here match the fields configured on the PDF template | ||
| data: { | ||
| shortText: 'Hello World!', | ||
| date: '2024-01-15', | ||
| name: { firstName: 'Robin', mi: 'W', lastName: 'Smith' }, | ||
| email: 'testy@example.com', | ||
| phone: { num: '5554443333', region: 'US', baseRegion: 'US' }, | ||
| usAddress: { | ||
| street1: '123 Main St #234', | ||
| city: 'San Francisco', | ||
| state: 'CA', | ||
| zip: '94106', | ||
| country: 'US', | ||
| }, | ||
| ssn: '456454567', | ||
| ein: '897654321', | ||
| checkbox: true, | ||
| decimalNumber: 12345.67, | ||
| dollar: 123.45, | ||
| integer: 12345, | ||
| percent: 50.3, | ||
| longText: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', | ||
| }, | ||
| }) | ||
|
|
||
| if (statusCode === 200 && data) { | ||
| // `data` is the filled PDF binary; save it with no encoding or the file | ||
| // will be corrupt | ||
| fs.writeFileSync('fill-output.pdf', data, { encoding: null }) | ||
| console.log('Filled PDF saved to fill-output.pdf') | ||
| } else { | ||
| console.log('Error filling PDF:', statusCode, JSON.stringify(errors, null, 2)) | ||
| } | ||
| } | ||
|
|
||
| fillPDF().catch((error) => { | ||
| console.error(error) | ||
| process.exit(1) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Generate a PDF from HTML and CSS via the Anvil API. | ||
| // Docs: https://www.useanvil.com/docs/api/generate-pdf#html--css-to-pdf | ||
| // | ||
| // Run it from a project with @anvilco/anvil installed: | ||
| // ANVIL_API_KEY=yourKey node generate-html.js | ||
|
|
||
| import fs from 'fs' | ||
| import Anvil from '@anvilco/anvil' | ||
|
|
||
| // Your API key from your Anvil organization settings | ||
| const apiKey = process.env.ANVIL_API_KEY ?? '' | ||
|
|
||
| async function generateHTMLPDF () { | ||
| const anvilClient = new Anvil({ apiKey }) | ||
|
|
||
| const { statusCode, data, errors } = await anvilClient.generatePDF({ | ||
| title: 'Example HTML to PDF', | ||
| type: 'html', | ||
| data: { | ||
| html: ` | ||
| <h1 class='header-one'>What is Lorem Ipsum?</h1> | ||
| <p> | ||
| Lorem Ipsum is simply dummy text of the printing and typesetting | ||
| industry. Lorem Ipsum has been the industry's standard dummy text | ||
| ever since the <strong>1500s</strong>, when an unknown printer took | ||
| a galley of type and scrambled it to make a type specimen book. | ||
| </p> | ||
| <h3 class='header-two'>Where does it come from?</h3> | ||
| <p> | ||
| Contrary to popular belief, Lorem Ipsum is not simply random text. | ||
| It has roots in a piece of classical Latin literature from | ||
| <i>45 BC</i>, making it over <strong>2000</strong> years old. | ||
| </p> | ||
| `, | ||
| css: ` | ||
| body { font-size: 14px; color: #171717; } | ||
| .header-one { text-decoration: underline; } | ||
| .header-two { font-style: italic; } | ||
| `, | ||
| }, | ||
| }) | ||
|
|
||
| if (statusCode === 200 && data) { | ||
| // `data` is the generated PDF binary; save it with no encoding or the file | ||
| // will be corrupt | ||
| fs.writeFileSync('generate-html-output.pdf', data, { encoding: null }) | ||
| console.log('Generated PDF saved to generate-html-output.pdf') | ||
| } else { | ||
| console.log('Error generating PDF:', statusCode, JSON.stringify(errors, null, 2)) | ||
| } | ||
| } | ||
|
|
||
| generateHTMLPDF().catch((error) => { | ||
| console.error(error) | ||
| process.exit(1) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add
allowUpdates: falsein here? it powers interactive signing, which a lot people want/will need. the comment can be about how you need it set to true to use interactive signing, and interactive signing is a product pack featureThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to both the
.jsand.tsexamples:Used "Product pack or Enterprise" since that's what the e-sign doc says for API access.
One catch: the Python and C# examples can't have this field.
allowUpdatesisn't onCreateEtchPacketPayloadin python-anvil orPayloads/Request/CreateEtchPacket.csin dotnet-anvil. node-anvil works because it passesvariablesstraight through.Those two SDKs are missing a lot more than this one.
createEtchPackettakes 25 args, python-anvil is missing 9 and dotnet-anvil 12:allowUpdates,requireSignatures,finishPageOptions,excludeCertificateFromSignerDownloads,signatureRecipients,signatureProvider,advancedCreate,detectBoxesAdvanced,organizationEidenableEmails,createCastTemplatesFromUploads,duplicateCastsShould I create an issue to update them?