Home
About
Search
Welcome to M-Files Empower – our new support experience. We'd love to hear what you think!Give feedback
Home/Support and troubleshooting/Troubleshooting/Common problems

REST API calls may suddenly fail around January 2024 and miss cookies

Last updated on 9 December 2024 · 4 min read

Admin
REST API

Overview

This article applies to the following set of circumstances:

  • You have a vault in the "New" M-Files Cloud.
  • You have a REST API integration that has been working for some time.
  • The REST API integration stopped working suddenly around the beginning of the year 2024.
  • None of the requests succeed.
  • You get only one cookie in the /server/authenticationtokens response (the ASP.NET_SessionId cookie) and you do not get the mfilesmsm cookie in the response.

Details

Old .NET versions (such as .NET 4.7.2 and .NET 4.8) by default send the Expect: 100-continue header. This can cause the cookie to be missing as it causes communication incompatibility with newer network components that we now have in place to improve security.

Newer .NET versions (such as .NET 6 or .NET 8) do not send it by default. With them things should work fine.

NOTE: This article uses .NET as a common and known example, other tools/frameworks may also exhibit the same behavior, as it stems from the expect: 100-continue header, not from the tool itself.

Solution

Do NOT send the Expect: 100-continue header.

Usually this can be done with the setting highlighted in the code sample above for .NET:

wr.ServicePoint.Expect100Continue = false;

Alternatively, upgrade the version of .NET used to a new one (such as .NET 8 at the time of writing).

If you use other tools, ensure they do not send this header.

Sample Code and Results

Here is a sample code that can be used to reproduce the issue with .NET 4.7.2 Console application, and screenshots of the expected vs the problematic output. To run this, add also a reference to Newtonsoft.Json.

image.png

image.png

using System.Net;

using Newtonsoft.Json;

using System;

using System.IO;

namespace ConsoleApp1

{

    class Credentials

    {

        public string Username = "";

        public string Password = "";

        public string VaultGuid = "";

    };

    class Program

        {

        static bool Connect()

        {

            try

            {

                string yourVaultName = "YourCloudVault";

                var server = new Uri( $"https://{yourVaultName}.cloudvault.m-files.com/REST/server/authenticationtokens.aspx" );

                               HttpWebRequest wr = HttpWebRequest.CreateHttp( server );

                wr.CookieContainer = new CookieContainer();

                wr.Method = "POST";

                // without this, old .NET versions (4.7.2 and 4.8) send the "Expect: 100-continue" header

                // while new ones such as .NET 8 do not

                // its presence can cause the load balancing cookie (mfilesmsm) to be missing

                wr.ServicePoint.Expect100Continue = false;

                //basic authentication sample follows, dummy data used for illustration purposes

               Credentials cred = new Credentials();

                cred.Username = "test";

                cred.Password = "test";

                cred.VaultGuid = "{0000-0000-0000-0000}";

                var jsonSerializer = Newtonsoft.Json.JsonSerializer.CreateDefault();

                using( var streamWriter = new StreamWriter( wr.GetRequestStream() ) )

                {

                    using( var jsonTextWriter = new JsonTextWriter( streamWriter ) )

                    {

                        {

                           {

                               jsonSerializer.Serialize( jsonTextWriter, cred );

                           }

                        }

                    }

                }

                var authenticationResponse = ( HttpWebResponse )wr.GetResponse();

                var cookies = authenticationResponse.Cookies;

                // log the cookies we got

                Console.WriteLine( String.Format( "{0} cookies received", cookies.Count ) );

                for( int i = 0; i < cookies.Count; i++ )

                {

                   Console.WriteLine( String.Format( "{0} = {1}", i, cookies[ i ] ) );

                }

            }

            catch( Exception ex )

            {

                Console.WriteLine( "Error: " + ex.Message );

            }

            return true;

        }

        public static void Main()

        {

            Connect();

        }

    }

}

Still need help?