nopSolutions/nopCommerce · error · NopException

AccountId not set

Error message

AccountId not set

What it means

Thrown by PrepareSecurity() in ItemClassificationHttpClient when _avalaraTaxSettings.AccountId is null. PrepareSecurity builds the Basic-auth token '{AccountId}:{LicenseKey}' base64-encoded for the HS classification API, so both values are mandatory.

Source

Thrown at src/Plugins/Nop.Plugin.Tax.Avalara/Services/ItemClassificationHttpClient.cs:49

        httpClient.DefaultRequestHeaders.Add(HeaderNames.UserAgent, AvalaraTaxDefaults.UserAgent);
        httpClient.DefaultRequestHeaders.Add(HeaderNames.Accept, MimeTypes.ApplicationJson);

        _avalaraTaxSettings = avalaraTaxSettings;
        _httpClient = httpClient;
    }

    #endregion

    #region Utilities

    /// <summary>
    /// Set security using CompanyId / License Key
    /// </summary>
    /// <returns>Security token</returns>
    protected string PrepareSecurity()
    {
        if (_avalaraTaxSettings.AccountId is null)
            throw new NopException("AccountId not set");

        if (_avalaraTaxSettings.LicenseKey is null)
            throw new NopException("LicenseKey is not set");

        var s = $"{_avalaraTaxSettings.AccountId}:{_avalaraTaxSettings.LicenseKey}";
        return Convert.ToBase64String(Encoding.UTF8.GetBytes(s));
    }

    #endregion

    #region Methods

    /// <summary>
    /// Request services
    /// </summary>
    /// <typeparam name="TRequest">Request type</typeparam>
    /// <typeparam name="TResponse">Response type</typeparam>
    /// <param name="request">Request</param>

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Enter the Avalara AccountId (found in the Avalara account settings) on the plugin configuration page.
  2. Ensure both AccountId AND LicenseKey are saved together — the validation should require both.
  3. Verify the settings saved to the correct store scope.

Example fix

// before
if (_avalaraTaxSettings.AccountId is null)
    throw new NopException("AccountId not set");

// after — fail fast at config-save time in the controller
if (string.IsNullOrWhiteSpace(model.AccountId) || string.IsNullOrWhiteSpace(model.LicenseKey))
    ModelState.AddModelError(string.Empty, "Avalara AccountId and LicenseKey are both required");
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(_avalaraTaxSettings.AccountId))
    throw new InvalidOperationException("Avalara AccountId is required for HS classification");

Type guard

static bool HasAccountId(AvalaraTaxSettings s) => !string.IsNullOrWhiteSpace(s?.AccountId);

Try / catch

try { await _itemClassificationHttpClient.RequestAsync<...,...>(req); }
catch (NopException ex) when (ex.Message == "AccountId not set")
{ _notificationService.ErrorNotification("Enter your Avalara AccountId."); }

Prevention

When it happens

Trigger: Any HS classification HTTP request is sent (RequestAsync) while the Avalara AccountId has not been entered in the plugin configuration.

Common situations: Plugin configured with LicenseKey but AccountId left blank, or vice-versa; fresh install; settings cleared after DB migration.

Related errors


AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13). Data as JSON: /api/errors/1f1cff9210b57293. Report an issue: GitHub.