A Go SDK for interacting with Loops's API.
go get github.com/tilebox/loops-go
Below are a few examples of how to use the SDK to send API requests. For some full, working examples, see the examples directory.
Create a client:
package main
import (
"context"
"github.com/tilebox/loops-go"
"log/slog"
)
func main() {
ctx := context.Background()
client, err := loops.NewClient(loops.WithAPIKey("YOUR_LOOPS_API_KEY"))
if err != nil {
slog.Error("failed to create client", slog.Any("error", err.Error()))
return
}
// now use the client to make requests
}
Find a contact
contact, err := client.FindContact(ctx, &loops.ContactIdentifier{
Email: loops.String("neil.armstrong@moon.space"),
})
if err != nil {
slog.Error("failed to find contact", slog.Any("error", err.Error()))
return
}
Create a contact
contactID, err := client.CreateContact(ctx, &loops.Contact{
Email: "neil.armstrong@moon.space",
FirstName: loops.String("Neil"),
LastName: loops.String("Armstrong"),
UserGroup: loops.String("Astronauts"),
Subscribed: true,
// custom user defined properties for contacts
CustomProperties: map[string]interface{}{
"role": "Astronaut",
},
})
if err != nil {
slog.Error("failed to create contact", slog.Any("error", err.Error()))
return
}
Delete a contact
err = client.DeleteContact(ctx, &loops.ContactIdentifier{
Email: loops.String("neil.armstrong@moon.space"),
})
if err != nil {
slog.Error("failed to delete contact", slog.Any("error", err.Error()))
return
}
Send an event
err = client.SendEvent(ctx, &loops.Event{
Email: loops.String("neil.armstrong@moon.space"),
EventName: "joinedMission",
EventProperties: &map[string]interface{}{
"mission": "Apollo 11",
},
})
if err != nil {
slog.Error("failed to send event", slog.Any("error", err.Error()))
return
}
Send a transactional email
err = client.SendTransactionalEmail(ctx, &loops.TransactionalEmail{
TransactionalId: "cm...",
Email: "recipient@example.com",
DataVariables: &map[string]interface{}{
"name": "Recipient Name",
},
})
if err != nil {
slog.Error("failed to send transactional email", slog.Any("error", err.Error()))
return
}
The API documentation is part of the official Loops Documentation and can be found here.
Contributions are welcome! Especially if the loops API is updated, please feel free to open PRs for new or updated endpoints.
Created by Tilebox - The Solar System’s #1 developer tool for space data management.
This project is licensed under the MIT License - see the LICENSE file for details.
go test ./...
golangci-lint run --fix ./...