locked
Unable to pass body value into datafactory pipeline RRS feed

  • Question

  • Hi Team,

    We have datafactory pipeline where we will call pipileine run method from node js. But inside node js i am passing input path and output path .

    I am able to run pipeline but input and output path value not coming.

    Requesting help for the same

    sample code

    'use strict';
    var AuthenticationContext = require('adal-node').AuthenticationContext;
    var tenant = '########';

    var authorityHostUrl = '#########';
    var clientId = '######';
    var clientSecret = '######';
    var authorityUrl = authorityHostUrl + '/' + tenant;
    var resource = '#######';
    var context = new AuthenticationContext(authorityUrl);
    var express = require('express');
    const app = express();
    const https = require('https');
    const writer = require('./writer.js');
    const serverPort = process.env.PORT || 8090;
    var bodyParser = require('body-parser');
    app.use(bodyParser.json()); // support json encoded bodies
    app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies

    app.post('/dialdata', function (req, res) {
        context.acquireTokenWithClientCredentials(resource, clientId, clientSecret, function (err, tokenResponse) {
            if (err) {
                console.log('Error in connection: ' + err.stack);
            }
            else {
                // parse json
                var jsonParsed = JSON.stringify(tokenResponse);
                var jsonObj = JSON.parse(jsonParsed);
                var tokenType = jsonObj.tokenType;
                var token = jsonObj.accessToken;
           
                var inputPath = req.body.inputPath;
                var outputPath = req.body.outputPath;
                var bodyData = { "inputPath": inputPath", "outputPath": outputPath }
                console.log(bodyData)
                console.log(JSON.stringify(bodyData))
                const options = {
                    hostname: 'management.azure.com',
                    port: 443,
                    path: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelines/{pipelineName}/createRun?api-version=2018-06-01',
                    body: JSON.stringify( bodyData ),
                    method: 'POST',
                    headers: {
                        'Authorization': tokenType + ' ' + token,
                        'Content-Type': 'application/json'
                    }
                  
                };
                var req2 = https.request(options, result => {
                    result.on('data', (chunk) => {
                        console.log(JSON.stringify(chunk));
                       
                       // res.send(inputPath,);
                        res.send(chunk);
                     //   res.send(inputPath + ' ' + outputPath + ' ' + chunk);

                    });
                })
                req2.on('data', (data) => {
                    console.log(data);
                });
                req2.on('error', (e) => {
                    console.error(`problem with request: ${e.message}`);
                    res.send('Error');
                });
                req2.write(JSON.stringify(bodyData))
                req2.end()
             }
        }
        )
    });

    // });

    // // Start the server
    var server = app.listen(serverPort);
    //export server so it can be unit-tested
    module.exports = { server, app }

    Thanks

    Swarupk

    Friday, March 29, 2019 1:44 PM

All replies

  • Just to make sure that we understand the problem statement we re trying to trigger a pipeline from nodejs and the output and input path which you are passing to the pipeline is not being captured by the pipeline . 

    If our understanding is correct , did you tried to invoke the API using curl/postman and see if that works ?

    That way you please know if this a problem with nodejs or API .


    Thanks Himanshu

    Wednesday, April 3, 2019 6:15 PM