Wednesday, 7 June 2017

Pardot and node for API authentication and retrieve posted data

Ok I am trying to send data from the front-end (Angular) then send data to the backed (node).

I also need to authenticate my the third party API in the backed by getting my API key by sending a post with my email, password and user_key, once posted I should get a temp api_key.

I then use this key and my retried data (from front-end) to post the the API end point.

Im getting a bit lost and am new to angular and node.

I need some help with a few things

  • retrieving my posted data from front-end
  • Authentication (get api_key)
  • post full data (Fname, Lname, email, user_key, api_key)

I have used a npm package found for the API im sending to found here

Here is where I have got to, any help will be good.

Backed server/index.js

 // First Get Posted variables

// Code HERE


// Now authenticate the api and get api_key
var pardot = require('pardot');
pardot({
    email: 'tom@mail.co.uk',
    password: 'Password',
    userKey: '345636345345'
})
    .then(function (client) {
        // We've successfully authenticated.
        // Perform some action

        client.prospects.create(email, params, {
            email: 'test',
            Fname: 'tom',
            Lname: 'boom'
        });

    }).fail(function (err) {
    // Failed to authenticate

    alert('failed')
});

Front end post`

FirstModule.controller('formController', function ($scope, $http) {
    $scope.formData = {};

    $scope.processForm = function (Fname, Lname, email) {
        var data = {
            Fname: $scope.formData.Fname,
            Lname: $scope.formData.Lname,
            email: $scope.formData.email,
        };

//Call the services
        $http.post('server/index', JSON.stringify(data)).then(function (response) {
            if (response.data)
                $scope.formData = "Post Data Submitted Successfully!";

        }, function (response) {
            $scope.formData = "Post Data Submitted Failed";
            $scope.statusval = response.status;
            $scope.statustext = response.statusText;
            $scope.headers = response.headers();
        });
    };
});`



via Beep

No comments:

Post a Comment