Installation
Every client needs the same two things: the package, and an API key in the configuration. The snippets below each install, configure and send one email.
Get a key first, from Creating keys. All of these read
it from LOCKALLY_API_KEY.
TypeScript, JavaScript and Node
npm install lockally
import { Configuration, SendApi } from 'lockally';
const api = new SendApi(
new Configuration({ accessToken: process.env.LOCKALLY_API_KEY }),
);
const data = await api.sendEmail({
idempotencyKey: 'welcome-user-42',
sendEmailRequest: {
from: 'hello@yourcompany.com',
to: ['customer@example.com'],
subject: 'Welcome aboard',
text: 'Thanks for signing up.',
},
});
One package covers all three. It ships CommonJS and ESM builds and its own
type declarations, so there is no @types package to add.
Python
pip install lockally
import os, lockally
configuration = lockally.Configuration(
access_token=os.environ["LOCKALLY_API_KEY"],
)
with lockally.ApiClient(configuration) as api_client:
api = lockally.SendApi(api_client)
data = api.send_email(
idempotency_key="welcome-user-42",
send_email_request=lockally.SendEmailRequest(
var_from="hello@yourcompany.com",
to=["customer@example.com"],
subject="Welcome aboard",
text="Thanks for signing up.",
),
)
Go
go get github.com/lockallyinc/lockally-go
cfg := lockally.NewConfiguration()
client := lockally.NewAPIClient(cfg)
ctx := context.WithValue(context.Background(),
lockally.ContextAccessToken, os.Getenv("LOCKALLY_API_KEY"))
body := *lockally.NewSendEmailRequest(
"hello@yourcompany.com",
[]string{"customer@example.com"},
)
resp, _, err := client.SendAPI.SendEmail(ctx).
IdempotencyKey("welcome-user-42").
SendEmailRequest(body).
Execute()
The key goes on the context, not the configuration, which is the Go generator’s convention and differs from every other client here.
Ruby
gem install lockally
require 'lockally'
Lockally.configure do |config|
config.access_token = ENV['LOCKALLY_API_KEY']
end
api = Lockally::SendApi.new
result = api.send_email(
'welcome-user-42',
Lockally::SendEmailRequest.new(
from: 'hello@yourcompany.com',
to: ['customer@example.com'],
subject: 'Welcome aboard',
text: 'Thanks for signing up.',
),
)
PHP
composer require lockally/sdk
$config = Lockally\SDK\Configuration::getDefaultConfiguration()
->setAccessToken(getenv('LOCKALLY_API_KEY'));
$api = new Lockally\SDK\Api\SendApi(new GuzzleHttp\Client(), $config);
$body = new \Lockally\SDK\Model\SendEmailRequest([
'from' => 'hello@yourcompany.com',
'to' => ['customer@example.com'],
'subject' => 'Welcome aboard',
'text' => 'Thanks for signing up.',
]);
$result = $api->sendEmail('welcome-user-42', $body);
The constructor takes an HTTP client as well as the configuration. Guzzle is pulled in as a dependency.
Java
<dependency>
<groupId>com.lockally</groupId>
<artifactId>lockally-sdk</artifactId>
<version>0.3.3</version>
</dependency>
See the Java snippet for a full example.
C# and .NET
dotnet add package Lockally.SDK
Rust
cargo add lockally
Published and generated from the same spec as the rest. We have not verified a snippet against it, so the shape is the standard generator output rather than something we have run. Treat the generated docs in the crate as the reference.
Android and iOS
implementation("com.lockally:lockally-android:0.3.3")
pod 'Lockally'
These target mobile app development and pair with the mobile auth flow rather than an API key. CocoaPods currently serves 0.3.1, two releases behind.
Flutter
flutter pub add lockally