SAP B1 Example
SAP B1 is a widely used enterprise resource planning software that is capable of being integrated with UniFi. It can be implemented on premise or hosted in a cloud environment.
Overview of the process
In order to interact with SAP the data connector must do the following steps:
- Authenticate using a valid SAP user.
- Send a request for the required information via http.
- Parse the response from SAP
- Return the response back to the UniFi field or process step that trigger the connector.
Adapting existing data connectors
If you already have some advanced data connectors that work with SAP B1 you will probably find its better to use these as a starting point rather than build one from scratch. The steps needed to adapt an existing data connector to work with your own instance of SAP are detailed in this section, if you want to get a more thorough understanding of how it actually works then full details are in the section below.
The SAP Business One API Gateway must be configured within SAP for data connectors to work. Refer to the SAP documentation for details of how to do this.
If the data connector is already doing what you need but you want to use it in another app, then you can simply re-use it by selecting it when you create an external dropdown. If you want to take an existing data connector and make it look at a different SAP account you will need the following:
- User name
- Password
- Company name
- Database instance (this is optional, only required if you have multiple database instances configured
- The server name and port of your SAP gateway server
The first step would be to make a copy of the existing data connector to work on, in this example we are using the 'SAP B1 Suppliers' data connector. You can then edit this data connector and make the following changes:
- Edit the first step described as 'Login' and change the relevant fields. The server name and port are from the connection details of your SAP gateway server, the rest is part of your SAP account information.
- Edit the second RestHttpClient step described as 'Get Supplier Data' and change the relevant parts of the URL (server name and port) to point to your SAP instance as described above.
Other values should stay the same, although if you want to change the fields being returned you can edit query in the 'Content' field as necessary.
Do not edit the content field of an existing data connector without knowing what other apps may be using it. As data connectors can be shared among multiple apps, if you are not sure its always safer to make a duplicate and work with that instead.
Your new data connector is now ready to test. Once successfully tested it can be used to populate a dropdown field in the form designer of the app builder.
Changing data connectors
If you want to make further changes to the data connector, or create one from scratch, then as well as making the above steps you will also need to consider the following:
-
In step 2 above, the URL after the server name part contained details about the API being called, in this case 'BusinessPartners'. You can use the same format to call any other available API's, you just need to enter the correct endpoint and adjust the query accordingly.
-
The 'Advanced' tab of this step includes some code to add the access token gained in the first 'Login' step of the process to the header of this request in the format required by SAP. This is essential for all requests to SAP to authenticate them.
- The next required step is to parse the results of this query so a 'Text Parser' step will be necessary. This gets the results returned by the previous step and turns them into a format suitable for use in UniFi.
Note that the source content field contains reference to GetData.ResponseContent. 'GetData' is the name of the previous step, so this code allows us to reference the output from this step and run a JSON Path query on that content.
- Finally, we need a 'Finish' step to indicate the process has completed.
This takes the output from the previous step (named 'Suppliers') and returns it back to the app or process that called it.