Authentication

Authenticate with Basic Auth or OAuth 2.0 tokens.

Every request to https://a.eztexting.com must carry an Authorization header. There are two ways to fill it:

HTTP Basic AuthOAuth 2.0 bearer token
HeaderAuthorization: Basic <base64(username:password)>Authorization: Bearer <accessToken>
SetupNoneOne call to POST /v1/tokens/create
LifetimeUntil you change your passwordAccess token: 90 minutes (5400 s). Refresh token: 60 days.
Best forGetting started, scripts, the API reference's Try It, and many production integrationsProduction apps that want the extra credential protection below
WhyZero frictionYour password never leaves your server after the first call, tokens can be revoked without a password change, and a leaked token expires on its own

Both work on every endpoint. Basic is fine to start with, and you may want to switch to tokens before you ship.


HTTP Basic Auth

Your username and password are the same ones you use to log in to the EZ Texting web app. Most HTTP clients build the header for you from a username/password pair:

curl https://a.eztexting.com/v1/credits \
  -u "$EZTEXTING_USERNAME:$EZTEXTING_PASSWORD"
import os, requests

auth = (os.environ["EZTEXTING_USERNAME"], os.environ["EZTEXTING_PASSWORD"])
requests.get("https://a.eztexting.com/v1/credits", auth=auth, timeout=30)
const credentials = Buffer.from(
  `${process.env.EZTEXTING_USERNAME}:${process.env.EZTEXTING_PASSWORD}`
).toString("base64");

await fetch("https://a.eztexting.com/v1/credits", {
  headers: { Authorization: `Basic ${credentials}` },
});
<?php
$ch = curl_init("https://a.eztexting.com/v1/credits");
curl_setopt($ch, CURLOPT_USERPWD, getenv("EZTEXTING_USERNAME") . ":" . getenv("EZTEXTING_PASSWORD"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$body = curl_exec($ch);
require "net/http"

uri = URI("https://a.eztexting.com/v1/credits")
req = Net::HTTP::Get.new(uri)
req.basic_auth(ENV.fetch("EZTEXTING_USERNAME"), ENV.fetch("EZTEXTING_PASSWORD"))
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
String basicAuth = Base64.getEncoder().encodeToString(
    (System.getenv("EZTEXTING_USERNAME") + ":" + System.getenv("EZTEXTING_PASSWORD")).getBytes());

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://a.eztexting.com/v1/credits"))
    .header("Authorization", "Basic " + basicAuth)
    .GET().build();
var credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(
    $"{Environment.GetEnvironmentVariable("EZTEXTING_USERNAME")}:{Environment.GetEnvironmentVariable("EZTEXTING_PASSWORD")}"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials);
var res = await client.GetAsync("https://a.eztexting.com/v1/credits");
req, _ := http.NewRequest("GET", "https://a.eztexting.com/v1/credits", nil)
req.SetBasicAuth(os.Getenv("EZTEXTING_USERNAME"), os.Getenv("EZTEXTING_PASSWORD"))
resp, err := http.DefaultClient.Do(req)

If you build the header by hand, base64-encode username:password with no trailing newline (echo -n, not echo) and send it as Basic <encoded>.


OAuth 2.0 bearer tokens

1. Create a token pair

Exchange your username and password (as appKey / appSecret) for an access token and a refresh token:

curl -X POST https://a.eztexting.com/v1/tokens/create \
  -H "Content-Type: application/json" \
  -d '{
    "appKey": "'"$EZTEXTING_USERNAME"'",
    "appSecret": "'"$EZTEXTING_PASSWORD"'"
  }'
tokens = requests.post(
    "https://a.eztexting.com/v1/tokens/create",
    json={"appKey": os.environ["EZTEXTING_USERNAME"], "appSecret": os.environ["EZTEXTING_PASSWORD"]},
    timeout=30,
).json()
const tokens = await (await fetch("https://a.eztexting.com/v1/tokens/create", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    appKey: process.env.EZTEXTING_USERNAME,
    appSecret: process.env.EZTEXTING_PASSWORD,
  }),
})).json();
<?php
$ch = curl_init("https://a.eztexting.com/v1/tokens/create");
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
    CURLOPT_POSTFIELDS => json_encode([
        "appKey" => getenv("EZTEXTING_USERNAME"),
        "appSecret" => getenv("EZTEXTING_PASSWORD"),
    ]),
]);
$tokens = json_decode(curl_exec($ch), true);
curl_close($ch);
require "net/http"
require "json"

uri = URI("https://a.eztexting.com/v1/tokens/create")
req = Net::HTTP::Post.new(uri, "Content-Type" => "application/json")
req.body = { appKey: ENV.fetch("EZTEXTING_USERNAME"), appSecret: ENV.fetch("EZTEXTING_PASSWORD") }.to_json
tokens = JSON.parse(Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }.body)
String json = mapper.writeValueAsString(Map.of(
    "appKey", System.getenv("EZTEXTING_USERNAME"),
    "appSecret", System.getenv("EZTEXTING_PASSWORD")));
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://a.eztexting.com/v1/tokens/create"))
    .header("Content-Type", "application/json")
    .POST(HttpRequest.BodyPublishers.ofString(json))
    .build();
JsonNode tokens = mapper.readTree(client.send(request, HttpResponse.BodyHandlers.ofString()).body());
using var client = new HttpClient();
var res = await client.PostAsJsonAsync("https://a.eztexting.com/v1/tokens/create", new
{
    appKey = Environment.GetEnvironmentVariable("EZTEXTING_USERNAME"),
    appSecret = Environment.GetEnvironmentVariable("EZTEXTING_PASSWORD")
});
var tokens = await res.Content.ReadFromJsonAsync<JsonElement>();
body, _ := json.Marshal(map[string]string{
	"appKey":    os.Getenv("EZTEXTING_USERNAME"),
	"appSecret": os.Getenv("EZTEXTING_PASSWORD"),
})
resp, err := http.Post("https://a.eztexting.com/v1/tokens/create", "application/json", bytes.NewReader(body))
if err != nil {
	panic(err)
}
defer resp.Body.Close()
var tokens struct {
	AccessToken      string `json:"accessToken"`
	RefreshToken     string `json:"refreshToken"`
	ExpiresInSeconds int    `json:"expiresInSeconds"`
}
json.NewDecoder(resp.Body).Decode(&tokens)
{
  "accessToken": "6b2e8f41-3c9a-4d17-b5e0-9a7c2d4f8e13",
  "refreshToken": "f3c9a1e2-7b44-4d2e-9a0c-2f6c8e1b5d77",
  "expiresInSeconds": 5400
}

Note that this is the only call that needs your password. Store both tokens somewhere safe (a secrets manager, an encrypted column, not a log line).

Reuse your tokens

Create a token pair once, cache it, and use the access token until it's close to expiring. Then call refresh to get a new pair. You only need to call create again if the refresh token has expired or been revoked.

Avoid calling create on every request. Each call sends your password and issues a new 60-day refresh token, and every unused refresh token stays valid until it expires. The session class below handles this for you.

2. Use the access token

curl https://a.eztexting.com/v1/credits \
  -H "Authorization: Bearer $EZTEXTING_ACCESS_TOKEN"
headers = {"Authorization": f"Bearer {tokens['accessToken']}"}
requests.get("https://a.eztexting.com/v1/credits", headers=headers, timeout=30)
await fetch("https://a.eztexting.com/v1/credits", {
  headers: { Authorization: `Bearer ${tokens.accessToken}` },
});
<?php
$ch = curl_init("https://a.eztexting.com/v1/credits");
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer " . $tokens['accessToken']]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$body = curl_exec($ch);
uri = URI("https://a.eztexting.com/v1/credits")
req = Net::HTTP::Get.new(uri, "Authorization" => "Bearer #{tokens['accessToken']}")
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
HttpRequest credits = HttpRequest.newBuilder()
    .uri(URI.create("https://a.eztexting.com/v1/credits"))
    .header("Authorization", "Bearer " + tokens.get("accessToken").asText())
    .GET().build();
client.send(credits, HttpResponse.BodyHandlers.ofString());
client.DefaultRequestHeaders.Authorization =
    new AuthenticationHeaderValue("Bearer", tokens.GetProperty("accessToken").GetString());
var credits = await client.GetAsync("https://a.eztexting.com/v1/credits");
req, _ := http.NewRequest("GET", "https://a.eztexting.com/v1/credits", nil)
req.Header.Set("Authorization", "Bearer "+tokens.AccessToken)
resp, err = http.DefaultClient.Do(req)

3. Refresh before it expires

Access tokens live for 90 minutes. Refresh proactively (say, at 80 minutes) or reactively when a request returns 401. Either way, the refresh returns a new pair: the old refresh token is replaced, so store both again.

curl -X POST https://a.eztexting.com/v1/tokens/refresh \
  -H "Content-Type: application/json" \
  -d '{"refreshToken": "'"$EZTEXTING_REFRESH_TOKEN"'"}'
import os, time, requests

class EzTextingSession:
    def __init__(self):
        self.access = self.refresh = None
        self.expires_at = 0

    def _login(self):
        t = requests.post("https://a.eztexting.com/v1/tokens/create",
                          json={"appKey": os.environ["EZTEXTING_USERNAME"],
                                "appSecret": os.environ["EZTEXTING_PASSWORD"]}, timeout=30).json()
        self._store(t)

    def _refresh(self):
        r = requests.post("https://a.eztexting.com/v1/tokens/refresh",
                          json={"refreshToken": self.refresh}, timeout=30)
        # refresh token expired or revoked
        if r.status_code == 401:
            return self._login()
        self._store(r.json())

    def _store(self, t):
        self.access, self.refresh = t["accessToken"], t["refreshToken"]
        # refresh 5 min early
        self.expires_at = time.time() + t["expiresInSeconds"] - 300

    def request(self, method, path, **kw):
        if not self.access:
            self._login()
        elif time.time() >= self.expires_at:
            self._refresh()
        kw.setdefault("headers", {})["Authorization"] = f"Bearer {self.access}"
        resp = requests.request(method, "https://a.eztexting.com" + path, **kw)
        # token revoked out from under us
        if resp.status_code == 401:
            self._refresh()
            kw["headers"]["Authorization"] = f"Bearer {self.access}"
            resp = requests.request(method, "https://a.eztexting.com" + path, **kw)
        return resp

ez = EzTextingSession()
ez.request("GET", "/v1/credits").json()
class EzTextingSession {
  #access; #refresh; #expiresAt = 0;

  async #login() {
    const t = await (await fetch("https://a.eztexting.com/v1/tokens/create", {
      method: "POST", headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ appKey: process.env.EZTEXTING_USERNAME, appSecret: process.env.EZTEXTING_PASSWORD }),
    })).json();
    this.#store(t);
  }

  async #refreshTokens() {
    const r = await fetch("https://a.eztexting.com/v1/tokens/refresh", {
      method: "POST", headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ refreshToken: this.#refresh }),
    });
    // refresh token expired or revoked
    if (r.status === 401) return this.#login();
    this.#store(await r.json());
  }

  #store(t) {
    this.#access = t.accessToken; this.#refresh = t.refreshToken;
    // refresh 5 min early
    this.#expiresAt = Date.now() + (t.expiresInSeconds - 300) * 1000;
  }

  async request(method, path, body) {
    if (!this.#access) await this.#login();
    else if (Date.now() >= this.#expiresAt) await this.#refreshTokens();

    const call = () => fetch("https://a.eztexting.com" + path, {
      method, headers: { Authorization: `Bearer ${this.#access}`, "Content-Type": "application/json" },
      body: body ? JSON.stringify(body) : undefined,
    });
    let res = await call();
    // revoked out from under us
    if (res.status === 401) { await this.#refreshTokens(); res = await call(); }
    return res;
  }
}

const ez = new EzTextingSession();
console.log(await (await ez.request("GET", "/v1/credits")).json());
<?php
class EzTextingSession {
    private ?string $access = null;
    private ?string $refresh = null;
    private int $expiresAt = 0;

    private function post(string $path, array $payload): array {
        $ch = curl_init("https://a.eztexting.com$path");
        curl_setopt_array($ch, [
            CURLOPT_POST => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
            CURLOPT_POSTFIELDS => json_encode($payload),
        ]);
        $body = curl_exec($ch);
        $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return [$status, json_decode($body, true)];
    }

    private function login(): void {
        [, $t] = $this->post("/v1/tokens/create",
            ["appKey" => getenv("EZTEXTING_USERNAME"), "appSecret" => getenv("EZTEXTING_PASSWORD")]);
        $this->store($t);
    }

    private function refreshTokens(): void {
        [$status, $t] = $this->post("/v1/tokens/refresh", ["refreshToken" => $this->refresh]);
        // refresh token expired or revoked
        if ($status === 401) { $this->login(); return; }
        $this->store($t);
    }

    private function store(array $t): void {
        $this->access = $t['accessToken'];
        $this->refresh = $t['refreshToken'];
        // refresh 5 min early
        $this->expiresAt = time() + $t['expiresInSeconds'] - 300;
    }

    public function request(string $method, string $path, ?array $body = null): array {
        if (!$this->access) $this->login();
        elseif (time() >= $this->expiresAt) $this->refreshTokens();

        $call = function () use ($method, $path, $body) {
            $ch = curl_init("https://a.eztexting.com$path");
            curl_setopt_array($ch, [
                CURLOPT_CUSTOMREQUEST => $method,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_HTTPHEADER => ["Authorization: Bearer {$this->access}", "Content-Type: application/json"],
            ]);
            if ($body !== null) curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
            $resp = curl_exec($ch);
            $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);
            return [$status, json_decode($resp, true)];
        };
        [$status, $data] = $call();
        // revoked out from under us
        if ($status === 401) { $this->refreshTokens(); [$status, $data] = $call(); }
        return [$status, $data];
    }
}

$ez = new EzTextingSession();
[$status, $credits] = $ez->request("GET", "/v1/credits");
require "net/http"
require "json"

class EzTextingSession
  BASE = "https://a.eztexting.com"

  def request(method, path, body = nil)
    if @access.nil? then login
    elsif Time.now.to_i >= @expires_at then refresh_tokens
    end

    res = call(method, path, body)
    # revoked out from under us
    if res.code == "401"
      refresh_tokens
      res = call(method, path, body)
    end
    res
  end

  private

  def call(method, path, body)
    uri = URI(BASE + path)
    req = Net::HTTPGenericRequest.new(method, !body.nil?, true, uri,
                                      "Authorization" => "Bearer #{@access}", "Content-Type" => "application/json")
    req.body = body.to_json if body
    Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
  end

  def post(path, payload)
    uri = URI(BASE + path)
    req = Net::HTTP::Post.new(uri, "Content-Type" => "application/json")
    req.body = payload.to_json
    Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
  end

  def login
    store(JSON.parse(post("/v1/tokens/create",
                          { appKey: ENV.fetch("EZTEXTING_USERNAME"), appSecret: ENV.fetch("EZTEXTING_PASSWORD") }).body))
  end

  def refresh_tokens
    res = post("/v1/tokens/refresh", { refreshToken: @refresh })
    # refresh token expired or revoked
    return login if res.code == "401"
    store(JSON.parse(res.body))
  end

  def store(t)
    @access, @refresh = t["accessToken"], t["refreshToken"]
    # refresh 5 min early
    @expires_at = Time.now.to_i + t["expiresInSeconds"] - 300
  end
end

ez = EzTextingSession.new
puts JSON.parse(ez.request("GET", "/v1/credits").body)
public class EzTextingSession {
    private final HttpClient client = HttpClient.newHttpClient();
    private final ObjectMapper mapper = new ObjectMapper();
    private String access, refresh;
    private Instant expiresAt = Instant.EPOCH;

    public synchronized HttpResponse<String> request(String method, String path, Object body) throws Exception {
        if (access == null) login();
        else if (Instant.now().isAfter(expiresAt)) refreshTokens();

        HttpResponse<String> res = call(method, path, body);
        // revoked out from under us
        if (res.statusCode() == 401) {
            refreshTokens();
            res = call(method, path, body);
        }
        return res;
    }

    private HttpResponse<String> call(String method, String path, Object body) throws Exception {
        HttpRequest.BodyPublisher publisher = body == null
            ? HttpRequest.BodyPublishers.noBody()
            : HttpRequest.BodyPublishers.ofString(mapper.writeValueAsString(body));
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://a.eztexting.com" + path))
            .header("Authorization", "Bearer " + access)
            .header("Content-Type", "application/json")
            .method(method, publisher)
            .build();
        return client.send(request, HttpResponse.BodyHandlers.ofString());
    }

    private HttpResponse<String> post(String path, Map<String, String> payload) throws Exception {
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://a.eztexting.com" + path))
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(mapper.writeValueAsString(payload)))
            .build();
        return client.send(request, HttpResponse.BodyHandlers.ofString());
    }

    private void login() throws Exception {
        store(post("/v1/tokens/create", Map.of(
            "appKey", System.getenv("EZTEXTING_USERNAME"),
            "appSecret", System.getenv("EZTEXTING_PASSWORD"))));
    }

    private void refreshTokens() throws Exception {
        HttpResponse<String> res = post("/v1/tokens/refresh", Map.of("refreshToken", refresh));
        // refresh token expired or revoked
        if (res.statusCode() == 401) { login(); return; }
        store(res);
    }

    private void store(HttpResponse<String> res) throws Exception {
        JsonNode t = mapper.readTree(res.body());
        access = t.get("accessToken").asText();
        refresh = t.get("refreshToken").asText();
        // refresh 5 min early
        expiresAt = Instant.now().plusSeconds(t.get("expiresInSeconds").asLong() - 300);
    }
}

EzTextingSession ez = new EzTextingSession();
System.out.println(ez.request("GET", "/v1/credits", null).body());
var ez = new EzTextingSession();
Console.WriteLine(await (await ez.RequestAsync(HttpMethod.Get, "/v1/credits")).Content.ReadAsStringAsync());

public class EzTextingSession
{
    private readonly HttpClient _http = new() { BaseAddress = new Uri("https://a.eztexting.com") };
    private string? _access, _refresh;
    private DateTimeOffset _expiresAt;

    public async Task<HttpResponseMessage> RequestAsync(HttpMethod method, string path, object? body = null)
    {
        if (_access is null) await LoginAsync();
        else if (DateTimeOffset.UtcNow >= _expiresAt) await RefreshAsync();

        var res = await _http.SendAsync(Build(method, path, body));
        // revoked out from under us
        if (res.StatusCode == HttpStatusCode.Unauthorized)
        {
            await RefreshAsync();
            res = await _http.SendAsync(Build(method, path, body));
        }
        return res;
    }

    private HttpRequestMessage Build(HttpMethod method, string path, object? body)
    {
        var req = new HttpRequestMessage(method, path);
        req.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _access);
        if (body is not null) req.Content = JsonContent.Create(body);
        return req;
    }

    private async Task LoginAsync()
    {
        var res = await _http.PostAsJsonAsync("/v1/tokens/create", new
        {
            appKey = Environment.GetEnvironmentVariable("EZTEXTING_USERNAME"),
            appSecret = Environment.GetEnvironmentVariable("EZTEXTING_PASSWORD")
        });
        await StoreAsync(res);
    }

    private async Task RefreshAsync()
    {
        var res = await _http.PostAsJsonAsync("/v1/tokens/refresh", new { refreshToken = _refresh });
        // refresh token expired or revoked
        if (res.StatusCode == HttpStatusCode.Unauthorized) { await LoginAsync(); return; }
        await StoreAsync(res);
    }

    private async Task StoreAsync(HttpResponseMessage res)
    {
        var t = await res.Content.ReadFromJsonAsync<JsonElement>();
        _access = t.GetProperty("accessToken").GetString();
        _refresh = t.GetProperty("refreshToken").GetString();
        // refresh 5 min early
        _expiresAt = DateTimeOffset.UtcNow.AddSeconds(t.GetProperty("expiresInSeconds").GetInt32() - 300);
    }
}
type EzTextingSession struct {
	mu        sync.Mutex
	access    string
	refresh   string
	expiresAt time.Time
}

type tokenPair struct {
	AccessToken      string `json:"accessToken"`
	RefreshToken     string `json:"refreshToken"`
	ExpiresInSeconds int    `json:"expiresInSeconds"`
}

func (s *EzTextingSession) postTokens(path string, payload map[string]string) (int, error) {
	body, _ := json.Marshal(payload)
	resp, err := http.Post("https://a.eztexting.com"+path, "application/json", bytes.NewReader(body))
	if err != nil {
		return 0, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != 200 {
		return resp.StatusCode, nil
	}
	var t tokenPair
	if err := json.NewDecoder(resp.Body).Decode(&t); err != nil {
		return 0, err
	}
	s.access, s.refresh = t.AccessToken, t.RefreshToken
	// refresh 5 min early
	s.expiresAt = time.Now().Add(time.Duration(t.ExpiresInSeconds-300) * time.Second)
	return 200, nil
}

func (s *EzTextingSession) login() error {
	_, err := s.postTokens("/v1/tokens/create", map[string]string{
		"appKey": os.Getenv("EZTEXTING_USERNAME"), "appSecret": os.Getenv("EZTEXTING_PASSWORD"),
	})
	return err
}

func (s *EzTextingSession) refreshTokens() error {
	status, err := s.postTokens("/v1/tokens/refresh", map[string]string{"refreshToken": s.refresh})
	// refresh token expired or revoked
	if err == nil && status == 401 {
		return s.login()
	}
	return err
}

func (s *EzTextingSession) Request(method, path string, body []byte) (*http.Response, error) {
	s.mu.Lock()
	defer s.mu.Unlock()
	if s.access == "" {
		if err := s.login(); err != nil {
			return nil, err
		}
	} else if time.Now().After(s.expiresAt) {
		if err := s.refreshTokens(); err != nil {
			return nil, err
		}
	}

	call := func() (*http.Response, error) {
		req, _ := http.NewRequest(method, "https://a.eztexting.com"+path, bytes.NewReader(body))
		req.Header.Set("Authorization", "Bearer "+s.access)
		req.Header.Set("Content-Type", "application/json")
		return http.DefaultClient.Do(req)
	}
	resp, err := call()
	// revoked out from under us
	if err == nil && resp.StatusCode == 401 {
		resp.Body.Close()
		if err := s.refreshTokens(); err != nil {
			return nil, err
		}
		resp, err = call()
	}
	return resp, err
}

ez := &EzTextingSession{}
resp, err := ez.Request("GET", "/v1/credits", nil)

In a multi-process deployment, keep the token pair in shared storage (Redis, a database row) and refresh under a lock, or you'll have workers racing to refresh and invalidating each other's refresh tokens.

4. Revoke a token

Revoke when a token may have leaked, when you rotate credentials, or when decommissioning an integration. Revoking a refresh token kills the whole chain.

curl -X POST https://a.eztexting.com/v1/tokens/revoke \
  -H "Content-Type: application/json" \
  -d '{"token": "'"$EZTEXTING_REFRESH_TOKEN"'", "type": "REFRESH_TOKEN"}'
requests.post(
    "https://a.eztexting.com/v1/tokens/revoke",
    json={"token": tokens["refreshToken"], "type": "REFRESH_TOKEN"},
    timeout=30,
).raise_for_status()
await fetch("https://a.eztexting.com/v1/tokens/revoke", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ token: tokens.refreshToken, type: "REFRESH_TOKEN" }),
});
<?php
$ch = curl_init("https://a.eztexting.com/v1/tokens/revoke");
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
    CURLOPT_POSTFIELDS => json_encode(["token" => $tokens['refreshToken'], "type" => "REFRESH_TOKEN"]),
]);
curl_exec($ch);
curl_close($ch);
uri = URI("https://a.eztexting.com/v1/tokens/revoke")
req = Net::HTTP::Post.new(uri, "Content-Type" => "application/json")
req.body = { token: tokens["refreshToken"], type: "REFRESH_TOKEN" }.to_json
# raises unless 2xx
Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }.value
HttpRequest revoke = HttpRequest.newBuilder()
    .uri(URI.create("https://a.eztexting.com/v1/tokens/revoke"))
    .header("Content-Type", "application/json")
    .POST(HttpRequest.BodyPublishers.ofString(
        mapper.writeValueAsString(Map.of("token", tokens.get("refreshToken").asText(), "type", "REFRESH_TOKEN"))))
    .build();
client.send(revoke, HttpResponse.BodyHandlers.ofString());
var res = await client.PostAsJsonAsync("https://a.eztexting.com/v1/tokens/revoke",
    new { token = tokens.GetProperty("refreshToken").GetString(), type = "REFRESH_TOKEN" });
res.EnsureSuccessStatusCode();
body, _ := json.Marshal(map[string]string{"token": tokens.RefreshToken, "type": "REFRESH_TOKEN"})
resp, err := http.Post("https://a.eztexting.com/v1/tokens/revoke", "application/json", bytes.NewReader(body))
if err != nil {
	panic(err)
}
resp.Body.Close()

type is ACCESS_TOKEN or REFRESH_TOKEN. Returns 200 OK.


Which credentials to use

Your API credentials are a user on your EZ Texting account, usually the account holder's own login. If your account has teammates, one option is a separate Admin teammate login just for the API, so a staff change doesn't affect your integration. Teammates may add cost, so this is optional.


Troubleshooting 401

SymptomLikely cause
401 on every request with Basic AuthWrong username or password; trailing newline in the base64; Authorization header missing or malformed.
401 after ~90 minutes with a tokenAccess token expired. Refresh it.
401 from /v1/tokens/refreshRefresh token expired (60 days) or was revoked. Create a new pair with username and password.
401 from /v1/tokens/createWrong appKey / appSecret.
Your code calls /v1/tokens/create regularlyNot an error. The likely cause is that your code isn't storing the token pair and refreshing it. See the tip above.
Works in the API reference, fails in codeThe reference uses Basic Auth with the values you typed. Compare the exact header your code sends.

More in Troubleshooting.


Related

API reference


Did this page help you?