Add dcoumentation for API (#18)
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
---
|
||||
title: Introduction
|
||||
description: "Fundamental concepts of Usend's API."
|
||||
---
|
||||
|
||||
## Base URL
|
||||
|
||||
Unsend's API is built on REST principles and is served over HTTPS. To ensure data privacy, unencrypted HTTP is not supported.
|
||||
|
||||
The Base URL for all API endpoints is:
|
||||
|
||||
```sh Terminal
|
||||
https://app.unsend.dev/api/
|
||||
```
|
||||
|
||||
## Authentication
|
||||
|
||||
Authentication to Usend's API is performed via the Authorization header with a Bearer token. To authenticate, you need to include the Authorization header with the word Bearer followed by your token in your API requests like so:
|
||||
|
||||
```sh Terminal
|
||||
Authorization: Bearer us_12345
|
||||
```
|
||||
|
||||
You can create a new token/API key under your Unsend [Developer Settings](https://app.unsend.dev/api-keys).
|
||||
|
@@ -106,6 +106,18 @@
|
||||
},
|
||||
"/v1/emails/{emailId}": {
|
||||
"get": {
|
||||
"parameters": [
|
||||
{
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"minLength": 3,
|
||||
"example": "1212121"
|
||||
},
|
||||
"required": true,
|
||||
"name": "emailId",
|
||||
"in": "path"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Retrieve the user",
|
||||
|
35
apps/docs/get-started/nodejs.mdx
Normal file
35
apps/docs/get-started/nodejs.mdx
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
title: NodeJS
|
||||
description: "Send your mail using unsend in NodeJS"
|
||||
---
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- [Unsend API key](https://app.unsend.dev/api-keys)
|
||||
- [Verified domain](https://app.unsend.dev/domains)
|
||||
|
||||
## Code
|
||||
|
||||
```js server.ts
|
||||
const options = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: "Bearer us_12345",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: {
|
||||
to: "jsmith@example.com",
|
||||
from: "jsmith@example.com",
|
||||
subject: "<string>",
|
||||
replyTo: "<string>",
|
||||
text: "<string>",
|
||||
html: "<string>",
|
||||
attachments: [{ filename: "<string>", content: "<string>" }],
|
||||
},
|
||||
};
|
||||
|
||||
fetch("https://app.unsend.dev/api/v1/emails", options)
|
||||
.then((response) => response.json())
|
||||
.then((response) => console.log(response))
|
||||
.catch((err) => console.error(err));
|
||||
```
|
@@ -30,4 +30,11 @@ Quicklinks to set up your account and get started
|
||||
>
|
||||
Learn how to use our API to send emails programmatically.
|
||||
</Card>
|
||||
<Card
|
||||
title="NodeJS"
|
||||
icon="node-js"
|
||||
href="/get-started/nodejs"
|
||||
>
|
||||
Learn how to use our API to send emails programmatically.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
@@ -47,11 +47,12 @@
|
||||
{
|
||||
"group": "Get Started",
|
||||
"pages": [
|
||||
"introduction"
|
||||
"introduction",
|
||||
"get-started/nodejs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "API Documentation",
|
||||
"group": "API Reference",
|
||||
"pages": [
|
||||
"api-reference/introduction"
|
||||
]
|
||||
@@ -76,7 +77,7 @@
|
||||
"method": "bearer"
|
||||
},
|
||||
"playground": {
|
||||
"mode": "simple"
|
||||
"mode": "show"
|
||||
}
|
||||
},
|
||||
"footerSocials": {
|
||||
|
@@ -7,14 +7,10 @@ const ErrorCode = z.enum([
|
||||
"BAD_REQUEST",
|
||||
"FORBIDDEN",
|
||||
"INTERNAL_SERVER_ERROR",
|
||||
"USAGE_EXCEEDED",
|
||||
"DISABLED",
|
||||
"NOT_FOUND",
|
||||
"NOT_UNIQUE",
|
||||
"RATE_LIMITED",
|
||||
"UNAUTHORIZED",
|
||||
"PRECONDITION_FAILED",
|
||||
"INSUFFICIENT_PERMISSIONS",
|
||||
"METHOD_NOT_ALLOWED",
|
||||
]);
|
||||
|
||||
@@ -25,9 +21,6 @@ function codeToStatus(code: z.infer<typeof ErrorCode>): StatusCode {
|
||||
case "UNAUTHORIZED":
|
||||
return 401;
|
||||
case "FORBIDDEN":
|
||||
case "DISABLED":
|
||||
case "INSUFFICIENT_PERMISSIONS":
|
||||
case "USAGE_EXCEEDED":
|
||||
return 403;
|
||||
case "NOT_FOUND":
|
||||
return 404;
|
||||
@@ -35,8 +28,6 @@ function codeToStatus(code: z.infer<typeof ErrorCode>): StatusCode {
|
||||
return 405;
|
||||
case "NOT_UNIQUE":
|
||||
return 409;
|
||||
case "PRECONDITION_FAILED":
|
||||
return 412;
|
||||
case "RATE_LIMITED":
|
||||
return 429;
|
||||
case "INTERNAL_SERVER_ERROR":
|
||||
@@ -52,12 +43,14 @@ function statusToCode(status: StatusCode): z.infer<typeof ErrorCode> {
|
||||
return "UNAUTHORIZED";
|
||||
case 403:
|
||||
return "FORBIDDEN";
|
||||
|
||||
case 404:
|
||||
return "NOT_FOUND";
|
||||
|
||||
case 405:
|
||||
return "METHOD_NOT_ALLOWED";
|
||||
case 409:
|
||||
return "NOT_UNIQUE";
|
||||
case 429:
|
||||
return "RATE_LIMITED";
|
||||
case 500:
|
||||
return "INTERNAL_SERVER_ERROR";
|
||||
default:
|
||||
|
@@ -9,6 +9,20 @@ import { UnsendApiError } from "../../api-error";
|
||||
const route = createRoute({
|
||||
method: "get",
|
||||
path: "/v1/emails/{emailId}",
|
||||
request: {
|
||||
params: z.object({
|
||||
emailId: z
|
||||
.string()
|
||||
.min(3)
|
||||
.openapi({
|
||||
param: {
|
||||
name: "emailId",
|
||||
in: "path",
|
||||
},
|
||||
example: "cuiwqdj74rygf74",
|
||||
}),
|
||||
}),
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
|
Reference in New Issue
Block a user