none
Attempting to Run an ADFv2 Pipeline using the REST API

    Question

  • I have been working all day today on the following and trying to google anything I can about the Data Factory and the REST APIs.

    I feel I have constructed the proper HTTP Post command to fire off my Data Factory Pipeline (the pipeline itself run from within the ADFv2 is working great – A Stored Proc calling an SSIS IR Package). The following is the POST I have been trying to get to run this ADFv2 Pipeline (as per the literature) from outside of Azure:

    http://management.azure.com/subscriptions/23b65d0e-b7be-4151-8e09-1324a916d00c/resourceGroups/OPC-POC/providers/Microsoft.DataFactory/factories/OPC-POC-ADF/pipelines/pipeline1/createRun?api-version=2017-03-01-preview

    I have been trying to test this with the tool Postman, which is awesome at testing HTTP Commands like POST, GET etc but I am getting an error regarding security. I am starting to wonder if I can not run the HTTP Post outside of my Azure Subscription using a tool like Postman due to security. I am getting the same when I just paste it into a browser.

    What are your thoughts on this? I am going to attempt to build an Azure Function tomorrow using this HTTP Post and hope that it is not the command itself as I tried to follow the docs. I appreciate any advice you might have on this. 



    Mike Kiser

    Thursday, April 12, 2018 1:15 AM

Answers

  • Hi Mike,

    Is the access token contained in your HTTP Authorization header?

    Please refer to Register your client application with Azure AD

    and this one Create an Azure data factory and pipeline by using the REST API
    • Edited by Bo Xiao (MSFT) Thursday, April 12, 2018 1:46 AM
    • Marked as answer by EMKISER Friday, April 13, 2018 2:12 PM
    Thursday, April 12, 2018 1:42 AM
  • Hi Mike,

    You might get an access token through Authenticate with Azure AD

    $AuthContext = [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext]"https://login.microsoftonline.com/${tenantId}"
    $cred = New-Object -TypeName Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential -ArgumentList ($appId, $authKey)
    $result = $AuthContext.AcquireToken("https://management.core.windows.net/", $cred)
    $authHeader = @{
    'Content-Type'='application/json'
    'Accept'='application/json'
    'Authorization'=$result.CreateAuthorizationHeader()
    }

    Then please add the token in your HTTP header.


    • Marked as answer by EMKISER Friday, April 13, 2018 2:12 PM
    Thursday, April 12, 2018 7:42 AM
  • Hi Mike,

    This is a XMLHttp request example.

      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
          //
        }
      };
      xhttp.open("POST", your_url, true);
      xhttp.setRequestHeader("Content-type", "application/json");
      xhttp.setRequestHeader("Authorization", "Bearer your_token");
      xhttp.send("your_data");
    You may find the similar syntax for different coding languages. Basically you can setRequestHeader before sending your request.

    • Marked as answer by EMKISER Friday, April 13, 2018 1:57 PM
    Friday, April 13, 2018 2:38 AM

All replies

  • Hi Mike,

    Is the access token contained in your HTTP Authorization header?

    Please refer to Register your client application with Azure AD

    and this one Create an Azure data factory and pipeline by using the REST API
    • Edited by Bo Xiao (MSFT) Thursday, April 12, 2018 1:46 AM
    • Marked as answer by EMKISER Friday, April 13, 2018 2:12 PM
    Thursday, April 12, 2018 1:42 AM
  • Hi Bo,

    Thanks for the quick response!

    No, I don't have an access token in the HTTP Authorization Header; would it be the access token for my Data Factory? I need to look at the links in your email as I am not familiar with that. I read the 2nd link over several times yesterday and it doesn't relate much on the REST APIs and authorizations but I will read it again tomorrow. Would you have an example access token in an HTTP Authorization Header for me to understand better?

    Thanks again Bo!
    Mike


    Mike Kiser

    Thursday, April 12, 2018 3:14 AM
  • Hi Mike,

    You might get an access token through Authenticate with Azure AD

    $AuthContext = [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext]"https://login.microsoftonline.com/${tenantId}"
    $cred = New-Object -TypeName Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential -ArgumentList ($appId, $authKey)
    $result = $AuthContext.AcquireToken("https://management.core.windows.net/", $cred)
    $authHeader = @{
    'Content-Type'='application/json'
    'Accept'='application/json'
    'Authorization'=$result.CreateAuthorizationHeader()
    }

    Then please add the token in your HTTP header.


    • Marked as answer by EMKISER Friday, April 13, 2018 2:12 PM
    Thursday, April 12, 2018 7:42 AM
  • Hi Bo,

    It was the Bearer Token (Access Token) that I needed. I got it using Fiddler. My url is

    https://management.azure.com/subscriptions/23b65d0e-b7be-4151-8e09-1324a916d00c/resourceGroups/OPC-POC/providers/Microsoft.DataFactory/factories/OPC-POC-ADF/pipelines/pipeline1/createRun?api-version=2017-03-01-preview

    and is working in Postman when I entered my bearer token. However (sorry I have never worked in this area), so how do I put the token in the Authorization Header for my url shown above? In other words when I am calling this from an Azure Function for example, and I know the token, how does this HTTP Post syntax look? With this I can complete my work and meet my deadline.

    Thanks again
    Mike


    Mike Kiser

    Thursday, April 12, 2018 5:18 PM
  • Hi Mike,

    This is a XMLHttp request example.

      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
          //
        }
      };
      xhttp.open("POST", your_url, true);
      xhttp.setRequestHeader("Content-type", "application/json");
      xhttp.setRequestHeader("Authorization", "Bearer your_token");
      xhttp.send("your_data");
    You may find the similar syntax for different coding languages. Basically you can setRequestHeader before sending your request.

    • Marked as answer by EMKISER Friday, April 13, 2018 1:57 PM
    Friday, April 13, 2018 2:38 AM
  • Thanks, Bo! This is exactly what I had hoped for. I very much appreciate your assistance!

    Mike


    Mike Kiser

    Friday, April 13, 2018 1:58 PM