angularjs not get data from woocommerce rest api - angularjs

Sorry to say I am new in REST-API and authentication.
I am writing an application on angularjs using yomen. I want to get data using woocommerce rest api from wordpress. I am working on my computer local node server
I have write my controller
/*get the function from phpjs*/
function rawurlencode(str) {
str = (str+'').toString();
return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
replace(/\)/g, '%29').replace(/\*/g, '%2A');
}
var oauth = OAuth({
consumer: {
public: 'ck_my_customer_key',
secret: 'cs_my_customer_secret'
},
signature_method: 'HMAC-SHA1'
});
var request_data = {
url: 'http://biswas-stall.com/wc-api/v1/products',
method: 'GET',
};
var data = oauth.authorize(request_data);
var url =rawurlencode(request_data.url) + "&" +
"oauth_consumer_key"+"%3D"+rawurlencode(data.oauth_consumer_key)+
"%26"+"oauth_nonce"+"%3D"+rawurlencode(data.oauth_nonce)+
"%26"+"oauth_signature_method"+"%3D"+rawurlencode(data.oauth_signature_method)+
"%26"+"oauth_timestamp"+"%3D"+rawurlencode(data.oauth_timestamp)+
"%26"+"oauth_signature"+"%3D"+rawurlencode(data.oauth_signature);
$http.get(url).success(function(data) {
console.log(data);
})
I am using https://github.com/ddo/oauth-1.0a this library for my authentication.
I am getting 404 Not Found massage. What is my wrong. Can any one help me?

Related

Read cookie in AngularJs, REST API

So, I created my client application using angular to interact with my WCF REST API. I basically use cookies to store the login session and retrieve the information by sessions. This works perfectly from Postman and also with a console client application (there I created cookie container).
Now I have a problem to read the cookies from AngularJs. My HTTP response header shows the cookies but the angular response header is undefined.
AngularService.js:
this.login = function (credential) {
var request = $http({
method: "POST",
url: "someUrlLogin",
data: angular.toJson(credental),
config: { withCredentials: true },
});
return request;
}
AngularContoller.js :
var promisePost = AngularService.login(credential);
promisePost.then(function (response) {
$scope.loginResult = angular.fromJson(response);
$timeout(function () {
console.log(response.headers("Set-Cookie"); //null
console.log($cookies["ASP.NET_SessionId"]); //undefined
console.log($cookies.getAll); //undefined
},
function error (err) {
$scope.loginResult = err;
});
WCF REST session:
_context.Session["USERLOGGEDIN"] = "SomeValue"
I have set the HTTPOnly flag to false
I have also tried "console.log(response.headers("setcookie") which also doesn't work
"Access-Control-Allow-Credentials = true"
"Access-Control-Expose-Headers" value="content-type, Set-Cookie"
What else am I missing? Is it even possible to read the cookies from the http response headers?

Not able to fetch employee details in web api using angularjs

Hi I am developing one web api application using angularjs. I am doing one small crud operation. I am not able to hit to controller when debugging. Below is my controll.js code.
$scope.EditSubscriber = function (sub) {
var servCall = UserCreation.getSubsbyID(sub.user_id);
servCall.then(function (d) {
$scope.user_email = d.user_email,
$scope.user_password = d.user_password
}, function (error) {
console.log('Oops! Something went wrong while fetching the data.')
});
}
Below is my service.js code.
this.getSubsbyID = function (user_id) {
return $http({
method: 'get',
data: JSON.stringify(user_id),
url: 'api/User_Creation/' + user_id,
contentType: "application/json"
});
}
This is my controller code.
public IEnumerable<Noor_Users> Get(int user_id)
{
return entityObject.Noor_Users.Where(a => a.user_id == user_id).AsEnumerable();
}
I am not getting any error but I am not able to hit breakpoint in controller. May I know where I am doing wrong? Thank you all.

Passing External API to Angularjs

I'm working with an external API from Shipstation. I can do a GET request to pull the information in just fine into Nodejs, but I can't figure out how I can transfer that data client-side to manipulate within Angular? I've been struggling with this for a few days now and all my googling searching isn't helping out.
server.js
var express = require('express');
var request = require('request');
var app = express();
app.use(express.static('public'));
var Orders = require('./controllers/ordersController');
app.use('/orders', Orders);
app.listen(3000, function() {
console.log('I am live on port 3000');
});
ordersController.js
var request = require('request');
module.export = request({
method: 'GET',
url: 'https://ssapi.shipstation.com/orders/listbytag?orderStatus=awaiting_shipment&tagId=32099&page=1&pageSize=100',
headers: {
'Authorization': 'xxxxxxxxxxx'
}}, function (error, response, body) {
console.log('Status:', response.statusCode);
console.log('Headers:', JSON.stringify(response.headers));
console.log('Response:', body);
});
I figured the best way was to put the GET request in its own "orders" module, export it, and then have angular access that route in an http request (/orders). Sounds good in theory, right?
I appreciate the help in advance! Thanks guys!
I'm assuming that the ShipStation API provides JSON which is easily consumable by Angular.
You can load the JSON into your Angular app like this:
$http.get('/orders:3000', function(data) {
$scope.Orders = data;
console.log($scope.Orders);
});
Add this to your controller, then check the browser's developer console to see the output. From there, you can manipulate the JSON object however you need and display the information in your HTML view.

How can front-end application based on AngularJs consume backend application based on Spring MVC whic is on Tomacat 7 server

I am trying to develop web app using AngularJS as front-end which is separate application from backend Spring MVC on Tomcat 7.How can my front-end consume backend ?
Consider using $http or $resource for consuming your RESTful Webservices.
HTTP Simple GET request example:
$http({
method: 'GET',
url: '/someUrl'
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
})
Resource example:
var User = $resource('/user/:userId', {userId:'#id'});
var user = User.get({userId:123}, function() {
user.abc = true;
user.$save();
})

AngularJS Web Api HttpHandler Image Downloader

My AngularJS application is interacting with ASP.NET Web API to full fill the request which is working fine. it has an use case that allows user to download user specific secure PDF document. I have implemented this functionality as below
AngularJS:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
$scope.DownloadHandler = function (id, downloadURL) {
FileStreamManager.getPdf(id, downloadURL)
.then(function (result) {
// success
window.open(downloadURL + id, '_self', '');
},
function (result) {
$scope.errors = result.data;
});
};
Note : downloadURL is the Controller call like \ImageRepo\Get
Web Api Controller I have this implementation:
HttpResponseMessage response = new HttpResponseMessage();
// DB call to to build the URL
string fileName = "myLocation\Image\doc.pdf";
if (!fileProvider.Exists(fileName))
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
FileStream fileStream = fileProvider.Open(fileName);
response.Content = new StreamContent(fileStream);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = fileName;
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response.Content.Headers.ContentLength = fileProvider.GetLength(fileName);
return response;
Which is working fine. Due to the security issue, i was asked to implement this by using HttpHanlder which is pretty new to me. I have some question on the same.
Should my AngularJS ng-click calls to my .ashx handler directly instead of a Controller URL? Or Should this call route through Controller? How?
I have DB calls to build the image URL and update some the status. Can this be done in Handler itself?
How would i make sure my documents are secured while downloading?
Please help.

Resources