Trying to set the shipping_line (and ideally get tax info) for Draft Order?

Highlighted
New Member
2 0 0

Using the Ruby shopify gem and I can create a Draft Order fine, but I can't seem to be able to set a shipping price.  If I do it manually in the admin console and then look at the attributes that are set (by fetching the Draft Order), I see this: #<ShopifyAPI::ShippingLine:0x00000005d28de0 @attributes={"title"=>"blah", "price"=>"12.00", "custom"=>true, "handle"=>nil}, @prefix_options={}, @persisted=true>

And yet when I try to set the shipping when I create the draft order the request fails:

      shipping_line: [
        {
          price: 10.00,
          title: "Free Shipping",
          handle: nil
        }
      ],

 

The same holds true when I try to set a shipping_line for an actual order.  I've tried removing handle, adding custom: true, etc. and can't seem to get it to work.  Has anyone successfully set the shipping rate for a draft order and order and can show me the right attributes?

Relatedly, ideally I would be able to see the relevant tax (set by Shopify) after creating a draft order, but whenever I create a draft order the tax remains unset.  Elsewhere in the forums people suggested this is possible, would also appreciate a working API call (i.e., one that returns a Shopify-set tax for a Draft Order createdd via the API) for that to see what I'm doing wrong.

Thanks!

0 Likes
Highlighted
New Member
2 0 0

Try setting the price as a string. Had the same issue yesterday. The draft order doesn't use variables as you would normally expect

0 Likes
Highlighted
New Member
2 0 0

Thanks for the reply Tomahawk.  I tried using price: "10.00" but that's still not working.  Are you just including price and title in the shipping_line object, or do I need something else?

0 Likes
Highlighted
Tourist
6 0 2

@Tomahawk, have you been successful in setting the shipping_line object when creating the draft order (on the initial POST)?

I'm always getting back '{ shipping_line: 'expected Array to be a Array' }' which I believe means that something in the shipping_line object is failing validation.

This is my draft order object (the rest of which is working):

{
...
  shipping_line:
   [ { custom: true,
       handle: null,
       price: '20.00',
       title: 'Price based shipping'
   } ],
...
}

I've tried not specifying handle, not specifying custom, I've tried numeric and string price, I've tried null, 'Nil', '' for handle.

0 Likes
Highlighted
Tourist
6 0 2

I finally got something to work, I have to specify shipping_line as an object instead of an array as the documentation indicates. I also had to use a 'custom' shipping method although I'm actually just using a shipping method pulled from shopify.

so my request looks like this:
 

{
...
  "shipping_line": {
    "custom": true,
    "price": "8.00",
    "title": "Standard Shipping"
  },
...
}

 

2 Likes
Highlighted
New Member
3 0 0

Hey @bliles 

I'm trying to do something similar.  I'm creating full Orders (not Draft Orders) via the API, and then fulfilling them via USPS/UPS.  Looking to capture the calculated shipping costs and the tax amounts. 

Two questions:

After you set the "shipping_line" field,  did you see it update with the actual shipping cost?

Was the order ever updated with the appropriate tax amount?

Thanks! 

0 Likes
Highlighted
Tourist
6 0 2

Hey Inspire Technology,

I have never been able to get the Shopify API to calculate the shipping costs for me in a simple/intuitive way. What I would like to see from Shopify is that after creating a draft order, it should be possible query some endpoint and get a list of possible shipment methods for that draft order along with the cost for each of these methods. I have not found a way to do this, if anyone has, please speak up!!!

As a workaround with both draft orders and orders, I'm using Shopify's ShippingZones endpoint and then manually attempting to do a similar shipping cost resolution as Shopify does, in my case always trying to get the cheapest shipment method that matches the order. Once I have the shipping cost calculated, I can add this to the draft order and then I am able to get an accurate tax amount from the draft order and show that to my users prior to purchase. We switched to using the draft order API so that we could use Shopify to calculate tax. I don't think there is a way to get Shopify to calculate tax while using the order API.

0 Likes
Highlighted
New Member
3 0 0

Thanks! That's super helpful.  Will keep searching for another way but that at least gives me a path forward.

-Matt

0 Likes
Highlighted
Shopify Partner
14 0 8

I was struggling with this too. The following works (python):

 

```

data = {
   "email" : "test@test.com",
   "shipping_address" : {
      "first_name": firstName,
      "last_name": lastName,
      "address1" : address1,
      "phone" : phone,
      "city" : city,
      "province" : state,
      "zip" : zipcode,
      "country" : "United States"
   },

   "fulfillment_status" : "unfulfilled",
   "financial_status" : "paid",
   "status" : "open",

   "shipping_line" : {
      "custom" : True,
      "price" : "9.99",
      "title" : "Expedited shipping",
   },

   "note" : "whatever",
}

shopify.DraftOrder.create(data)

```

 

Hope it helps someone!

0 Likes
Highlighted
New Member
5 0 0

@Johan_Land @Jonathan12 @Tomahawk @bliles 

As your problem was solved,

I posted the following data following your instruction on first order create,

 

{
   "order":{
      "line_items":[
         {
            "title":"2 Pieces Sets Tracksuit Men New Brand Autumn Winter Hooded Sweatshirt +Drawstring Pants Male Stripe Patchwork Hoodies Bigsweety",
            "variant_id":"31253838430251",
            "quantity":"2",
            "price":"0.3",
            "fulfillment_status":null
         }
      ],
      "customer":{
         "first_name":"Tekraj",
         "last_name":"Shrestha",
         "email":"shrestharj64@gmail.com"
      },
      "billing_address":{
         "first_name":"Tekraj",
         "last_name":"Shrestha",
         "address1":"Kathmandu, freak street",
         "phone":"",
         "city":"Kathmandu",
         "province":"",
         "country":"Nepal",
         "zip":"44600"
      },
      "shipping_address":{
         "first_name":"Tekraj",
         "last_name":"Shrestha",
         "address1":"Kathmandu, freak street",
         "phone":"",
         "city":"Kathmandu",
         "province":"",
         "country":"Nepal",
         "zip":"44600"
      },
      "shipping_line":{
         "custom":true,
         "price":"9.99",
         "title":"Expedited shipping"
      },
      "email":"shrestharj64@gmail.com",
      "financial_status":"paid",
      "fulfillment_status":"unfulfilled",
      "send_receipt":false,
      "send_fulfillment_receipt":false,
      "inventory_behaviour":"decrement_obeying_policy"
   }
}

I am doing this in php so data structures are a bit different. But I am not being able to post the shipping line. Can you please help me to solve this ?

Thanks

0 Likes