I am building an Ionic app using woocommerce API
Below is my woocommerce provider .ts file
import * as WC from 'woocommerce-api';
this.Woocommerce = new WC({
url: "http://myftuplad.com",
consumerKey: "ok_d064f357304e",
consumerSecret: "os_0e59869ac5e08",
wpAPI: true,
version: 'wc/v2'
/*queryStringAuth: true,
verify_ssl: false*/
});
Below is checkout.ts file to place and order
this.WooCommerce.postAsync("orders", orderData.order).then((data) => {
let response = (JSON.parse(data.body));
console.log(response);
})
Below is the error :
code : woocommerce_rest_authentication_error
status : 401
message : Invalid signature - provided signature does not match.
Thanks.
Related
I am building a flutter application that requires oauth 1 authorization for one of the third party services I am using. Because flutter oauth 1 package is restricted I decided to use the oauth 1 package that npm provides. This is the code that is used to access the user generated access token from the site.
I previously used request to make a call to the api endpoint first, to access the token and secondly to use the token recieved to make another call to a different resource endpoint
How can I use axios to make the same request, emphasis on the fact that each request needs a hmac-sha1 signed signature in the header.
Thank you.
consumer: {
key: CONSUMER KEY,
secret: CONSUMER SECRET,
},
signature_method: 'HMAC-SHA1',
hash_function(base_string, key) {
return crypto
.createHmac('sha1', key)
.update(base_string)
.digest('base64')
},
})
const request_data = {
url: 'https://www.instapaper.com/api/1/oauth/access_token/',
method: 'POST',
data: { x_auth_username : USERNAME , x_auth_password : PASSWORD , x_auth_mode : 'client_auth' },
}
request(
{
url: request_data.url,
form: request_data.data,
method: request_data.method,
headers: oauth.toHeader(oauth.authorize(request_data)),
},
function(error, response, body) {
// Process your data here
console.log(error);
console.log(response);
console.log(body);
}
)
Finally found the answer for this link to the issue created on github
https://github.com/axios/axios/issues/2771
I have a service that do post. The service is being hosted in another machine. When I tried to post using Postman, it works fine. Now, when I tried to post using my Angular2 app which is run in another machine I got an error "Response with status: 0 for URL: null." The code in my angular service is as follows:
postQuestions() {
var json = JSON.stringify({
"TestInfo_FK" : "612",
"Resource_FK" : 0,
"QuestionNo" : 22,
"ContentType" : "HTML",
"Content" : "This is the question from Jason",
"NoOptions" : 4,
"OptionLayout" : "Vertical",
"Answer" : "A"
});
var url = 'http://my.service.net/api/ONLINE/Question';
var params = 'json=' + json;
var headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Access-Control-Allow-Origin', '*');
return this._http.post(url, params, {
headers: headers
})
.map(res => res.json());
}
how to solve this issue?
This situation arises when your hosted service is not able to be accessed via cross origin(CORS) .So if u you are accessing Spring Rest service then use #CrossOrigin annotation on service.
OR use
flask-restful to build remote API
from flask_restful.utils import cors
from flask_restful import Api
api = Api(app, decorators=[cors.crossdomain(origin='*')])
I found out what was causing the issue.. Its a server side issue. You need to set the CORS middleware first then the remaining API middlewares.
Please note i am working with Laravel 5.6 + Angular 5
Wrong Code
'api' => [
'throttle:60,1',
'bindings',
\Barryvdh\Cors\HandleCors::class,
],
Currect Code
'api' => [
\Barryvdh\Cors\HandleCors::class,
'throttle:60,1',
'bindings'
],
hi I am new to elgg REST API.
I want to login and add post to wire for that I have method=wire.save_post
I learned from Google that api auth and user auth must be given in request header how?
I am doing a ajax for adding post to wire :
$("#post_text").submit(function() {
$.ajax({
type:"POST",
url:"http://elgg.amusedcloud.com/services/api/rest/json/?",
data:{ method:'wire.save_post', text : text_val, access : 'public', wireMethod : 'site', username : uname },
dataType:"json",
success: function(data) {
}
});
});
Normally an ajax call to the elgg webservice you are referring to should look something like this. Note that the api_key and auth_token are part of the request URL.
$("#post_text").submit(function() {
$.ajax({
type:"POST",
url:"http://elgg.amusedcloud.com/services/api/rest/json/?method=wire.save_post&api_key=1140321cb56c71710c38feefdf72bc462938f59f&auth_token=df123dfgg455666",
data:{
text : text_val,
access : 'public',
wireMethod : 'site',
username : uname
},
dataType:"json",
success: function(data) {
}
});
});
You didn't mention this but, when you say
... I learned from Google that api auth and user auth must be given in request header
is this in the context of using OAuth as an authentication mechanism? In which case, you will have to use the HTTP header Authorization to send the hash and signature. The above call would then be like this.
$("#post_text").submit(function() {
$.ajax({
type:"POST",
url:"http://elgg.amusedcloud.com/services/api/rest/json/?method=wire.save_post&auth_token=df123dfgg455666",
data:{
text : text_val,
access : 'public',
wireMethod : 'site',
username : uname
},
beforeSend: function(xhr){
xhr.setRequestHeader('X-Test-Header', 'test-value');
},
dataType:"json",
success: function(data) {
}
});
});
Note the changes in the url and addition of beforeSend property to the ajax object.
References:
http://docs.elgg.org/wiki/OAuth
http://api.jquery.com/jQuery.ajax/
I'm trying to call Paypay from Parse.com Cloud Code.
I'm getting the following error on Firebug:
{"code":141,"error":"Uncaught Error: Can't form encode an Object"}
I'm using the example straight out of the Paypal example code. My cURL snippet works fine. When I try it with Parse Cloud Code, I get the above error. Here's my Parse Cloud Code:
Parse.Cloud.httpRequest({
url: 'https://svcs.sandbox.paypal.com/AdaptiveAccounts/CreateAccount',
method: 'POST',
headers: { "X-PAYPAL-SECURITY-USERID": "XXXXXXXXX",
"X-PAYPAL-SECURITY-PASSWORD": "XXXXXXXX",
"X-PAYPAL-SECURITY-SIGNATURE": "XXXXXXXXXXXXX",
"X-PAYPAL-REQUEST-DATA-FORMAT": "JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT": "JSON",
"X-PAYPAL-APPLICATION-ID": "APP-NNNNNNNNNNN",
"X-PAYPAL-DEVICE-IPADDRESS": "<my_actual_IP_address>",
"X-PAYPAL-SANDBOX-EMAIL-ADDRESS": "XXXXXXXXXXXXXX"
},
body: { "sandboxEmailAddress":"xyz#me.com",
"accountType":"PERSONAL",
"name": {"firstName":"Lenny","lastName":"Riceman"},
"address":{"line1":"123 Main St", "city":"Austin", "state":"TX", "postalCode":"78759", "countryCode":"US"},
"citizenshipCountryCode":"US",
"contactPhoneNumber":"512-555-5555",
"dateOfBirth":"1968-01-01Z",
"createAccountWebOptions": {"returnUrl":"http://www.example.com/success.html"},
"currencyCode":"USD",
"emailAddress":"lr12345#example.com",
"preferredLanguageCode":"en_US",
"registrationType":"Web",
"requestEnvelope": {"errorLanguage":"en_US"}
},
success: function() {
response.success("Paypal made!");
},
error: function(err) {
response.error(err);
console.error('Request failed with response code ' );
}
Update: May 9, 2014
OK. I don't know if this will help, but here is the exact code that is working for me.
Parse.Cloud.httpRequest({
method: 'POST',
url: 'https://api-3t.paypal.com/nvp -d',
body: {
USER: 'sr1.me.com',
PWD: 'LEgfdgfsdg8',
SIGNATURE: 'gfdgh',
METHOD: 'MassPay',
VERSION: '93',
RECEIVERTYPE: 'EmailAddress',
CURRENCYCODE: 'USD',
EMAILSUBJECT: 'You have a new payment from ',
L_EMAIL0: sellerEmail,
L_AMT0: paypalPmt,
L_NOTE0: paypalNote,
L_UNIQUEID0: bumpSoldTrans
}
Parse.Cloud.define("getUserPayPalToken", function(request, response){
//Setup private varaibles for paypal request to user
var receivers = new Array();
//Setup Receivers for Paypal when payment begins
//Primary Receiver --- Created first array for primary receiver
receivers[0] = new Array();
receivers[0][0] = {'amount':'1.00', 'email':'email-test-1#gmail.com'};
//receivers[0][0] = {'email':request.params.email};
//Secondary Receiver --- Created second array for secondary receiver
receivers[1] = new Array();
receivers[1][0] = {'amount':'2.00', 'email':'test-email#gmail.com'};
var receiverListParams = [{'receiver': receiverParams}];
var receiverParams = JSON.stringify(receiverListParams);
//Set Parse to call PayPal Adaptive Payments
Parse.Cloud.httpRequest({
method:'POST',
url: 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay',
headers: {
//Setting PayPal request headers
'X-PAYPAL-SECURITY-USERID' : 'xxxxx',
'X-PAYPAL-SECURITY-PASSWORD' : 'xxxxx',
'X-PAYPAL-SECURITY-SIGNATURE' : 'xxxxx',
// Global Sandbox Application ID
'X-PAYPAL-APPLICATION-ID ' : 'APP-80W284485P519543T',
// Input and output formats
'X-PAYPAL-REQUEST-DATA-FORMAT' : 'JSON',
'X-PAYPAL-RESPONSE-DATA-FORMAT' : 'JSON'
},
body:{
'actionType' : 'PAY',
'cancelUrl' : 'http://www.cancel.com',
'currencyCode' : 'USD',
'returnUrl' : 'http://www.return.com',
'requestEnvelope' : {"errorLanguage":"en_US"},
'receiverList' : receiverParams
},
success: function(httpResponse) {
console.log(httpResponse.text);
response.success(httpResponse.text);
},
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
response.error(httpResponse.text);
}
});
});
I'm trying to get XML response from a secure https URL using Jquery AJAX call...
I'm getting the following error. Can anyone help me with the issue?
Unauthorized user
Here is my code
$.ajax({
type : "GET",
url : url + "?" + params,
error : function(jqxhr, status, error)
{
alert(status +"....."+error);
},
success : function(data, textStatus, jqxhr) {
var xmlDoc = jqxhr.responseText;
alert(xmlDoc);
}
});
Definitely need more details, but if you're sending a request to a secure url, you likely need to pass some kind of value to show you're logged in or some-such, like a cookie value. To pass a value, you may need to use the headers option:
$.ajax({
type : "GET",
url : url + "?" + params,
headers : {"COOKIE", "userID=h3j5o273h4"},
error : function(jqxhr, status, error)
{
alert(status +"....."+error);
},
success : function(data, textStatus, jqxhr) {
var xmlDoc = jqxhr.responseText;
alert(xmlDoc);
}
});