Stepping it up: Making Copilot create an API integration between Business Central and Shopify

Stepping it up: Making Copilot create an API integration between Business Central and Shopify

In the latest examples with Copilot in my previous blog posts, I have covered:

First run: Making Copilot create documentation for my solution – Peik’s Corner

Which I have also used for this solution,

Using Copilot to create the featured picture – Peik’s Corner

Which was used to make the featured picture together with: how to make a complete solution

How to make Copilot create your Business Central App – Peik’s Corner

What if I want to step it up and only provide Copilot with the examples of Json files for an API integration solution used to retrieve sales orders from Shopify?

Yes, I know; there is already a readymade app with a Shopify integration, but this is an example that would show the level of complexity that Copilot can work with.

The files given

I am going to give three files in the project for Copilot to work with:

  • My prompt file: Shopify Integration.md
  •  Orders.json: List of all orders to retrieve
  • Order.Json: One order with all details

The files are from an actual customer case so, I will anonymize the data in the files.

The Prompt File

First of all, my work with Copilot has taught me that I must set up the Goal first:

This will reference the Best Practices of Business Central and introduce the Json files in the Examples folder that I want it to work with.

Then I start setting up the requirements for the filtering and which tables in the Base Application to work with.

Lastly, I set the requirements:

The Orders.Json file

This includes all information about:

  • the orders
  • the customer info
  • the order lines
  • the tax (VAT) information

The Order.Json file

This also includes all information about:

  • the orders
  • the customer info
  • the order lines
  • the tax (VAT) information

But also, information about:

  • Payment Information
  • Refunds
  • Gift cards
  • Duties
  • Shipping lines

The test

So, what happens if I:

  • Create a new project
  • Add the launch.json file pointing to my Sandbox in the cloud
  • Add an App.json file with the basin information like: App Id, Description and Object Range
  • Download the symbols from the Sandbox
  • Add a Documentation file in the Prompt folder
  • Add the examples Json-files in the Example files folder
  • Set the agent to be Claude Sonnet 4.5
  • Use the prompt in the Copilot agent

What it did, was ignoring my requirement in the prompt about using best practices for Business Central and the files look like this:

So, I try once more to prompt it with the Best Practices for Business Central:

Which fixed that problem.

Next, I will let it document the solution by itself

Which gave me this:

The solution made

It seems to have understood the assignment. The solution consists of:

With three Codeunit, one Enum a Table and a Page:

But will it actually work?

The Setup Table

It has understood the need of a setup table and it has added all the necessary fields:

  • Primary Key
  • API Endpoint
  • API User Id
  • API Password

And it has added the code to store the password encrypted

Saving the password in a blob field: Encrypted Password

  • Encrypted Password
  • Web order Status filter

which is an Enum (” “,Open,closed,cancelled,any)

  • Last Order No. Imported
  • Last Date Imported
  • Last Time Imported
  • Last DateTime Imported

I am really happy with this 😊

The Setup Page

This has been created as any setup page for a Singleton record in Business Central including the

creation of the blank record if it does not exist.

Copilot even created the manual test of the import orders as an action.

The Import Codeunit

The Codeunits are off course the most important. Copilot created three Codeunits:

  • A Json helper Codeunit

This helps getting different values from the Json tokens

  • Text values
    • Decimal values
    • Integer values
    • Date values
    • DateTime values
    • Boolean values
    • GetObject
    • GetArray
    • GetNestedTextValue (Which was not used)
  • And a HTTP Client helper Codeunit

This contains the communication between Business Central and the Shopify API

  • The GetOrders method uses the information in the setup table and return a JsonArray
    • BuildOrdersURL to set the filters
    • A GetStatusFilterValue which converts the Enum values to text values (I am not sure that this is necessary)
    • SetupBasicAuthentication to create the authentication used with the API
  • The import Codeunit

The Import Codeunit has been given the Jon Queue Entry table as source table:

This is the only error that I have seen on first inspection, but it is not a crucial error.

The Import Codeunit seems to work fine other than that:

  • Utilizes the GetOrders from the HTTP Helper Codeunit to add the orders to a JsonArray
    • Uses the ProcessOrders method to add each order to a JsonObject and then process every order in the ProcessSingleOrder method
    • The ProcessSingleOrder method will then:
      • Testing if the order already exists using the External Order No
      • Create the sales header
      • Create the customer
      • Create the sales lines
      • Then Update the setup table

The Testing

Since I do not have a valid user id and password for the Shopify API, I cannot test it directly, but I can compare it with the solution I made for a customer back in 2021 and I don’t think that it would take a lot to make this work in a live environment.

The Conclusion

From now on, I will never start a new project in the future, without having Copilot making the hard work for me first. As I wrote initially, I would never add orders directly to the sales header and lines tables, but I did that here to make the solution as simple as possible.

So, did it make a perfect solution?

No

But, it did what I asked for; downloading orders from Shopify and importing them directly in the Sales Header and Line tables, and this was made almost perfectly.

It totally ignored a number of the important parts:

  • The payment
  • Gift cards
  • Shipping information
  • Duties
  • VAT information

However, most of these are not part of the Base Application, and it is something I would have to address with a customized solution anyway.

So, I am really pleased with the solution it made and I am looking forward to working with Copilot in the future, regardless of the dilemmas that I mentioned in my previous post.

Just remember, It’s all in the Prompt!

As always, you can download the created solution here:

peikba/Shopify-Copilot-Integration-I