Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

POST request with Array

Hi Sheldon.

If you want to send jQuery.ajax request through the Appery.io proxy you can use the following code:
pre$.ajax({
type: "GET",
url: "https://appery.io/app/rest/tunnel",
contentType: 'application/json',
headers: {
//Url to your request
"appery-proxy-url": "https://api.appery.io/rest/1/db/collections/dogs",

Code: Select all

     "appery-key": "13939800931xx", 
     "appery-rest": "45c2ad18-d6c7-460d-96ed-d945d9e8d5xx", 
     "appery-transformation": "checkTunnel", 
 }, 
 //Here is your request parameters 
 data: { 
     "paramName": "paramValue" 
 }, 
 success: function(data) { 
     //Note: ajax request is async. That's why you can't to return the value for parent function and should invoke some function instead. 
     console.log(data); 
 } 

});/pre

But there is one more way to do this:

  1. Create REST service;

  2. Fill settings with those url, parameters, etc you need;

  3. Paste proxy id into the "Use Appery.io Proxy"

  4. Invoke Service via javascript code with parameters you need.

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

POST request with Array

I think i like you second option. But perhaps you can answer this before I do all that. Because im pulling this json file URL from the response and mapping it to a Grid as array, How can i be sure to always pull the correct "value" per line in the grid layout.

Example:
Line 1 = 1.json
Line 2 = 2.json
Line 3 = 3.json

I would now need to do a GET Request for Line 1 - 3 each. and output back the response value in that same Line.

Here is a example of the json file Response data that i'm mapping. Notice the Shipping_address is another json file. So essentially i need the actual shipping_address information to show in my Grid fields. - !!!And this is an Array!!!

pre
code
First Get Request Json file:

{
"id": 100,
"customer_id": 10,
"date_created": "Wed, 14 Nov 2012 19:26:23 +0000",
"date_modified": "Wed, 14 Nov 2012 19:26:23 +0000",
"date_shipped": "",
"status_id": 11,
"status": "Awaiting Fulfillment",
"subtotal_ex_tax": "79.0000",
"subtotal_inc_tax": "79.0000",
"subtotal_tax": "0.0000",
"base_shipping_cost": "0.0000",
"shipping_cost_ex_tax": "0.0000",
"shipping_cost_inc_tax": "0.0000",
"shipping_cost_tax": "0.0000",
"shipping_cost_tax_class_id": 2,
"base_handling_cost": "0.0000",
"handling_cost_ex_tax": "0.0000",
"handling_cost_inc_tax": "0.0000",
"handling_cost_tax": "0.0000",
"handling_cost_tax_class_id": 2,
"base_wrapping_cost": "0.0000",
"wrapping_cost_ex_tax": "0.0000",
"wrapping_cost_inc_tax": "0.0000",
"wrapping_cost_tax": "0.0000",
"wrapping_cost_tax_class_id": 3,
"total_ex_tax": "79.0000",
"total_inc_tax": "79.0000",
"total_tax": "0.0000",
"items_total": 1,
"items_shipped": 0,
"payment_method": "cash",
"payment_provider_id": null,
"payment_status": "",
"refunded_amount": "0.0000",
"order_is_digital": false,
"store_credit_amount": "0.0000",
"gift_certificate_amount": "0.0000",
"ip_address": "50.58.18.2",
"geoip_country": "",
"geoip_country_iso2": "",
"currency_id": 1,
"currency_code": "USD",
"currency_exchange_rate": "1.0000000000",
"default_currency_id": 1,
"default_currency_code": "USD",
"staff_notes": "",
"customer_message": "",
"discount_amount": "0.0000",
"coupon_discount": "0.0000",
"shipping_address_count": 1,
"is_deleted": false,
"billing_address": {
"first_name": "Trisha",
"last_name": "McLaughlin",
"company": "",
"street_1": "12345 W Anderson Ln",
"street_2": "",
"city": "Austin",
"state": "Texas",
"zip": "78757",
"country": "United States",
"country_iso2": "US",
"phone": "",
"email": "elsie@example.com"
},
"products": {
"url": "https://store-bwvr466.mybigcommerce.com/api/v2/orders/100/products.json",
"resource": "/orders/100/products"
},
"shipping_addresses": {
"url": "https://store-bwvr466.mybigcommerce.com/api/v2/orders/100/shippingaddresses.json",
"resource": "/orders/100/shippingaddresses"
},
"coupons": {
"url": "https://store-bwvr466.mybigcommerce.com/api/v2/orders/100/coupons.json",
"resource": "/orders/100/coupons"
}
}

/code
/pre

Example of the shipping json file: - I need parameters like street_1, city, state, etc..
precode
{
"id": 15,
"order_id": 114,
"first_name": "Julie",
"last_name": "Bishop",
"company": "Yamia",
"street_1": "988 Comanche Circle",
"street_2": "",
"city": "Cypress",
"zip": "77426-2265",
"country": "United States",
"country_iso2": "US",
"state": "Wyoming",
"email": "",
"phone": "5-(248)906-2014",
"items_total": 1,
"items_shipped": 0,
"shipping_method": "None",
"base_cost": "0.0000",
"cost_ex_tax": "0.0000",
"cost_inc_tax": "0.0000",
"cost_tax": "0.0000",
"cost_tax_class_id": 2,
"base_handling_cost": "0.0000",
"handling_cost_ex_tax": "0.0000",
"handling_cost_inc_tax": "0.0000",
"handling_cost_tax": "0.0000",
"handling_cost_tax_class_id": 2,
"shipping_zone_id": 1,
"shipping_zone_name": "Default Zone"
}
/code/pre

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

POST request with Array

As I understand your correctly you want to do next things:

1 Get some service response data.
2 Supplement the data by data obtained from another requests.
3 Map ready(after 1-2 steps) data to the list.

Because you use a async logic and it should to be synced. There is another way how to do this.

1 Create custom security context service: http://docs.appery.io/documentation/g...

2 Use next code to wrap answer and make custom logic(including server requests).

pre

Appery.MySecurityGeneric = Appery.createClass(SecurityContext, {

Code: Select all

 invoke: function(service, settings) { 
     var oldSuccess = settings.success; 

     var onSuccess = function(value, other){ 
         var onNeedToComplete = function(){ 
             oldSuccess.call(this, value, other); 
         }; 

         for(var i in value){ 
             //Set counterValue for each response item. This is sync way to change data. 
             value[i].shipping_addresses_ready = [{..}, {...}]; 

             //This you need to invoke your other services or ajax request. And sync it. 
             //After all data would be ready you have to run "onNeedToComplete();" function. 
         } 

         //You should call this function when all your changes competed. So if you use async js - you should call  
         it when all transformations are ready. 
         onNeedToComplete(); 
     }; 

     settings.success = onSuccess; 
     Appery.MySecurityGeneric.$super.invoke.call(this, service, settings); 
 } 

});

/pre
where MySecurityGeneric - your service name.

After you will do these steps you can use this generic service to create your layout without async problems.

Return to “Issues”