API Gateway Overview
SapphireOne’s API Gateway is typically used by SapphireOne end users to facilitate the importation or exporting of vast amounts of data quickly and easily. In other articles we have provided an extensive array of documentation, which is being added to on a daily basis. The SapphireOne community typically will use the API function in the scenario that they bring on a new vendors and that Vendor may have a range of inventory that they have provided to you in an electronic form. You would now like to import that inventory including the cost price and the Recommended Retail Price (RRP). This is one example of the usage of the SapphireOne API Gateway function. The SapphireOne API Gateway functions have an extensive and wide and varied use within SapphireOne that is designed to provide a very quick and efficient way of getting vast sums of data into or out of SapphireOne quickly and easily.
The SapphireOne API Gateway II function, provides the user a single convenient source of functionality and data. When we at SapphireOne make reference to testing in a backup copy of your live data file, in the technology industry this is typically referred to as a sandbox. The beauty with the Sapphire Single User that is provided with the SapphireOne Client Server application is that you can repeat these imports as many times as you wish in a sandbox environment and each time you perform the import you can then trash the data file and then take a fresh copy of your current data file and retest the import. You can redo this as many times as you like until you’re completely satisfied with your end result. So always run Sapphire Single User in a sandbox environment with a copy of your live data file and test before you import any data into your live data file.
API stands for Application Protocol Interface. This article will be updated as additions and alterations are made.
Never blind import any gateway files into a live data file. Run up a recent copy of your live data file using the same build as on the server in Single user Mode, and do a test import of the data that you want to import first.
Look carefully at the results and in particular check that the columns of data in the import file have been imported into the correct data fields in the copy of your live data file.
Only when the test has been completed and when all looks correct, then proceed to backup the live data file and only then, import the file into the live data file. If it is not correct find the error in the import file and then import it again into a fresh copy of the live data file.
Remember test first then import your data.
As of the updating of this reference manual there are a number of methods used to both import and export data from the data file. Using Gateway II, or III to export or import data.
Excel Link may also be used which is for exporting data out only.
- Gateway I – This function is no longer used.
- Gateway II – This function is used for forth importing and exporting from from the data file.
- Gateway III – This is a simplified function for the importing of limited items into the data file.
Differences gateway II and III:
- Gateway II – The user has to organise the import spreadsheet columns of data to match the requirements of SapphireOne. It uses the tables as documented in another article titled, Table Format of Data for Read & Write.
- Gateway III – The user is able to enter the columns of data in any order. Then by clicking on each headings name, map the columns to match SapphireOne’s requirements.
- New Data Files – This function has mainly been provided for the importing of data into new data files.
- Functionality – For the above reason reason, functionality in Gateway III is limited to the items in the drop-down list Also note that it only allows for the importing of data into the data file, not exporting.
Gateway II allows the direct interaction with SapphireOne’s Database for retrieving information, and the adding of data under controlled conditions. The information may be passed to SapphireOne via a text file or via TCP/IP.
This is mainly used when converting from an existing data base across to SapphireOne. Most data bases will export to a Tab delimited (.txt) or comma delimited (.csv) text file. Once that is done the text file can be opened using a spreadsheet program and the columns of data re-arranged to suit importation by SapphireOne.
To import this data into SapphireOne it must be in a tab delimited text file or a CSV file. You may use any spreadsheet program so long as it will allow you to save the file as Text (Tab Delimited) or as a CSV file.
Import / Export Syntax
SapphireOne expects to see in column A of any table, 2 to 4 letters preceded by a % or # symbol. That gives it the instructions for the current row of data and what it is to do with it.
- % Export – The % symbol instructs SapphireOne to read data out of the data file and then write it into a tab delineated text file.
- # Import – If SapphireOne is told to read a tab delineated file into a data file, the % symbol must be replaced with the # symbol so that it knows that all after the #CLA from column B through to column N in the row is to be read and written into the data file. #CLB would tell SapphireOne that it is to import every thing from column B through to Column BC
This is an example of a special file using the @ symbol in column B. SapphireOne looks at the first cell A1 and determines that it is to read from the database the CLA fields. The second cell B1 tells it to read them all. The last cell A2 tells it end of file.
Based on the letters in the first cell A SapphireOne will read almost any data from the database into a Tab delimited text file. For details on what can be read please look at the tables in another article here in knowledge base.
Gateway II may be accessed by going to:
Utilities > Utilities > Sapphire Functions
It is under the General Tab and is named Gateway II
% To Export Data – . When the user selects gateway II they will be asked by the operating platform Mac or Windows, to select a file for this operation.
SapphireOne will look at the file and determine that is is to export data out.
The user will see an alert asking for the name of the exported file and then where the file is to be sent to.
# Importing data – When a file has the # symbol prefixing the letters in column A the request immediately above will be displayed. Do not enter any name or details just select OK. There will be a brief display displaying numbers as SapphireOne imports the details in the file into your data file.
Controlling the reading and writing
Please look at the Client table below. It is an import table as the syntax’s all start with the # symbol. The letters from A to Z, then carrying on from AA to AZ, are the columns of data in the table article. Some import tables go pas this and will commence with BA through to BZ as may be seen in the Client import file below.
For the documentation here please read the left column from top to the bottom, then start at the top of the next column and go to the bottom. If there is a third column again read it from top to bottom.
If you use %CLA syntax in column A in the text file, SapphireOne will write data out of the data file into the tab delineated file from column B only up to column N and no further.
If you create a text file and use #CLA syntax in Column A in the text file, SapphireOne import all rows of data commencing with column B through to column N. Even though you may have data in column M the very next column it will not read it.
The read write rules are as follows
- % or # CLB extends the read write to column AG.
- % or # CLC continues to extend this read write functionality to column BC.
- % or # CLD continues this functionality on to extend this to column BU.
- % or # CLL is different as it is an independent table starting at column A through to column Y.
- % or # CLX is differentas it is another independant table from column A through to column Z.
For most tables column A holds the read write syntax, and the actual data commences at column B.
There are a few tables where data read write commences at column A but it is not normal and has been documented in the article on table formatting. For example if you have a multi-line invoice, SapphireOne will reach the end of the columns of data that is has been told to to import into the data file. If this last column does not contain four ^^^^ (shift-6) in the required column, it will expect to write an ID into column A and enter the line details. Extended details are in the Table format article.
Any formatting will cause problems if not removed before importing data into the data file.
Tab can be replaced by other characters that have an ASCII value greater than 138 instead of the tab.
Returns in line items (eg mailing details) need to be replaced with a grouped combination of three standard characters =|=. That is the two equal signs and the vertical pipe in the order as seen.
The file needs to end with %%%% to mark end of file as some programs require end of file markers.
SapphireOne will receive text via tcp to do the required actions.
Open a session to the tcp/ip address of the serving program as set up under remote access defaults.
Using that session number text packets can be sent and will be received identified by that session number. A packet of ???? will return the Serial Nº, Company Name, and Version Nº.