{"record":{"id":"84dede6d54dee580","repo":"nopSolutions/nopCommerce","slug":"failed-to-get-invitation","errorCode":null,"errorMessage":"Failed to get invitation","messagePattern":"Failed to get invitation","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Plugins/Nop.Plugin.Tax.Avalara/Services/AvalaraTaxManager.cs","lineNumber":1739,"sourceCode":"    /// A task that represents the asynchronous operation\n    /// The task result contains the URL to redirect customer\n    /// </returns>\n    public async Task<string> GetInvitationAsync(Customer customer)\n    {\n        return (await HandleFunctionAsync(async () =>\n        {\n            if (_avalaraTaxSettings.CompanyId is null)\n                throw new NopException(\"Company not selected\");\n\n            //create invitation for customer\n            var invitationModel = new List<CreateCertExpressInvitationModel>\n            {\n                new() { deliveryMethod = CertificateRequestDeliveryMethod.Download }\n            };\n            var invitation = (await ServiceClient\n                .CreateCertExpressInvitationAsync(_avalaraTaxSettings.CompanyId.Value, customer.Id.ToString(), invitationModel))\n                ?.FirstOrDefault()?.invitation\n                ?? throw new NopException(\"Failed to get invitation\");\n\n            return invitation.requestLink;\n        })).Result;\n    }\n\n    #endregion\n\n    #region Item classification\n\n    /// <summary>\n    /// Get item classification\n    /// </summary>\n    /// <returns>\n    /// A task that represents the asynchronous operation\n    /// The task result contains the classification results\n    /// </returns>\n    public async Task<(HSClassificationModel model, string Error)> ClassificationProductsAsync(ItemClassification item)\n    {","sourceCodeStart":1721,"sourceCodeEnd":1757,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Plugins/Nop.Plugin.Tax.Avalara/Services/AvalaraTaxManager.cs#L1721-L1757","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the customer exists in Avalara (create/link the customer entity first).","Verify CertExpress is enabled on the Avalara account and the Download delivery method is allowed.","Log the raw SDK response to distinguish 'no invitation returned' from a real API error."],"exampleFix":"// before\nvar invitation = (await ServiceClient\n    .CreateCertExpressInvitationAsync(_avalaraTaxSettings.CompanyId.Value, customer.Id.ToString(), invitationModel))\n    ?.FirstOrDefault()?.invitation\n    ?? throw new NopException(\"Failed to get invitation\");\n\n// after — clearer diagnostics\nvar result = await ServiceClient.CreateCertExpressInvitationAsync(_avalaraTaxSettings.CompanyId.Value, customer.Id.ToString(), invitationModel);\nvar invitation = result?.FirstOrDefault()?.invitation;\nif (invitation is null)\n    throw new NopException($\"Failed to get invitation for customer {customer.Id} (customer may not exist in Avalara or CertExpress is disabled)\");","handlingStrategy":"try-catch","validationCode":"var customerExists = await ServiceClient.GetCustomerAsync(_avalaraTaxSettings.CompanyId.Value, customer.Id.ToString()) is not null;\nif (!customerExists) throw new NopException($\"Customer {customer.Id} not found in Avalara\");","typeGuard":null,"tryCatchPattern":"try { return await GetInvitationAsync(customer); }\ncatch (NopException ex) when (ex.Message.Contains(\"Failed to get invitation\"))\n{ _logger.LogError(ex, \"CertExpress invitation failed for {Id}\", customer.Id); throw; }","preventionTips":["Ensure the customer exists in Avalara before requesting an invitation.","Confirm the Download delivery method is permitted on the account.","Log the raw SDK response to distinguish 'no invitation' from a real error."],"tags":["avalara","certcapture","certexpress","null-response","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}