public ConnetionWebFormResult ImportBankConnection(long bankid, string userId, string userPassword, string redirectUrl)
        {
            var token = GetUserAccessToken(userId, userPassword);

            var body = new ImportBankConnectionParams();

            body.BankId = bankid;

            var body2 = new { bankId = bankid };

            //var userApi = new BankConnectionsApi(BasePath);
            //userApi.ApiClient.AddDefaultHeader("Authorization", "Bearer " + response._AccessToken);
            var request = new RestRequest("/api/v1/bankConnections/import", Method.POST);

            request.AddHeader("Authorization", "Bearer " + token);
            request.AddJsonBody(body2);
            var responseX = restClient.Execute <BankConnection>(request);

            if (responseX.StatusCode == System.Net.HttpStatusCode.UnavailableForLegalReasons)
            {
                var errorMessage = JsonConvert.DeserializeObject <ErrorMessage>(responseX.Content);
                var result       = new ConnetionWebFormResult();

                result.WebFormId = int.Parse(errorMessage.Errors.First().Message);
                var webformurl = responseX.Headers.SingleOrDefault(h => h.Name == "Location").Value.ToString();

                if (redirectUrl.Contains("{connectid}"))
                {
                    redirectUrl = redirectUrl.Replace("{connectid}", result.WebFormId.ToString());
                }

                // see docs here https://finapi.zendesk.com/hc/en-us/articles/360002596391
                webformurl        = webformurl + "?redirectUrl=" + WebUtility.UrlEncode(redirectUrl);
                result.WebFormUrl = webformurl;



                return(result);
            }

            throw new Exception("this case should currently not happen, as evry connection should end up in webform flow");
        }
        /// <summary>
        /// Import a new bank connection Imports a new bank connection for a specific user. Must pass the connection credentials and the user&#39;s access_token. All bank accounts will be downloaded and imported with their current balances, transactions and supported two-step-procedures (note that the amount of available transactions may vary between banks, e.g. some banks deliver all transactions from the past year, others only deliver the transactions from the past three months). The balance and transactions download process runs asynchronously, so this service may return before all balances and transactions have been imported. Also, all downloaded transactions will be categorized by a separate background process that runs asynchronously too. To check the status of the balance and transactions download process as well as the background categorization process, see the status flags that are returned by the GET /bankConnections/&lt;id&gt; service.&lt;br/&gt;&lt;br/&gt;You can also import a \&quot;demo connection\&quot; which contains a single bank account with some pre-defined transactions. To import the demo connection, you need to pass the identifier of the \&quot;finAPI Test Bank\&quot;. In case of demo connection import, any other fields besides the bank identifier can remain unset. The login credentials and the &#39;storeSecrets&#39; field will be stored if you pass them, however they will not be regarded when updating the demo connection (in other words: It doesn&#39;t matter what credentials you choose for the demo connection). Note however that if you want to import the demo connection multiple times for the same user, you must use different login credentials for each of the imports. Also note that the skipPositionsDownload flag is ignored for the demo bank connection, i.e. when importing the demo bank connection, you will always get the transactions for its account. You can enable multi-step authentication for the demo bank connection by setting the bank connection name to \&quot;MSA\&quot;.&lt;br/&gt;&lt;br/&gt;The XS2A interface could also be used to initiate a demo connection import.&lt;br/&gt;The finAPI demo XS2A allows you to download a test account by using the &#39;import&#39; or &#39;connectInterface&#39; services - in general, this XS2A demo account is the FINTS_SERVER demo account, as it has the same account number and origin of balances and transactions.&lt;br/&gt;Keep in mind that calling an XS2A demo connection import will result as a newly created bank connection, while the &#39;connectInterface&#39; service attaches the XS2A demo account to an existing demo connection.&lt;br/&gt;Passing the login credentials is not obligated only for redirect banks, however the demo bank works without any given set of credentials for the XS2A interface. If you are looking to test the XS2A SCA (Strong Customer Authentication, or MSA (Multi-Step Authentication) in the finAPI context), you need to pass the bank connection name as \&quot;MSA\&quot; to trigger the SCA flow or as &#39;DECOUPLED-AUTH&#39; to simulate decoupled authentication. To get better understanding about the Multi-Step Authentication, please refer to the &#39;Error Messages&#39; section of the swagger documentation.&lt;br/&gt;&lt;br/&gt;&lt;b&gt;For a more in-depth understanding of the import process, please also read this article on our Dev Portal: &lt;a href&#x3D;&#39;https://finapi.zendesk.com/hc/en-us/articles/115000296607-Import-Update-of-Bank-Connections-Accounts&#39; target&#x3D;&#39;_blank&#39;&gt;Import &amp; Update of Bank Connections / Accounts&lt;/a&gt;&lt;/b&gt;&lt;br/&gt;&lt;br/&gt;NOTE: Depending on your license, this service may respond with HTTP code 451, containing an error message with a identifier of web form in it. In addition to that the response will also have included a &#39;Location&#39; header, which contains the URL to the web form. In this case, you must forward your user to finAPI&#39;s web form. For a detailed explanation of the Web Form Flow, please refer to this article: &lt;a href&#x3D;&#39;https://finapi.zendesk.com/hc/en-us/articles/360002596391&#39; target&#x3D;&#39;_blank&#39;&gt;finAPI&#39;s Web Form Flow&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;NOTE: For XS2A interface additional headers must be included in the request if the end user is involved. Please refer to the &#39;General Information/User metadata&#39; section of the swagger documentation.&lt;br/&gt;&lt;br/&gt;&lt;b&gt;Attention:&lt;/b&gt; Due to changes on the bank&#39;s side we have been forced to limit the maxDaysForDownload field to 89 days to reduce the risk of strong customer authentication (SCA) requests. If you have implemented the SCA flow, please contact us, so that we can remove this limitation from your client.
        /// </summary>
        /// <param name="body">Import bank connection parameters</param>
        /// <returns>BankConnection</returns>
        public BankConnection ImportBankConnection(ImportBankConnectionParams body)
        {
            // verify the required parameter 'body' is set
            if (body == null)
            {
                throw new ApiException(400, "Missing required parameter 'body' when calling ImportBankConnection");
            }


            var path = "/api/v1/bankConnections/import";

            path = path.Replace("{format}", "json");

            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>();
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, FileParameter>();
            String postBody     = null;

            postBody = ApiClient.Serialize(body);                                     // http body (model) parameter

            // authentication setting, if any
            String[] authSettings = new String[] { "finapi_auth" };

            // make the HTTP request
            IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings);

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling ImportBankConnection: " + response.Content, response.Content);
            }
            else if (((int)response.StatusCode) == 0)
            {
                throw new ApiException((int)response.StatusCode, "Error calling ImportBankConnection: " + response.ErrorMessage, response.ErrorMessage);
            }

            return((BankConnection)ApiClient.Deserialize(response.Content, typeof(BankConnection), response.Headers));
        }