Task 01 Creating a Custom Connector
Task 01 Creating a Custom Connector
VANTAGE INTERMEDIATE
Task 01 Creating a Custom Connector
Task 01 Creating a Custom Connector
In this task, we will show you how to create a custom connector using the Vantage
REST API. As an example, we will create a connector for Gmail that will take a
Purchase Order document attached to an email and send it for processing into
Vantage.
By completing this task, you will learn how to:
• Create a Client ID and Client Secret and choose the Authentication schema
• Create transactions and get a Skill ID using the Swagger tool
• Create a custom connector for Gmail using the Google Apps Script
• Add the connector to Gmail
• Send documents for processing straight from your Inbox folder
• Get the processing results, again using the Swagger tool
To complete this task, you need to either have or create a Gmail account.
Note: Please follow the task instructions when creating and naming folders, Skills, and files.
To process a document, we will use a pre-built Document Skill (Purchase Order US). Let’s find the
Skill ID; we will need it further in this task.
You will get information about your newly created API client.
6. Now open the Help page by clicking Help>Documentation in the bottom-left corner of the
screen.
7. Once you are on the Help page, select the
Vantage API card.
8. You have opened the Swagger tool. First of all, you
need to authorize. Click the Authorize button to the
right.
9. Check the two checkboxes at the bottom-left corner to grant Swagger access to all scopes. Click
Authorize. You may need to provide your Vantage credentials.
13. Click the Try it out button to the right, then click the blue Execute button.
14. In the Response body below, you will see a list of all available Skills with listed ID’s, names, and
types.
15. Press Ctrl+F to open up a search pane. Search for the Purchase Order US Skill. Save the
Purchase Order US Skill ID to Notepad. We will need the Skill ID later.
20. You will see that appscript.json file has appeared under the Files section. Open it.
We highly recommend that you read through the script and get familiarized with the described
settings.
22. Open the Code.gs file from the left-side menu.
Here you need to write JavaScript code that will do the
following:
• Set up your Vantage credentials
• Specify the API Client ID and Client Secret
• Copy to Notepad your Vantage URL (open Vantage,
then copy the URL where you have an account –
please see below)
Do not copy this example, as you might have an account in a different Vantage environment!
• Go to the Configuration > General, then copy to the Notepad your Tenant ID.
Don’t forget to add your Vantage login, password, the valid Skill ID, and the valid Vantage URL,
your Tenant ID, created Client ID and Client Secret to the script template!
Note that the script is quite long. Don’t inadvertently truncate anything while copying and
pasting!
When copying from a PDF, syntax errors may appear. If you see any syntax errors during
compilation, ensure that you haven’t copied a page footer along with the script, and confirm
that the script lines are not broken. The benefit of doing this is you become more familiar with
the code as you resolve any problems.
If, after thorough examination of your pasted script, syntax errors persist, please download
this appendix_B_code.js JavaScript file, then open it with Notepad. After that, you can copy
and paste the code without encountering syntax errors.
25. When asked to authorise, click on the Review permissions button and pick your Google
account.
27. After running the script, you might receive this error in the Execution log:
For the purposes of this task, this error message is not important—so just ignore it.
28. Click Deploy>Test deployments at the top-right corner of the screen.
Excellent! You have successfully created a custom connector and tested it!
// Get an access token scoped to the current message and use it for GmailApp calls.
var accessToken = e.gmail.accessToken;
GmailApp.setCurrentMessageAccessToken(accessToken);
// login
var token=VantageAuthenticate(VANTAGE_LOGIN,VANTAGE_PASSWORD);
// create a transaction
var transactionID=RunTransaction(token,VANTAGE_SKILL_ID,attachmentInBase64,attachment
Name)
// define headers
var headers = { 'Content-Type' : 'application/x-www-form-urlencoded' }
return token;
var options = {
'headers': headers,
'method' : 'post',
'contentType': 'application/json',
'payload' : JSON.stringify(payload)
};
var response=UrlFetchApp.fetch(VANTAGE_URL+'/api/publicapi/v1/transactions/run', option
s);
var transactionID=data.transactionId;
return transactionID;
var options = {
'headers': headers,
'method' : 'get',
};
var response=UrlFetchApp.fetch(VANTAGE_URL+'/api/publicapi/v1/transactions/'+transact
ionID, options);
var status=data.status;
return status;
}
}