none
Azure Data Lake Gen2 API Header Error

    Question

  • I am trying to call the gen2 rest endpoint directly and keep getting an error that I am missing a required header (MissingRequiredHeader message An HTTP header that's mandatory for this request is not specified. I fail to see what header is missing. I'm using the following code to send the request.

                    var client = new HttpClient();
    
                    client.BaseAddress = new Uri($"https://{account}.dfs.core.windows.net/");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Add("api_version", "2018-11-09");
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _authResult.AccessToken);
                    
                    string azPath = $"{baseRawSystemPath}/{path.Replace("\\", "/")}";
    
                    byte[] bytes = Encoding.UTF8.GetBytes(content);
                    HttpContent body = new StringContent(content, Encoding.UTF8, "application/json");
    
                    HttpResponseMessage response = await client.PutAsync(azPath, body);
                    if (response.IsSuccessStatusCode)
                    {
                        var responseListingJson = await response.Content.ReadAsStringAsync();
                        return;
                    }
                    else
                    {
                        var error = await response.Content.ReadAsStringAsync();
                        return;
                    }




    Wednesday, February 27, 2019 5:25 PM

All replies

  • Hi Nelson,

    I found a similar thread that might be useful in your case as well. Please have a look at the answer on this thread and let us know if it helps. Else, we can gladly continue to probe in further.


    MSDN

    Tuesday, March 5, 2019 6:34 AM
    Moderator
  • Yeah, I looked at that thread already and it doesn't help.  They are using the list api which I have no trouble accessing.  I can see my file system including both folders and files.  I am trying to use the path create and then getting the error.  The API doc does not list any other required headers.

    https://docs.microsoft.com/en-us/rest/api/storageservices/datalakestoragegen2/path/create


    Tuesday, March 5, 2019 3:20 PM
  • Hi Nelson,

    Sorry for the delayed response. I was working with the team on the issue and found out the problem. 

    Once you have all the right permissions, you need to acquire an access token. To do so, you can use the following API (POST request) :

    https://login.microsoftonline.com/$TENANT_NAME/oauth2/v2.0/token

    Header needed - "Content-Type: application/x-www-form-urlencoded"

    To create a file system, you can use the following API :

    https://$STORAGE_ACCOUNT_NAME.dfs.core.windows.net/mydata?resource=filesystem

    Headers needed -  "content-length: 0", "x-ms-version: 2018-11-09", "Authorization: Bearer $ACCESS_TOKEN" 

    Hope this helps.


    MSDN

    Wednesday, March 20, 2019 10:54 AM
    Moderator
  • Hi Nelson,

    Just wanted to check - was the issue resolved with the above suggestion ?


    MSDN

    Thursday, March 28, 2019 10:25 AM
    Moderator