We needed a way of importing data and files to Knack from another application (Orion) that had an API integration. So we configure the client’s server to connect with the API and then in Knack call a specific endpoint configured in the server to import the final information in.
Note: The server is running in NodeJs/HapiJs as framework
These were the step we took to accomplish this:
Step 1: Configure the endpoint that the app in Knack is going to call passing some parameters:
Step 2: Authenticate server in the API with the client credentials:
Step 3: Then start using the API to retrieve the information needed from Orion passing through some data needed beforehand to filter the information retrieved:
Step 4: Once we had the initial information from Orion, we used this to start generating some files to import, saving them temporarily, so once they were saved in Knack we deleted them to clear all kinds of unwanted space-consuming files and data:
Step 5: The process of uploading a file to Knack is a different and recurrent process, so we extracted this into a different function called ‘uploadFileKnack (seen in the screenshot above):
This process of uploading a file to Knack is in a different plugin that makes a request to the Knack API with the information provided in the function above:
Step 6: Then we proceed to make some queries to Knack to know if the information from Orion matches some information already in Knack when the import is made. Also, we start building the body needed in the creation of records in Knack, one thing to mention is that the ID that we got back in the creation of the file in Knack is needed to link the file itself to the record that we’ll be going to create:
Step 7: We insert the record to Knack with the body built before and then delete the file as mentioned in point 4.
Step 8: Once we had all set up and ready on the server-side, we went ahead and built a modal in the Knack app with a table within in a form view to track the required information to import from Orion:
Step 9: This is how we built the table inside a form view in Knack:
Step 10: And when a person hits the import button in the modal, this will trigger some code that will pick up the information filled in the table to then make the HTTP request to the endpoint configured in the server with this information: