I've been working on migrating data from one database to another in an angular.js application, and I am facing some challenges with the code. The specific issue arises when trying to obtain authorization credentials for sending POST requests to the receiving database. Although my initial function,
ATsintegrationsService.beginBackfill(clientIDs)
, successfully retrieves the list of applicants, the problem starts at getAuthToken()
. Despite correctly accessing the URL with the required data, I keep encountering errors within the service. If anyone could provide insights into what might be causing these problems, I would greatly appreciate it as I'm currently stuck.
The main function triggered by pressing an apply button:
$scope.beginBackfill = function() {
$scope.loading = true;
AtsintegrationsService.beginBackfill($scope.clientids).then(function (response) {
$scope.applicants = response.data;
$scope.getAuthToken();
$scope.createSuccess = true;
$scope.loading = false;
},
function(error) {
$scope.loading = false;
$scope.createFailure = true;
console.log("Failure to backfill data - " + error);
});
};
This is how $scope.getAuthToken()
is implemented:
$scope.getAuthToken = function() {
AtsintegrationsService.getAuthToken().then(function (response) {
$scope.authToken = response.data;
console.log($scope.authToken);
},
function(error) {
$scope.loading = false;
$scope.createFailure = true;
console.log("Failure to obtain auth token - " + error);
console.log(error);
});
};
And this is the service code for getAuthToken()
, where certain sensitive data has been replaced with placeholders like {snip}
.
srvc.getAuthToken = function () {
var url = {snip};
return $http({
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
responseType: 'json',
method: 'POST',
url: url,
data:
{
"grant_type": "{snip}",
"client_id": {snip},
"client_secret": "{snip}"
}
})
.success(function (data) {
console.log("We have a proper return.");
return data;
})
.error(function (data) {
console.log("There was an error in the service.");
return data;
});
};