Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## v7.5.0 (2026-02-03)

- Adds the following functions usable by child and referral customer users:
- `ApiKey.Create`
- `ApiKey.Delete`
- `ApiKey.Enable`
- `ApiKey.Disable`

## v7.4.0 (2025-11-24)

- Adds .NET 10 support
Expand Down
65 changes: 46 additions & 19 deletions EasyPost.Tests/ServicesTests/ApiKeyServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,33 @@ public ApiKeyServiceTests() : base("api_key_service", TestUtils.ApiKey.Productio

#region Test CRUD Operations

[Fact]
[CrudOperations.Read]
public async Task TestRetrieveApiKeys()
{
UseVCR("retrieve_api_keys");

User user = await Client.User.RetrieveMe();

List<ApiKey> apiKeys = await Client.ApiKey.RetrieveApiKeysForUser(user.Id);

Assert.IsType<List<ApiKey>>(apiKeys);
}

[Fact]
[CrudOperations.Read]
public async Task TestRetrieveApiKeysChild()
{
UseVCR("retrieve_api_keys_child");

const string fakeChildId = "user_123456789";

// Test suite user has no child users, so this should throw a FilteringError
Exception? possibleException = await Record.ExceptionAsync(async () => await Client.ApiKey.RetrieveApiKeysForUser(fakeChildId));

Assert.IsType<FilteringError>(possibleException);
}

[Fact]
[CrudOperations.Read]
[Testing.Function]
Expand All @@ -43,30 +70,30 @@ public async Task TestAll()
}

[Fact]
[CrudOperations.Read]
public async Task TestRetrieveApiKeys()
[CrudOperations.Create]
[CrudOperations.Update]
[CrudOperations.Delete]
public async Task TestApiKeyLifecycle()
{
UseVCR("retrieve_api_keys");
string? referralApiKey = Environment.GetEnvironmentVariable("REFERRAL_CUSTOMER_PROD_API_KEY");
UseVCR("lifecycle", referralApiKey);

User user = await Client.User.RetrieveMe();
// Create an API key
ApiKey apiKey = await Client.ApiKey.Create("production");
Assert.NotNull(apiKey);
Assert.StartsWith("ak_", apiKey.Id);
Assert.Equal("production", apiKey.Mode);

List<ApiKey> apiKeys = await Client.ApiKey.RetrieveApiKeysForUser(user.Id);
// Disable the API key
apiKey = await Client.ApiKey.Disable(apiKey.Id);
Assert.False(apiKey.Active);

Assert.IsType<List<ApiKey>>(apiKeys);
}
// Enable the API key
apiKey = await Client.ApiKey.Enable(apiKey.Id);
Assert.True(apiKey.Active);

[Fact]
[CrudOperations.Read]
public async Task TestRetrieveApiKeysChild()
{
UseVCR("retrieve_api_keys_child");

const string fakeChildId = "user_123456789";

// Test suite user has no child users, so this should throw a FilteringError
Exception? possibleException = await Record.ExceptionAsync(async () => await Client.ApiKey.RetrieveApiKeysForUser(fakeChildId));

Assert.IsType<FilteringError>(possibleException);
// Delete the API key
await Client.ApiKey.Delete(apiKey.Id);
}

#endregion
Expand Down
184 changes: 184 additions & 0 deletions EasyPost.Tests/cassettes/net/api_key_service/lifecycle.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion EasyPost.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>
<id>EasyPost-Official</id>
<title>EasyPost (Official)</title>
<version>7.4.0</version>
<version>7.5.0</version>
<authors>EasyPost</authors>
<owners>EasyPost</owners>
<projectUrl>https://www.easypost.com</projectUrl>
Expand Down
12 changes: 12 additions & 0 deletions EasyPost/Models/API/ApiKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,24 @@ public class ApiKey : EasyPostObject
{
#region JSON Properties

/// <summary>
/// Whether the API key is active.
/// </summary>
[JsonProperty("active")]
public bool? Active { get; set; }

/// <summary>
/// The actual key value to use for authentication.
/// </summary>
[JsonProperty("key")]
public string? Key { get; set; }

/// <summary>
/// The mode of the API key (e.g., "production" or "test").
/// </summary>
[JsonProperty("mode")]
public new string? Mode { get; set; }

#endregion
}

Expand Down
6 changes: 3 additions & 3 deletions EasyPost/Properties/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

// Version information for an assembly must follow semantic versioning
// When releasing a release candidate, append a 4th digit being the number of the release candidate
[assembly: AssemblyVersion("7.4.0")]
[assembly: AssemblyFileVersion("7.4.0")]
[assembly: AssemblyInformationalVersion("7.4.0")]
[assembly: AssemblyVersion("7.5.0")]
[assembly: AssemblyFileVersion("7.5.0")]
[assembly: AssemblyInformationalVersion("7.5.0")]
Loading
Loading