idempotency (#282)
This commit is contained in:
@@ -48,6 +48,37 @@ usesend.emails.send({
|
||||
html: "<p>useSend is the best open source product to send emails</p>",
|
||||
text: "useSend is the best open source product to send emails",
|
||||
});
|
||||
|
||||
// Safely retry sends with an idempotency key
|
||||
await usesend.emails.send(
|
||||
{
|
||||
to: "hello@acme.com",
|
||||
from: "hello@company.com",
|
||||
subject: "useSend email",
|
||||
html: "<p>useSend is the best open source product to send emails</p>",
|
||||
},
|
||||
{ idempotencyKey: "signup-123" },
|
||||
);
|
||||
|
||||
// Works for bulk sends too
|
||||
await usesend.emails.batch(
|
||||
[
|
||||
{
|
||||
to: "a@example.com",
|
||||
from: "hello@company.com",
|
||||
subject: "Welcome",
|
||||
html: "<p>Hello A</p>",
|
||||
},
|
||||
{
|
||||
to: "b@example.com",
|
||||
from: "hello@company.com",
|
||||
subject: "Welcome",
|
||||
html: "<p>Hello B</p>",
|
||||
},
|
||||
],
|
||||
{ idempotencyKey: "bulk-welcome-1" },
|
||||
);
|
||||
// Reusing the same key with a different payload returns HTTP 409.
|
||||
```
|
||||
|
||||
## Campaigns
|
||||
|
||||
Reference in New Issue
Block a user