Integrate Autheona using Go

Server-side Go integration guide for Autheona Trust Verification API with copy-paste ready code using standard library.

Prerequisites

Before using this code, you need:

  1. An Autheona account: Sign up at https://app.autheona.com/sign-up
  2. A project (Sandbox or Production): See project creation guide
  3. An access token with API permissions: See access token documentation

Store your access token securely using environment variables. Never hardcode tokens in your source code.

Code

This function sends an HTTP POST request to the Autheona API with the email address to validate. It accepts an optional customPolicy parameter for testing validation rules. The function returns the API response as a map containing the validation result and email intelligence data.

package autheona

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
	"strings"
)

func ValidateEmail(email string, apiKey string, customPolicy map[string]interface{}) (map[string]interface{}, error) {
	normalizedEmail := strings.ToLower(strings.TrimSpace(email))

	payload := map[string]interface{}{
		"email_address": normalizedEmail,
	}
	if customPolicy != nil {
		payload["custom_policy"] = customPolicy
	}

	jsonBody, err := json.Marshal(payload)
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest("POST", "https://api.autheona.com/v1/intelligence", bytes.NewBuffer(jsonBody))
	if err != nil {
		return nil, err
	}

	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("x-api-key", apiKey)

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("HTTP %d", resp.StatusCode)
	}

	var result map[string]interface{}
	if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
		return nil, err
	}

	return result, nil
}

Usage

Import the package, provide your API key via environment variable, and call ValidateEmail with an email address. The function returns a map with action field ('allow', 'block', or 'ignore') and detailed email analysis. For testing specific rules, pass a custom policy as the third argument.

package main

import (
	"fmt"
	"log"
	"os"

	"your-module/autheona"
)

func main() {
	apiKey := os.Getenv("AUTHEONA_API_KEY")

	// Basic validation
	result, err := autheona.ValidateEmail("user@example.com", apiKey, nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Action: %s\n", result["action"])

	// With custom policy for testing
	customPolicy := map[string]interface{}{
		"parent_rules": []map[string]interface{}{
			{
				"action": "block",
				"field":  "domain_disposable",
				"operator": "==",
				"target": map[string]bool{"bool": true},
			},
		},
		"stop_on_block": true,
		"version":       "1.0",
	}

	testResult, err := autheona.ValidateEmail("user@tempmail.com", apiKey, customPolicy)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Action: %s\n", testResult["action"])
}

Custom Policy Parameter

Warning

The custom_policy parameter is for testing only. In production, configure policies using the Policy Editor instead of sending them in requests.

Add custom_policy to your request body to test custom validation rules:

customPolicy := map[string]interface{}{
	"parent_rules": []map[string]interface{}{
		{"action": "block", "field": "domain_disposable", "operator": "==", "target": map[string]bool{"bool": true}},
		{"action": "block", "field": "email_deliverable", "operator": "==", "target": map[string]bool{"bool": false}},
		{"action": "ignore", "field": "domain_free", "operator": "==", "target": map[string]bool{"bool": true}},
	},
	"stop_on_block": true,
	"version":       "1.0",
}

Available fields: domain_disposable, domain_free, email_deliverable, domain_has_website, email_has_fraud_pattern, and more from the API response.

Environment Variables

Set your API key as an environment variable to keep it out of your code:

export AUTHEONA_API_KEY="your-api-key"

Note

This is a minimal integration example. For production use cases, error handling, retry logic, rate limiting, and advanced response processing, refer to the API Reference Documentation.

Support

For issues with the API, refer to: