nopSolutions/nopCommerce · error · NopException

Failed to get invitation

Error message

Failed to get invitation

What it means

Thrown when CreateCertExpressInvitationAsync returns null/empty (the ?.FirstOrDefault()?.invitation chain yields null). The SDK returned no invitation objects, meaning the CertExpress invitation could not be created.

Source

Thrown at src/Plugins/Nop.Plugin.Tax.Avalara/Services/AvalaraTaxManager.cs:1739

    /// A task that represents the asynchronous operation
    /// The task result contains the URL to redirect customer
    /// </returns>
    public async Task<string> GetInvitationAsync(Customer customer)
    {
        return (await HandleFunctionAsync(async () =>
        {
            if (_avalaraTaxSettings.CompanyId is null)
                throw new NopException("Company not selected");

            //create invitation for customer
            var invitationModel = new List<CreateCertExpressInvitationModel>
            {
                new() { deliveryMethod = CertificateRequestDeliveryMethod.Download }
            };
            var invitation = (await ServiceClient
                .CreateCertExpressInvitationAsync(_avalaraTaxSettings.CompanyId.Value, customer.Id.ToString(), invitationModel))
                ?.FirstOrDefault()?.invitation
                ?? throw new NopException("Failed to get invitation");

            return invitation.requestLink;
        })).Result;
    }

    #endregion

    #region Item classification

    /// <summary>
    /// Get item classification
    /// </summary>
    /// <returns>
    /// A task that represents the asynchronous operation
    /// The task result contains the classification results
    /// </returns>
    public async Task<(HSClassificationModel model, string Error)> ClassificationProductsAsync(ItemClassification item)
    {

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Ensure the customer exists in Avalara (create/link the customer entity first).
  2. Verify CertExpress is enabled on the Avalara account and the Download delivery method is allowed.
  3. Log the raw SDK response to distinguish 'no invitation returned' from a real API error.

Example fix

// before
var invitation = (await ServiceClient
    .CreateCertExpressInvitationAsync(_avalaraTaxSettings.CompanyId.Value, customer.Id.ToString(), invitationModel))
    ?.FirstOrDefault()?.invitation
    ?? throw new NopException("Failed to get invitation");

// after — clearer diagnostics
var result = await ServiceClient.CreateCertExpressInvitationAsync(_avalaraTaxSettings.CompanyId.Value, customer.Id.ToString(), invitationModel);
var invitation = result?.FirstOrDefault()?.invitation;
if (invitation is null)
    throw new NopException($"Failed to get invitation for customer {customer.Id} (customer may not exist in Avalara or CertExpress is disabled)");
Defensive patterns

Strategy: try-catch

Validate before calling

var customerExists = await ServiceClient.GetCustomerAsync(_avalaraTaxSettings.CompanyId.Value, customer.Id.ToString()) is not null;
if (!customerExists) throw new NopException($"Customer {customer.Id} not found in Avalara");

Try / catch

try { return await GetInvitationAsync(customer); }
catch (NopException ex) when (ex.Message.Contains("Failed to get invitation"))
{ _logger.LogError(ex, "CertExpress invitation failed for {Id}", customer.Id); throw; }

Prevention

When it happens

Trigger: The customer does not exist in Avalara under the configured company; the delivery method (Download) is not enabled for the account; Avalara rate-limits or returns an error wrapped as an empty result; the customer already has a pending invitation.

Common situations: Calling GetInvitationAsync for a customer that was never linked/synced to Avalara; CertExpress feature not enabled on the Avalara account; transient API error returning an empty list.

Related errors


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