Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shipstation api gives me an 400 error when posting an order #8

Closed
redragonx opened this issue Aug 13, 2017 · 2 comments
Closed

Shipstation api gives me an 400 error when posting an order #8

redragonx opened this issue Aug 13, 2017 · 2 comments

Comments

@redragonx
Copy link

Hi there,

I'm trying to create a order and make a post request. However, I get this error when doing so:

"{"Message":"The request is invalid.","ModelState":{"apiOrder":["Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'SS.OpenApi.Models.Orders.Order' because the type requires a JSON object (e.g. {\"name\":\"value\"}) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON object (e.g. {\"name\":\"value\"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\r\nPath '', line 1, position 1."]}}"

I tried your example order and still got the same error.

Here's my relevant code.

    function newShipStationOrder($reqArray) {


        $order = new \LaravelShipStation\Models\Order();

        $order->orderNumber =  $reqArray['content']['invoiceNumber'];
        $order->orderDate = $reqArray['content']['creationDate'];
        $order->orderStatus = $reqArray['content']['status'];
        $order->amountPaid = $reqArray['content']['grandTotal'];
        $order->taxAmount = $reqArray['content']['taxesTotal'];
        $order->shippingAmount = $reqArray['content']['shippingFees'];

        if ($order->shippingAmount == null) {
            $order->shippingAmount = 0;
        }

        $order->internalNotes = $reqArray['content']['notes'];

        if ($order->shippingAmount == null) {
            $order->internalNotes = "N/A";
        }

        $tempAddressArray = $this->createPhysicalAddresses($reqArray['content']);
        $order->billTo = $tempAddressArray['billingAddress'];
        $order->shipTo = $tempAddressArray['shippingAddress'];

        $jsonOrderItemArray = $reqArray['content']['items'];

        foreach ($jsonOrderItemArray as $item) {
            $newOrderItem = new \LaravelShipStation\Models\OrderItem();

            $newOrderItem->lineItemKey = $item['id'];
            $newOrderItem->sku = $item['id'];
            $newOrderItem->name = $item['name'];
            $newOrderItem->quantity = $item['quantity'];
            $newOrderItem->unitPrice  = $item['unitPrice'];

            $newOrderItem->weight = $item['weight'];
            $newOrderItem->warehouseLocation = "N/A";

            $order->items[] = $newOrderItem;
        }

        return $order;
    }

    private function createPhysicalAddresses($data)
    {
        $shippingAddress = new \LaravelShipStation\Models\Address();
        $billingAddress = new \LaravelShipStation\Models\Address();

        $billingAddress->name = $data['billingAddressName'];
        $billingAddress->street1 = $data['billingAddressAddress1'];
        $billingAddress->street2 = $data['billingAddressAddress2'];
        $billingAddress->city = $data['billingAddressCity'];
        $billingAddress->state = $data['billingAddressProvince'];
        $billingAddress->postalCode = $data['billingAddressPostalCode'];
        $billingAddress->country = $data['billingAddressCountry'];
        $billingAddress->phone = $data['billingAddressPhone'];

        if ($data['shippingAddressSameAsBilling'] == true) {

            $shippingAddress = $billingAddress;
        } else {
            $shippingAddress->name = $data['shippingAddressName'];
            $shippingAddress->street1 = $data['shippingAddressAddress1'];
            $shippingAddress->street2 = $data['shippingAddressAddress2'];
            $shippingAddress->city = $data['shippingAddressCity'];
            $shippingAddress->state = $data['shippingAddressProvince'];
            $shippingAddress->postalCode = $data['shippingAddressPostalCode'];
            $shippingAddress->country = $data['shippingAddressCountry'];
            $shippingAddress->phone = $data['shippingAddressPhone'];
        }

        $addressArray['billingAddress'] = $billingAddress;
        $addressArray['shippingAddress'] = $shippingAddress;

        return $addressArray;
    }

Here is the order object.

Order {#152
  +orderNumber: "SNIP-1019"
  +orderKey: null
  +orderDate: "2017-08-12T05:37:41Z"
  +paymentDate: null
  +shipByDate: null
  +orderStatus: "Processed"
  +customerUsername: null
  +customerEmail: null
  +billTo: Address {#167
    +name: "dev1"
    +company: null
    +street1: "r4weghtjrt"
    +street2: null
    +street3: null
    +city: "ddd"
    +state: "AL"
    +postalCode: "111111"
    +country: "US"
    +phone: "7209998888"
    +residential: null
  }
  +shipTo: Address {#167}
  +items: array:3 [
    0 => OrderItem {#157
      +lineItemKey: "90397737-0d97-4863-bdae-bda267dce34e"
      +sku: "90397737-0d97-4863-bdae-bda267dce34e"
      +name: "bvlah1"
      +imageUrl: null
      +weight: null
      +quantity: 1
      +unitPrice: 111111111
      +taxAmount: null
      +shippingAmount: null
      +warehouseLocation: "N/A"
      +options: null
      +productId: null
      +fulfillmentSku: null
      +adjustment: false
      +upc: null
    }
    1 => OrderItem {#168
      +lineItemKey: "ad39db8f-23ee-47b6-8a5b-578ae213c72d"
      +sku: "ad39db8f-23ee-47b6-8a5b-578ae213c72d"
      +name: "Majora's mask"
      +imageUrl: null
      +weight: null
      +quantity: 1
      +unitPrice: 9000
      +taxAmount: null
      +shippingAmount: null
      +warehouseLocation: "N/A"
      +options: null
      +productId: null
      +fulfillmentSku: null
      +adjustment: false
      +upc: null
    }
    2 => OrderItem {#169
      +lineItemKey: "d094638e-f5ed-4de0-b9d3-db508a618d17"
      +sku: "d094638e-f5ed-4de0-b9d3-db508a618d17"
      +name: "Ocarina"
      +imageUrl: null
      +weight: null
      +quantity: 1
      +unitPrice: 7500
      +taxAmount: null
      +shippingAmount: null
      +warehouseLocation: "N/A"
      +options: null
      +productId: null
      +fulfillmentSku: null
      +adjustment: false
      +upc: null
    }
  ]
  +amountPaid: 111127611
  +taxAmount: 0
  +shippingAmount: 0
  +customerNotes: null
  +internalNotes: "N/A"
  +gift: null
  +giftMessage: null
  +paymentMethod: null
  +requestedShippingService: null
  +carrierCode: null
  +serviceCode: null
  +packageCode: null
  +confirmation: null
  +shipDate: null
  +holdUntilDate: null
  +weight: null
  +dimensions: null
  +insuranceOptions: null
  +internationalOptions: null
  +advancedOptions: null
  +tagIds: null
}

Any ideas?

@redragonx
Copy link
Author

redragonx commented Aug 13, 2017

After reverse engineering the Guzzle post response, it appears that the shipstation api does not support json arrays anymore(?)

var_dump($this->shipStation->orders->post([$finalOrder], 'createorder')); // does not work
var_dump($this->shipStation->orders->post($finalOrder, 'createorder')); // works fine

I have no idea if things changed or not regarding the shipstation api. It's my first time using it.

@joecampo
Copy link
Owner

Yeah, you're correct. If you look at the test it doesn't pass an array & just the object for the single order. I'll fix the docs. I'm going to close this, let me know if you need anything else!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants