Raising a purchase order in Xero, leaving UnitAmount field blank

Hi all,
We have a Shopify module set up to Watch orders.
If a new order is received and that order matches with a filter, a purchase order is raised in Xero.
Here’s an example of the flow…

I want to automate entry of the COST price of the product on the Xero purchase order.
All our cost prices are stored in Xero (in the products and services section). They are stored under SKUs that correspond exactly with those SKUs in Shopify. This means we can map the SKU from Shopify to the SKU in Xero as shown below. I was thinking that if we can map the SKUs like this, then the cost price data against the Xero version of the product will pull through onto the purchase order.

The problem I’m having is that the Unit Amount field in the Xero module cannot be left empty. In other words, we need to define a Unit amount (the cost price) before the data is even communicated to Xero. I’ve tried setting the Unit Amount field to zero in the hope that 0 is overridden by the actual product cost stored in Xero but this doesn’t work, the Unit Amount field is overriding the cost data stored against the corresponding SKU in Xero.

One option may be to move our cost prices to Shopify by adding them to the Cost per item field as shown here…

I can then set Unit amount to the cost per item figure stored in Shopify. The problem is I cannot see the cost per item variable in the Shopify API.

Just wondering if anyone has ever come up against this issue?
Does anyone know whether the cost per item variable is available via Shopify’s API.
Or is there another way around this problem?

1 Like

I’m guessing that’s a limitation of the Xero API. Possibly because a PO might have a different unit amount to what’s listed on the Xero Item.

If you just want to use the stored unit amount (product cost) from what you have stored in the Xero Item, then add a Xero Get a Item module before the Create a Purchase Order module.

Also, something really important that’s missing in your scenario … unless I’m very much mistaken, you’ll need an Iterator to iterate through each line item in the Shopify order. This will need to build a Xero line items array that you can then Map (see that little “Map” slider next to Line Items?) into the Create a Purchase Order module.

1 Like

Hi David,

Thank you so much for getting back to me regarding this.

You are broadly correct in that each line item on the Shopify order will need adding to the Xero purchase order. I can see why an iterator would be required for this, I assume to split out each line item right? However, I’m not totally sure how to configure the modules correctly. Here’s the flow…

In the Iterator, I’ve entered the array as “Line items” from Shopify…

In the Xero Get An Item module I’ve then entered line items “Sku” as the “Item ID or code”. Our Shopify SKUs match with our Xero SKUs.

Lastly, I’ve enabled mapping in the Xero Create A Purchase Order module. I’ve added “Sku” from the iterator to the Line Items field as shown below.

Unfortunately I’m getting the following error when testing “Array of objects expected in parameter ‘LineItems’.”

Any guidance on this would be greatly appreciated!

Actually surprised myself and managed to figure this out myself! The only issue I have now is that the array is putting each line item on a separate Xero purchase order, so if there are 3 line items on the Shopify order, there are 3 separate purchase orders being created in Xero!
Ideally I would like each Shopify line item as a separate line item on the same Xero invoice. Any idea how I would do that?

You’re going to need to build a new array for the Xero Create a Purchase Order module that contains all the SKU items from the Shopify line items.

You can’t just pass the Shopify Line Items array as it is, as it contains a lot of other fields that Xero neither knows nor cares about.

The easiest way to do this in your scenario is to use an Aggregator module after the Iterator.

The Source Module for the Aggregator will be the Iterator. The Aggregated Fields will be SKU and the Quantity. The Target Structure will be the Xero Create a Purchase Order Line Items array.

The Aggregator link above has some help on this, but for more (and better) background I’d recommend taking the free Make Academy courses. The Intermediate course has a great module on Iterators and Aggregators!

2 Likes

Hi David, thanks for the reply.
Not sure if you saw my most recent message. I managed to figure this out yesterday using the Aggregator as you suggested. The only issue I have now is that the array is putting each line item on a separate Xero purchase order, so if there are 3 line items on the Shopify order, there are 3 separate purchase orders being created in Xero!
Ideally I would like each Shopify line item as a separate line item on the same Xero invoice. Any idea how I would do that?

Thanks for the link to the academy courses. Will definitely look at these.

1 Like

The Aggregator (note - that’s different from, but complementary to the Iterator) should mean that the following Xero app will get a single bundle for the whole order.

Could you post a screenshot of your current scenario?

1 Like

Hi David, I figured it out! Or rather @Runcorn did. I changed the Source Module of the aggregator from Xero Get An Item to Iterator. That seems to have fixed it.

This has raised another issue though, which I’m unsure how to fix.

Prior to implementing the iterator and array, I had set the Xero create purchase order module up to add a fixed cost (an order “handling fee” that our supplier charges) plus a variable shipping cost based on the shipping method name in Shopify.
The handling fee and shipping cost are not items that are passed over in the array from Shopify, they are items that we add on to the purchase order before sending it to the supplier.

I can’t add these additional items because the array aggregator doesn’t give me options to add additional line items. See the screenshot below as an example…

This got me thinking, maybe after creating the purchase order I can then set up a Xero Get An Item module to fetch the “Handling fee” from Xero. And then a Xero Update purchase order to append the handling fee onto the bottom of the purchase order in Xero. As shown in the below scenario…
After that I would then add another Xero Get An Item module to fetch the shipping price from Xero and then a final Xero Update purchase order to append the shipping price below the handling fee.

The problem is, the Xero Update purchase order module deletes all the previously added line items and replaces them with the latest line item from the Xero Get An Item module (second to last module in the flow above).

Any idea how I can get around this? The expected functionality would be for Xero NOT to delete the previously added line items each time it updates the purchase order.

How many items do you need to add?

We need to add two extra line items in this case:

  1. A fixed handling fee charged by the supplier
  2. A variable shipping fee charged to us by the supplier, cost dependent on which Shipping method the customer selects in Shopify (Standard or Express, basically)

I think you could solve this by using the Set a Variable (or Set Multiple Variables) module. The values of these should then be available to the Aggregator to put into the array.

You’d set these before the Iterator so that they only get run once for each order, rather than once for each line.

1 Like

David, thanks for the reply.
I get what you’re saying, I’m just unsure how I link to that variable to make it appear on the Xero purchase order. Here’s the flow…

And here’s how I’ve defined the variable…

But unless I link to this variable somewhere else in the flow it just gets ignored and doesn’t appear on the purchase order.

As an experiment I tried adding the variable as a second line item to the iterator but that just caused Xero validation to fail.

Hopefully you can see what I’m getting at here. Where do I reference the variable in the flow?

I was assuming you wanted these items to be added to every line item, in which case you’d reference them in the aggregator.

If not, then you need to add them to the end of the array that the aggregator creates. To do that, add a Set Variable module after the Aggregator, with the value set by the add() function like this:

add(, item1, item2)

You’d then map that new variable as the Line Items parameter for the Xero module.

The Make Academy courses are invaluable for this kind of thing!

1 Like

Hi David,

Thanks for the reply. I think I understand what you’re saying. I’ve added the variable after the array as shown here…

Within the variable module I’ve used the add() function and to add the array and the output of the second Xero get an item module as shown here…

I’ve then mapped the output of the variable to the Line Items field in the Xero create a purchase order module as shown here…

This is resulting in an error, Array of objects expected in parameter ‘LineItems’ as shown below.

Have I misunderstood something in your reply?

Hi @DK1,

You are in the right direction, But, You are adding a primitive field to an array of collections,s and since it is not as per the format that Xero Expects you are getting the error.

I shared a video to set this up on your DM, If you have time do check and see if that helps you with this issue.

@Runcorn thank you for the DM, your explanation worked perfectly and this is now fully working. Please do share the video here if you can as I’m sure it would be of help to others.
Thank you again for all your help!

1 Like