nextmail.providerImports
Every method in this namespace: its signature, its parameters, what it returns and an example.
Methods
Move from Resend, SendGrid, Postmark, Mailgun or Mailchimp: suppressions, audiences, contacts, templates and webhooks come across with one key, with a checklist for domains and API keys.
nextmail.providerImports.inspect()
Look inside an account at another provider before importing
inspect(apiKey: string, options?: ProviderImportInspectOptions): Promise<ProviderInventoryResource>Reads the first page of every resource with a key from Resend, SendGrid, Postmark, Mailgun or Mailchimp and returns a count for each, with more set where a resource runs past its first page. resources lists what this key can bring across: what the provider has no such thing for, or the key may not read, is left out. Nothing is stored, and the key is not kept.
options.provider picks the provider and defaults to resend. Resend needs a full-access key, SendGrid a key with read access, Postmark a Server API token, Mailgun a private API key from either region and Mailchimp an API key with its datacenter suffix. A key that can read nothing but sending is 400 restricted_key: create one with more access for the import and revoke it afterwards.
Parameters
apiKeystringRequiredThe key from the other provider: a full-access Resend key
re_…, a SendGrid keySG.…, a Postmark Server API token, a Mailgun private API key or a Mailchimp key ending in its datacenter, such as-us6.options.providerProviderImportProviderOne of
resend,sendgrid,postmark,mailgunandmailchimp. Defaults toresend.options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client API key for this call only.
Returns
ProviderInventoryResource with resources and counts per resource.
Example
const inventory = await nextmail.providerImports.inspect(process.env.SENDGRID_API_KEY!, { provider: 'sendgrid' }) console.log(inventory.resources, inventory.counts.contacts)Notes
A key restricted to addresses or domains is refused, since audiences, suppressions and templates belong to the whole workspace.
Postmark keeps domains and sender signatures behind an Account token, which the import does not take, so they are not in
resources. Mailchimp has no webhooks for sending events and does not list API keys.
Also available in
nextmail.providerImports.create()
Import from another provider
create(body: ProviderImportCreate, options?: RequestScope): Promise<ProviderImportResource>Queues an import from Resend, SendGrid, Postmark, Mailgun or Mailchimp. Suppressions keep their reason, segments and lists become audiences, subscribed contacts arrive with their names, templates arrive as HTML templates with their variables declared, and webhooks are registered switched off because deliveries here are signed differently. A contact who unsubscribed at the provider is not imported and is recorded as unsubscribed, so suppressions.listUnsubscribes lists them. Domains and API keys come back as a checklist in the report, since a signing key or a token cannot leave the provider that made it. Resources the provider has no such thing for, or the key cannot read, are left out, and resources on the import says what it brings.
The key is held encrypted only while the import runs and is erased when it ends, fails or is cancelled. Running it twice duplicates nothing.
Parameters
body.apiKeystringRequiredThe key from the other provider, as
inspecttakes it.body.providerProviderImportProviderOne of
resend,sendgrid,postmark,mailgunandmailchimp. Defaults toresend.body.resourcesArray<ProviderImportResourceKind>RequiredAny of
suppressions,audiences,contacts,templates,webhooks,domainsandapi-keys.options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client API key for this call only.
Returns
ProviderImportResource with status: queued.
Example
const job = await nextmail.providerImports.create({ apiKey: process.env.MAILGUN_API_KEY!, provider: 'mailgun', resources: ['suppressions', 'audiences', 'contacts', 'templates', 'webhooks', 'domains', 'api-keys']})Notes
One import runs per workspace at a time; a second is 409
already_running.Contacts who unsubscribed at the provider are left out and counted in
report.contacts.unsubscribed.SendGrid hands out contacts through an export it prepares first, so the contacts step waits for it before anything arrives.
Also available in
nextmail.providerImports.list()
List one page of imports from sending providers
list(options?: ProviderImportListOptions): Promise<Page<ProviderImportResource>>One page of the provider imports in the workspace, newest first, each with its report. Nothing is dropped from the history: follow nextCursor while hasMore is true to reach the first one, or let listAll and iterate do that walk.
Parameters
options.limitnumberRows per page, a whole number from 1 to 100. The server defaults to 25.
options.cursorstringThe
nextCursorfrom the previous page. One that names no provider import in the workspace is a 400invalid_cursor.options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client API key for this call only.
Returns
Page<ProviderImportResource> with items, hasMore and nextCursor.
Example
const page = await nextmail.providerImports.list() console.log(page.items.map((job) => job.status), page.hasMore)Also available in
nextmail.providerImports.listAll()
Collect every provider import into one array
listAll(options?: ProviderImportListOptions): Promise<Array<ProviderImportResource>>Follows nextCursor from page to page and resolves with every provider import in the workspace, newest first, each with its report.
Parameters
options.limitnumberPage size per request, from 1 to 100, defaulting to 25 on the server.
options.cursorstringA provider import id to start after.
options.signalAbortSignalCancels the request in flight and rejects the whole walk.
options.apiKeystringOverrides the client API key for every page of this walk.
Returns
Array<ProviderImportResource> holding every provider import across all pages.
Example
const jobs = await nextmail.providerImports.listAll() console.log(jobs.filter((job) => job.status === 'completed').length)Notes
A failure on any page rejects the whole call.
Also available in
nextmail.providerImports.iterate()
Stream provider imports one at a time
iterate(options?: ProviderImportListOptions): AsyncGenerator<ProviderImportResource, void, undefined>Returns an async generator that yields provider imports individually, newest first, and requests the next page only once the current one is drained. Breaking out of the loop stops the requests.
Parameters
options.limitnumberPage size per request, from 1 to 100, defaulting to 25 on the server.
options.cursorstringA provider import id to start after.
options.signalAbortSignalCancels the request in flight and rejects the whole walk.
options.apiKeystringOverrides the client API key for every page of this walk.
Returns
AsyncGenerator<ProviderImportResource, void, undefined> yielding one provider import per step.
Example
for await (const job of nextmail.providerImports.iterate()) { if (job.status === 'running') console.log(job.id)}Notes
The generator is lazy, so an abandoned loop costs only the pages you consumed.
Also available in
nextmail.providerImports.get()
Read one import from a sending provider
get(id: string, options?: RequestScope): Promise<ProviderImportResource>Status, the step it is on and the report so far. Poll it while status is queued or running.
Parameters
idstringRequiredProvider import id,
pimp_followed by 24 hex characters.options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client API key for this call only.
Returns
ProviderImportResource.
Example
const job = await nextmail.providerImports.get('pimp_3f9c2a7b1e4d8f60a5c7b92d') console.log(job.status, job.report.contacts.added)Also available in
nextmail.providerImports.cancel()
Cancel an import from a sending provider
cancel(id: string, options?: RequestScope): Promise<ProviderImportResource>Stops the import and erases the provider key. What already came across stays.
Parameters
idstringRequiredProvider import id,
pimp_followed by 24 hex characters.options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client API key for this call only.
Returns
ProviderImportResource with status: cancelled.
Example
await nextmail.providerImports.cancel('pimp_3f9c2a7b1e4d8f60a5c7b92d')