[RESOLVED] line_items expected Hash to be a Array (json) [Creating Order]

Highlighted
Shopify Partner
64 0 15

Hey all.

{"errors":{"line_items":"expected Hash to be a Array"}}

 

Getting the hash error when working with an order array. it's json -- array items don't have keys.So I'm thinking I may be missing a required field somehow.

{
  "order": {
    "shipping_address": {
      "address1": "3 fake Place",
      "city": "fake City",
      "zip": "65540",
      "country": "New Zealand"
    },
    "note_attributes": {
      "name": "order_number",
      "value": "234820"
    },
    "customer": {
      "name": "fake name",
      "note": "452020",
      "email": "fake@example.com"
    },
    "line_items": [
      {
        "title": "testtitle"
      }
    ],
    "email": "fake@example.com",
    "total_price": "32.26"
  }
}

Is there a required field I'm missing inside of line_items?

 

This isn't specified on the documentation at all and I've tried adding IDs linking to products and variants to no avail.

 

Anyone know what might be wrong with my line_items property?

 

Pushed to array for readability sake:

Array
(
    [order] => Array
        (
            [shipping_address] => Array
                (
                    [address1] => 3 fake Place
                    [city] => fake City
                    [zip] => 65540
                    [country] => New Zealand
                )

            [note_attributes] => Array
                (
                    [name] => order_number
                    [value] => 234820
                )

            [customer] => Array
                (
                    [name] => fake name
                    [note] => 452020
                    [email] => fake@example.com
                )

            [line_items] => Array
                (
                    [0] => Array
                        (
                            [title] => testtitle
                        )

                )

            [email] => fake@example.com
            [total_price] => 32.26
        )

)

 

Zyber Developer | https://apps.shopify.com/trademe | https://apps.shopify.com/productfilter | https://apps.shopify.com/splittest
0 Likes
Highlighted
Shopify Expert
4175 29 400

Would help if you explained further what you are trying to do. From your explanation, no one knows if you're doing a GET, PUT or POST, but we can glean maybe you are trying something out with the order endpoint. What are you trying to do? 

A better explanation from you might yield some help. 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Highlighted
Shopify Partner
64 0 15

Ah right. Good point, HunkyBill.

POST request creating an order.

Edit: 

I am using it through a private application (Permissions: http://image.prntscr.com/image/058c3f1805d44583a054c6d854a3d601.png).

Zyber Developer | https://apps.shopify.com/trademe | https://apps.shopify.com/productfilter | https://apps.shopify.com/splittest
0 Likes
Highlighted
Shopify Partner
64 0 15

Bump.

 

Zyber Developer | https://apps.shopify.com/trademe | https://apps.shopify.com/productfilter | https://apps.shopify.com/splittest
0 Likes
Highlighted
Shopify Expert
4175 29 400

Your order is lacking details. For example, if you try and create an order, it has to consist of at least one line item that includes a product ID, variant ID and a quantity. See the docs for examples that work. Build from those. 

It does not help that you are presenting some weirdo PHP code for data. If you want people to examine your data and try and point out the obvious mistakes, use JSON as it represents a data reality much better. 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Highlighted
Shopify Partner
64 0 15

Your order is lacking details. For example, if you try and create an order, it has to consist of at least one line item that includes a product ID, variant ID and a quantity. See the docs for examples that work. Build from those. 

It does not help that you are presenting some weirdo PHP code for data. If you want people to examine your data and try and point out the obvious mistakes, use JSON as it represents a data reality much better. 

Hey HunkyBill.

While I've noticed a majority of your replies seem to draw out some sort of angry response, I'd appreciate if you chose your wording a little better in a professional environment like the primary support area for developers working inside of Shopify.

 

First, the docs do not say in them anywhere about what the minimum required fields listed for line items. 

I explicity mentioned:

This isn't specified on the documentation at all and I've tried adding IDs linking to products and variants to no avail.

This is after I've spent some time reading through the API documetation, as well as testing my theories with direct post calls to try and get a response where I included both variant_id as well as product_id

https://help.shopify.com/api/reference/order 

 

Regarding my "weirdo" php data -- I'm not okay with being called a weirdo in a professional environment as such where I've simply returned an array in an easy to read format. Please also note that my first code example, was a JSON array of what I was sending. It was not pretty-formatted and have corrected this now.

I apologize for my reply being in a public post like this, but I couldn't find any way to private message you at all and find it unfair to simply say nothing. You've been a pillar of the community for a very long time, and deserve a lot of respect for this. I really do appreciate the help you have provided in the past and look forward to having some great conversation and debate about some of the odd pros and cons of the system we both work in.

Zyber Developer | https://apps.shopify.com/trademe | https://apps.shopify.com/productfilter | https://apps.shopify.com/splittest
0 Likes
Highlighted
Shopify Partner
64 0 15

I've added the quantity as another key/value in each line item, as this is indeed something I hadn't thought to try, but still retain the same error.

Another copy of a tested array:

{
  "order": {
    "shipping_address": {
      "address1": "3 fake Place",
      "city": "fake City",
      "zip": "65540",
      "country": "New Zealand"
    },
    "note_attributes": {
      "name": "order_number",
      "value": "234820"
    },
    "customer": {
      "name": "fake name",
      "note": "452020",
      "email": "fake@example.com"
    },
    "line_items": [
      {
        "title": "testtitle",
        "quantity": 1,
        "variant_id": 18899065990,
        "product_id": 5972475206
      }
    ],
    "email": "fake@example.com",
  }
}

Still failing to return successfully..

 

Another tested array with the same error:

{
  "order": {
    "shipping_address": {
      "address1": "3 fake Place",
      "city": "fake City",
      "zip": "65540",
      "country": "New Zealand"
    },
    "note_attributes": {
      "name": "order_number",
      "value": "234820"
    },
    "customer": {
      "name": "fake name",
      "note": "452020",
      "email": "fake@example.com"
    },
    "line_items": [
      {
        "quantity": 1,
        "variant_id": 18899065990
      }
    ],
    "email": "fake@example.com"
  }
}

 

Zyber Developer | https://apps.shopify.com/trademe | https://apps.shopify.com/productfilter | https://apps.shopify.com/splittest
0 Likes
Highlighted
Shopify Partner
64 0 15

And it turns out it was the Guzzle implementation sending the data in a bad format.

Zyber Developer | https://apps.shopify.com/trademe | https://apps.shopify.com/productfilter | https://apps.shopify.com/splittest
1 Like
Highlighted
Tourist
9 0 1

Zac, what was the solution you implemented in the end with Guzzle? I'm facing a similar, if not exactly the same problem.

0 Likes
Highlighted
Tourist
9 0 1

Any update on this..?

0 Likes