2

I was going through the list of REST API's for Azure Data Lake Storage Gen2 and facing problems when i call the api's from CLI/Postman.

i just started with simple get request path list api. Postman get request

But response am getting as below

{"error":{"code":"InvalidHeaderValue","message":"The value for one of the HTTP headers is not in the correct format.\nRequestId:ecb96bb0-501f-0030-2578-65cf12000000\nTime:2020-07-29T07:20:35.6240747Z"}}

After searching found sample code to create directory/file and tried to create directory but got response like

Put Request

curl -i -X PUT -H "x-ms-version: 2020-07-29" -H "content-length: 0" -H "Authorization: Bearer $ACCESS_TOKEN" "https://$AccountName.dfs.core.windows.net/mydata?resource=filesystem"

Response for the above request

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed
100   202  100   202    0     0    115      0  0:00:01  0:00:01 --:--:--   115HTTP/1.1 400 The value         
for one of the HTTP headers is not in the correct format.
Content-Length: 202
Content-Type: application/json;charset=utf-8
Server: Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: 8d615c77-001f-0070-2b79-65c82a000000
Date: Wed, 29 Jul 2020 07:25:54 GMT

{"error":{"code":"InvalidHeaderValue","message":"The value for one of the HTTP headers is not in the correct format.\nRequestId:8d615c77-001f-0070-2b79-65c82a000000\nTime:2020-07-29T07:25:55.9048230Z"}}

For authentication i am using https://login.microsoftonline.com/{{tenantID}}/oauth2/token? and then capturing the bearer token in Test section using this below code.

pm.test(pm.info.requestName, () => {
    pm.response.to.not.be.error;
    pm.response.to.not.have.jsonBody('error');
});
pm.globals.set("bearerToken", pm.response.json().access_token);

pm.test(pm.info.requestname, ()=>{
    pm.response.to.not.be.error;
    pm.response.to.not.have.jsonBody('error');
})
pm.globals.set('BearerToken',("Bearer ").concat(pm.response.json().access_token));

can anyone tell me where and what is going wrong?



Updating question as requested with Screenshots.

After doing so many trials figured outfilesystem-list i am getting response but for path-list getting error saying AuthorizationPermissionMismatch with 403 status code.

FileSystem List:

FileSystem-list

Path List:

Path-List

Headers for the failed one

enter image description here

Prateek Naik
  • 2,522
  • 4
  • 18
  • 38
  • What is the resource for your token? It should be `https://storage.azure.com` – Hong Ooi Jul 29 '20 at 10:08
  • IN resource was using `https://management.azure.com/` and tried with your suggestion also but the response is same. – Prateek Naik Jul 29 '20 at 10:23
  • Your resource should be `https://storage.azure.com`. Did I say this before? Why yes, yes I did – Hong Ooi Aug 07 '20 at 12:33
  • @HongOoi tried with `https://storage.azure.com` still the same response. `{"error":{"code":"AuthorizationPermissionMismatch","message":"This request is not authorized to perform this operation using this permission.\nRequestId:8cb9734d-f01f-0090-19b8-6c4bb3000000\nTime:2020-08-07T12:44:57.8346082Z"}}` – Prateek Naik Aug 07 '20 at 12:46
  • @HongOoi tell me how come it is working for `file system - list` API ? – Prateek Naik Aug 07 '20 at 12:47

1 Answers1

1

Update 0807:

Suppose you have already created a Service principal. Then follow the steps below:

Step 1: In azure portal, your ADLS Gen2 -> click on the "Access Control" -> click "Add" -> click "Add role assignment" -> in the "Add role assignment" popup, select "Contributor" for Role; then select your Service Principal name; at last, click Save button. The screenshot as below(Note, it may take a few minutes to take effect.):

enter image description here

Then add the "Storage Blob Data Reader" role:

enter image description here

Step 2: In postman, input this url for get request: https://login.microsoftonline.com/<tenant_id>/oauth2/token.

Then in Body -> select "form-data", and input the following keys and values:

grant_type:  client_credentials
client_id :  xxxxxxx
client_secret: xxxxxx
resource: https://storage.azure.com/

The screenshot as below:

enter image description here

At last, you can call the ADLS Gen2 rest api(note: the x-ms-date should be set to today). The screenshot as below:

enter image description here


Update 0730: How to use SAS token for authentication.

1.Nav to azure portal -> your "data lake storage gen2 account" -> then in the left pane, click on "Shared access signature" -> then select proper values -> at last, click the "Generate SAS and connection string" button. And please refer to the screenshot below:

enter image description here

2.Open postman, and there're something you should note:

1.for SAS token, please replace the first ? with &. Then place the SAS token at the end of the url. 2.if you're using SAS token, then you no need to use Authorization in the request header, please remove it.

Here is the screenshot:

enter image description here

Please let me know if you still have more issues.


Original answer:

There're several errors in your request.

Take Path - List for example, the x-ms-version should be 2018-11-09; and you should add the x-ms-date in the request header; and please remove the Content-Length in the request header.

I test it at my side, it works ok. Here is the test result:

enter image description here

Please let me know if you still have more issues.

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60