Configuration
Create one client when your application starts and reuse it. It keeps connections open between requests.
| Option | Node.js | Python | Go | Default |
|---|---|---|---|---|
| API key | apiKey | first argument | first argument | required |
| Signing secret | signingSecret | signing_secret | WithSigningSecret | none |
| Base URL | baseUrl | base_url | WithBaseURL | https://api.msgine.net/api/v1 |
| Timeout per attempt | timeout (ms) | timeout (s) | WithTimeout | 30 seconds |
| Retries | maxRetries | max_retries | WithMaxRetries | 2 |
| HTTP client | fetch | http_client | WithHTTPClient | built in |
const msgine = new MsGine({
apiKey: process.env.MSGINE_API_KEY!,
signingSecret: process.env.MSGINE_SIGNING_SECRET,
timeout: 10_000,
maxRetries: 3,
});msgine = MsGine(
os.environ["MSGINE_API_KEY"],
signing_secret=os.environ.get("MSGINE_SIGNING_SECRET"),
timeout=10.0,
max_retries=3,
)client, err := msgine.New(
os.Getenv("MSGINE_API_KEY"),
msgine.WithSigningSecret(os.Getenv("MSGINE_SIGNING_SECRET")),
msgine.WithTimeout(10*time.Second),
msgine.WithMaxRetries(3),
)Python: sync and async
MsGine is synchronous. AsyncMsGine has the same methods and returns coroutines. Close either one when you are done, or use it as a context manager.
from msgine import AsyncMsGine
async with AsyncMsGine(os.environ["MSGINE_API_KEY"]) as msgine:
await msgine.sms.send(to="+256701234567", message="Hello")Go: contexts
Every Go method takes a context.Context first. Cancelling it stops the request, including any wait between retries.
Sandbox keys
Keys created in the sandbox environment go through the same validation, scopes and rate limits as production keys and are recorded in your history, but nothing is delivered and nothing is charged. The send responses carry sandbox: true. Use sandbox keys in development, tests and CI.
Scopes
Each key carries scopes. A call outside the key's scopes fails with status 403 and code forbidden.
| Scope | Allows |
|---|---|
SEND_SMS, SEND_WHATSAPP, SEND_EMAIL, SEND_PUSH | Sending on that channel and reading its history |
READ_MESSAGES | Histories, message lookup, analytics |
MANAGE_WEBHOOKS | Webhooks |
READ_CONTACTS, MANAGE_CONTACTS | Opt-outs and contact fields |
MANAGE_WORKFLOWS, RUN_WORKFLOWS | Building workflows; starting runs, launches and events |
FULL_ACCESS | Everything |
Request signing
For extra protection, turn on signing when you create the key. MsGine then shows a signing secret once and refuses any request with that key that is not signed with it.
Pass the secret to the client and the SDK signs every request: it sends x-timestamp (Unix seconds) and x-signature, a hex HMAC-SHA256 over the method, the path with its query string, the timestamp and the SHA-256 of the body. MsGine refuses signatures more than two minutes old and any signature it has already seen, so a captured request cannot be replayed.