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:
- Get access token
- Make a put request with bearer authentication method
Below are documents which I am referring
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:
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
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:
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:
You need to attach the file in Postman before running the query like below:
When I checked the same in Azure Portal, file uploaded to storage account successfully like below: