Home > Back-end >  rest operations Azure Datalake gen2
rest operations Azure Datalake gen2

Time:11-15

I want to do operations in Azure datalake gen2 using rest operations. I have a service principal with client secret and having owner access on storage account. I am confused how to construct the request for operations. I can't find any proper example demonstrating it. The way which I want is to:

  1. Get access token
  2. Make a put request with bearer authentication method

Below are documents which I am referring

Access token

Put blob operation

I want to do it through postman. It would be really helpful if someone can suggest it

CodePudding user response:

I tried to reproduce the same in my environment and got below results:

I created one service principal named DataLake and added API permissions as below:

enter image description here

Now, I granted Storage Blob Data Contributor role to that service principal at storage account level like below:

Go to Azure Portal -> Storage Accounts -> Your storage account -> Access Control (IAM) -> Add role assignment -> Storage Blob Data Contributor

enter image description here

To generate the access token via Postman, I used below parameters:

POST https://login.microsoftonline.com/<tenantID>/oauth2/v2.0/token

client_id:<appID>
grant_type:client_credentials
client_secret:<secret>
scope: https://storage.azure.com/.default

Response:

enter image description here

When I ran the below query by including above Bearer token, I got Status 201 Created like below:

PUT https://<storageaccname>.blob.core.windows.net/<container_name>/test.txt

Authorization:Bearer <token>
x-ms-version:2017-11-09
x-ms-blob-type:BlockBlob

Response:

enter image description here

You need to attach the file in Postman before running the query like below:

enter image description here

When I checked the same in Azure Portal, file uploaded to storage account successfully like below:

enter image description here

  • Related