reggi / whiplash

Whiplash API Library for Node.js
1 stars 1 forks source link

Invalid data sent to Whiplash Server #2

Closed johnnyman727 closed 10 years ago

johnnyman727 commented 10 years ago

I'm testing out this module with Whiplash's servers. I'm trying to do an order creation using the JSON from the example order creation on the Whiplash API Documentation page.

My code looks like:

var Whiplash = new require('whiplash');
var whiplash = new Whiplash();

var realJSON = {
    "req_ship_method_text": "UPS Ground",
    "shipping_address_1": "123 Some Street",
    "shipping_state": "CA",
    "ship_notes": "Deliver to hot tub in back",
    "shipping_company": "Awesome, Inc",
    "req_ship_method_price": "10.50",
    "shipping_country": "US",
    "shipping_zip": "90210",
    "originator_id": "123456",
    "shipping_city": "Beverly Hills",
    "shipping_name": "Joe Smith",
    "insure": true,
    "require_signature": true,
    "insurance_value": "500.00",
    "order_items": [
        {
            "price": "23.12",
            "quantity": 20,
            "packaging": false,
            "originator_id": "654321",
            "description": null,
            "item_id": 136015
        }
    ],
    "gift": false,
    "shipping_phone": "123-456-7890",
    "email": "joe@awesomeinc.com",
    "shipping_address_2": "Apt2",
    "method" : "POST",
    "url":"orders/",
    "Content-Type" : "application/json"
}

whiplash.request(realJSON, 
    function (err, body) {
        if (err) throw err;
        console.log('Response body:', body);
    });
};

In the request, all of the fields are falsy except the Date fields, id, and days_in_transit:

{ 
billed: false,
  created_at: '2014-08-14T20:12:27-04:00',
  days_in_transit: 1,
  email: null,
  gift: false,
  id: 46238,
  insure: false,
  originator_notified: false,
  pack_fee_actual: null,
  packaging_fee_actual: null,
  pick_fee_actual: null,
  public_note: null,
  req_ship_method_price: '0.0',
  req_ship_method_text: null,
  require_signature: false,
  ship_3rdparty_cost: '0.0',
  ship_actual_cost: null,
  ship_method: null,
  ship_notes: null,
  shipped_on: null,
  shipping_address_1: null,
  shipping_address_2: null,
  shipping_city: null,
  shipping_company: null,
  shipping_country: null,
  shipping_country_iso2: null,
  shipping_name: null,
  shipping_phone: null,
  shipping_state: null,
  shipping_zip: '',
  status: 100,
  total_fee_actual: null,
  tracking_sent: false,
  updated_at: '2014-08-14T20:12:27-04:00',
  tracking: [],
  originator_id: null,
  provider: 'api',
  monetary_value: 0,
  insurance_value: 0,
  order_items: [] 
}

Additionally, when I check the order status on the Whiplash Dashboard, the order couldn't be created because the address couldn't be verified. I've also tried sending the POST with a legitimate address with the same results. I think it's because the data is being corrupted somehow before it hits the server.

reggi commented 10 years ago

You gotta remove these properties from realJSON.

    "method" : "POST",
    "url":"orders/",
    "Content-Type" : "application/json"

And here's the request:

whiplash.request({
  "method": "POST",
  "url": "orders",
  "body": realJSON
}, function(err, body, status) {
  if (err) throw err;
  console.log('Response body:', body);
  console.log(status)
});

I was getting { error: 'record could not be found' }

But that's because the item_id within order_items wasn't a real product. I just created an order using my actual key / actual product and it worked.

johnnyman727 commented 10 years ago

Great, thanks @reggi! I'll give this a try today.