Web API: How to fetch token using basic auth?

Luuk van Vliet 276 Reputation points
2021-01-06T10:38:36.003+00:00

Hello,

I try to fetch a token from a web api making a post request to the token endpoint. I am used to do this with Python but I don't know how to do this using ADF.

Python code I normally use:

   requests = requests.Session()  
     
   def authorization():  
       url = BASE_URL + "/login/login/"  
     
       auth = ("username", "password")  
                     
       response = requests.post(url, auth = auth).json()  
       requests.headers['authorization'] = 'Bearer ' + str(response.get("token"))   
       requests.headers['cache-control'] = "no-cache"  
       requests.headers['content-type'] = "application/json"  

How do I get this working in ADF?

53974-image.png

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,698 questions
0 comments No comments
{count} votes

Accepted answer
  1. Saurabh Sharma 23,816 Reputation points Microsoft Employee
    2021-01-06T16:04:23.81+00:00

    @Luuk van Vliet Thanks for using Microsoft Q&A !!

    If you want to use Basic authentication as your authentication method for the calling your endpoint in a Web Activity then you need to do the below changes -

    • Expand "Advanced" section in your web activity and select "Basic" from the available list and pass username/password. Please note that you need to store username password in Azure Key Vault which can be referred over here.
      53837-image.png
    • You also need to add Content-Type Header as application/Json under Headers section as shown below -
      54093-image.png
      • You can use Body section to sent the JSON payload like below -
        54112-image.png

    Please refer to the below the final pipeline GIF.
    54113-webapi-adf.gif
    You can also refer to this video and Web activity in Azure Data Factory documentation for additional information.
    Please let me know if you have any questions.


    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.