Sheldon Young
Posts: 0
Joined: Fri Feb 07, 2014 5:34 am

POST request with Array

Guys any lead way on this issue.. I see that the POST 411 error has been fixed, but i'm still in need of a way to POST array from grid column Layout. I to know the proper way to do this in appery.. I will need to show some progress on this app by Friday and this is the only holdup.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

POST request with Array

Hello! Sorry for delay. Working on it.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

POST request with Array

You can't do this with mapping only, you would need to add custom JS in mapping and return arrayprevar arr = [];
$('[name="labelName"]').not('[_tmpl=true]').each(function(){
arr.push($(this).text());
})
return arr;/pre

Sheldon Young
Posts: 0
Joined: Fri Feb 07, 2014 5:34 am

POST request with Array

Thanks Maryna, I can see where this would slit the data. But when i try to POST im getting a 500 error back from the API and this is what the they had to say about it -

"Due to a recent behavioral change in our API, a number of API responses that were incorrectly returning a HTTP 401 error are now returning a HTTP 500 error.
This issue may impact stores with a high volume of simultaneous API requests. These stores may receive a 500 error as part of the defenses we have in place to prevent a single store adversely impacting other stores.
Our recommendation is to spread API requests across the full 1 hour rolling window using the rate limit information returned to you in API responses, and minimize the number of simultaneous API requests per store."

Now the array i posted was only Three data.. But I'm not sure is that's the issue here. Because this is the layout of my Request Payload being sent:
precode
'requestMapping': [{
'PATH': ['Auth_user'],
'TYPE': 'STRING',
'ID': 'local_storage',
'ATTR': 'bc_USER'
}, {
'PATH': ['Auth_url'],
'TYPE': 'STRING',
'ID': 'local_storage',
'ATTR': 'bc_API_URL'
}, {
'PATH': ['Auth_Token'],
'TYPE': 'STRING',
'ID': 'local_storage',
'ATTR': 'bc_TOKEN'
}, {
'PATH': ['name'],
'TYPE': 'STRING',
'ID': 'dbListProdName_val_227',
'ATTR': '@',
'TRANSFORMATION': function(value) {
var arr = [];
$('[name="dbListProdName_val_227"]').not('[tmpl=true]').each(function() {
arr.push($(this).text());
});
return arr;
}
}, {
'PATH': ['type'],
'TYPE': 'STRING',
'ATTR': 'physical'
}, {
'PATH': ['price'],
'TYPE': 'STRING',
'ID': 'DBListItem_MSRP_val_231',
'ATTR': '@',
'TRANSFORMATION': function(value) {
var arr = [];
$('[name="DBListItem_MSRP_val_231"]').not('[tmpl=true]').each(function() {
arr.push($(this).text());
});
return arr;
}
}, {
'PATH': ['is_visible'],
'TYPE': 'STRING',
'ATTR': 'true'
}, {
'PATH': ['weight'],
'TYPE': 'STRING',
'ID': 'DBListItem_QtyInStock_val_233',
'ATTR': '@',
'TRANSFORMATION': function(value) {
var arr = [];
$('[name="DBListItem_QtyInStock_val_233"]').not('[_tmpl=true]').each(function() {
arr.push($(this).text());
});
return arr;
}
}, {
'PATH': ['availability'],
'TYPE': 'STRING',
'ATTR': 'available'
}, {
'PATH': ['categories', '.'],
'TYPE': 'STRING',
'ID': 'BCCategory_Select',
'ATTR': 'value'
}, {
'PATH': ['appery-proxy-url'],
'HEADER': true,
'ATTR': 'https://{Auth_user}:{Auth_Token}@{Auth_url}products.json'
}, {
'PATH': ['appery-transformation'],
'HEADER': true,
'ATTR': 'checkTunnel'
}, {
'PATH': ['appery-key'],
'HEADER': true,
'ATTR': '1392381800170'
}, {
'PATH': ['appery-rest'],
'HEADER': true,
'ATTR': 'f25a8d87-0a7f-4eed-b110-12952dc47bda'
}]
/code/pre
I don't think this is the way it should be setup, am i wrong?

Do you think there is a way to POST 3 different request(or as many as the array holds). to the API? for example: After using method above to split the values into array, can we send one value at a time until it loop through the array of value?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

POST request with Array

Hi Sheldon,

[quote:]Do you think there is a way to POST 3 different request(or as many as the array holds)[/quote]Sure. In JS code go through all the data and invoke service as many times as you need: http://docs.appery.io/documentation/r...

Sheldon Young
Posts: 0
Joined: Fri Feb 07, 2014 5:34 am

POST request with Array

Thanks katya ive done that and ur works great. Now there is just one more step in this process I need your help figuring out. Ok when I POST this request, I rely on response data to run my next function. The issue I'm having now is that one parameter from the response is a url to another json file. I Need to capture that url then send a Get request and input the response from this GET request as the value in said field. Now what I have done was write an Ajax call in the mapping js to GET the new data, but I'm having the cross-domain issue. So my question is this, is there a way for me to use the Appery Proxy in my Ajax call? If so, how?..

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

POST request with Array

Hello! Sure, please take a look here http://docs.appery.io/documentation/s...

Sheldon Young
Posts: 0
Joined: Fri Feb 07, 2014 5:34 am

POST request with Array

Hi maryna, I follow the document on Proxy API, to send request from an ajax written in my mapping JS. this is what happens:

My code in the response mapping JS field, where i received a json url that i must make a call to:

precode
var URL = value;
Auth = getAuth();
$.ajax({
type: "GET",
contentType: 'application/json',
Authorization: Auth,
appery-rest: "9a3bee38-30ab-48b1-b68e-1a01b99df8e7",
appery-proxy-url: URL,
appery-transformation: "checkTunnel",
success: function(data) {
result = JSON.parse(data);
alert(result.state);
// return result.state;
}
});
/code/pre

What appery put out in the actual .js file when testing:

precode
var URL = value;
Auth = getAuth();
$.ajax({
type: "GET",
contentType: 'application/json',
Authorization: Auth,
appery - rest: '9a3bee38-30ab-48b1-b68e-1a01b99df8e7',
appery - proxy - url: URL,
appery - transformation: 'checkTunnel',
success: function(data) {
result = JSON.parse(data);
alert(result.state);
// return result.state;
}
});
/code/pre
As you can see the spaces in the Proxy header parameters. How would i handle this? or is it a bug on your end?

Nikita
Posts: 0
Joined: Fri Feb 28, 2014 4:02 pm

POST request with Array

Hello.
Unfortunately, this is a appery's bug. Workaround should be following: add code to custom JS as function, and in service's mapping just call this function.

Sheldon Young
Posts: 0
Joined: Fri Feb 07, 2014 5:34 am

POST request with Array

Ok make sense Nikita...

But for the life of me I can't figure out the correct way to write an Ajax Request call using Appery Proxy. Here is what i have, please let me know if im going about this the correct way.

pre
code
$.ajax({
type: "GET",
url: "https://appery.io/app/rest/tunnel",
contentType: 'application/json',
headers: {
'Authorization' : THE AUTH I NEED,
'appery-rest' : '12345678-2222-2D4D-DdDd-000000000',
'appery-proxy-url' : 'https://URL/somefile.json',
'appery-transformation' : 'checkTunnel',
},
success: function(data) {
result = JSON.parse(data);
return result.state;
}
});
/code
/pre

now am i missing anything? or there a correct way of using the proxy

Return to “Issues”