Shopify Orders Api Error

Matt83
Shopify Partner
8 0 5

Hello All,

Having trouble creating an order for an existing customer through the Shopify Api.

 

Using Postman I am sending a POST request to: {store with auth}.myshopify.com/admin/orders.json

My JSON formatted request is this:

{
  "order": {
    "line_items": [
      {
        "product_id": 633636847661,
        "quantity": 1
      }
    ],
    "customer": {
      "id": 59850135966
    }
  }
}

This seems to be in line with what the API docs have however I am receiving back this error: 

{
    "errors": {
        "order": [
            "money field cannot be nil"
        ]
    }
}

Any ideas on what could be causing this issue? There is no mention of a money field in the Orders API Docs.

 

Even while sending the standard "Create a simple order with only a product variant ID" from the Api docs I still get the same error.

{
  "order": {
    "line_items": [
      {
        "product_id": 633636847661,
        "quantity": 1
      }
    ]
  }
}

 

Replies 15 (15)

smartywak
Shopify Partner
7 0 0

It looks like you'd have to either load existing product data to confirm whether that product has any money attached to it.

Nick_Atkinson
Pathfinder
83 1 35

Hi Matt,

I don't get an error using the same method, check that the variant actually exists because when I removed the product and tried to create the order I got back the same error but when the product was there I didn't get any error and instead of "product_id" try using the variant ID.

Nick_Atkinson
Pathfinder
83 1 35

Here's the response with the product removed

Simon43
Visitor
2 0 0

We've seen the same message several times over the last few days, and I was about to post a question about it when I saw this one. I'm not certain if the product is missing in our case because our error logs didn't include the original request. In any case, it's a confusing message. Is this something that Shopify have changed recently?

Nick_Atkinson
Pathfinder
83 1 35

Hi Simon,

I don't generally work with creating orders, rather gathering them and sending the data to suppliers. However, I don't believe an order can be created with just the product_id, instead the variant_id can be used as noted here in the documentation. I know the error message isn't very clear but to my assumption this means that the price of the product which is tied to the variant_id cannot be null and cannot be read with just the product_id. The three examples below show the JSON sent using just the product_id and using both product_id and variant_id. Using just the product_id will fail with that money field message just like it would if the variant/product did not exist any longer.

 

Returns "money field cannot be nil"

{
  "order": {
    "line_items": [
      {
        "product_id": 528267411510,
        "quantity": 1
      }
    ]
  }
}

 

Both examples below return a created order

Example 1

{
  "order": {
    "line_items": [
      {
        "product_id": 528267411510,
        "variant_id": 6986261266486,
        "quantity": 1
      }
    ]
  }
}

Example 2 

{
  "order": {
    "line_items": [
      {
        "variant_id": 6986261266486,
        "quantity": 1
      }
    ]
  }
}

 

Simon43
Visitor
2 0 0

Makes sense - thanks. What threw me was the term "money field", when actually it appears to be referring to price. Maybe "price" is a SQL Server "money" field type behind the scenes?

Matt83
Shopify Partner
8 0 5

Thanks Nick, this solution worked! Even if a product doesn't have variants, the API still requires that you use the variant.id. 

 

nerry
Visitor
3 0 0

Facing the same "money field cannot be nil" error here, even when I include a valid variant ID which has available inventory in my request like so:

 

{"order": {"line_items": [{"variant_id": 16088940052554, "quantity": 1, "product_id": 59139}], "customer": {"first_name": "***", "last_name": "***", "email": "***@gmail.com"}, "email": "***@gmail.com", "shipping_address": {"first_name": "***", "last_name": "***", "address1": "test order", "city": "SFO", "province": null, "zip": 94920, "country": "USA"}}}

 

What does this error mean?  Why is there no documentation?

 

thank you

Alex
Shopify Staff
1561 81 341

Thanks for the reports, everyone. I've made an issue to track internally with the interest of making this error clearer to API consumers. The issue that you need to be concerned with is the invalid (or not provided) variant_id, and the error message should reflect as much.

 

I'll update this thread when this is resolved.

Alex | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

chewax
Visitor
1 0 0

Hi there!

Im getting a similar error. For what is looks like, shopify isnt finding the product variant using the variant_id provided. However i made sure that product variant id is correct.

Any ideas on why this might be happening?

Thanks!

AFerrara
Shopify Partner
12 1 6

For anyone that finds this like I did, and it did not solve your issue, I hope this does...I encountered this same issue but it had nothing to do with whether or not I supplied a variant_id.  In my case I was trying to create an order and in my line_items I was only sending in the title, sku, and quantity.  So, by not sending in a variant_id Shopify had nothing to lookup, and therefore couldn't pull the price which is the required money field it was complaining about.  So i add the price field to the line_items being sent in the JSON and the order was created successfully.  Hope this helps.

jvantroyen
Tourist
5 0 2

If I GET the list of orders, that works, but if I POST the most basic of create order messages

 

 

{
    "order": {
        "line_items": [
            {
                "variant_id": 31779911532627,
                "quantity": 1
            }
        ]
    }
}

 

 

the response I get is very confusing: I just get a 200 OK with the below HTML:

 

<html>
<body>
	<noscript>
		<a href="https://accounts.shopify.com/oauth/authorize?client_id=REMOVED">Continue</a>
	</noscript>
	<script type="text/javascript" defer>
		window.location = "https:\/\/accounts.shopify.com\/oauth\/authorize?client_id=REMOVED";
	</script>
</body>
</html>

 

AFerrara
Shopify Partner
12 1 6

You are not posting enough data for a valid order.  You will need to take a look at the API documentation for orders.json and you will see other required fields in the schema.  If you pass in all required fields this error should go away.  I would recommend something like Postman to do your testing and just keep adding the fields marked as required until you have them all...hope this helps.

Gregarican
Shopify Partner
1033 86 285

Good points. Also, based on the API response there might be an issue with authorization. Ensure the client credentials have access to the scope you are hitting. And if you are using Postman ensure that it's configured so client cookies aren't being passed along with your API request.  

jvantroyen
Tourist
5 0 2

I actually found the problem in the meantime. I'm not bumping into missing required fields. I could make an order with only the line-item property present.

Shopify rejects all POST using Basic Auth if they contain cookies. Postman always sends (hidden) cookies.
(https://shopify.dev/tutorials/authenticate-a-private-app-with-shopify-admin#make-authenticated-reque...)

Changed to authentication with Shopify access token and it worked.