PrecisionLender API Power

 

Overview

When writing your skills, you may want to obtain data from PrecisionLender API endpoints. In this article, we'll discuss how to use the PrecisionLender API powers when writing your skills. 

Prior to using the powers, make sure you have entered the Service Username and Token fields in Admin-Applications

 

In this Article

 

What are the PrecisionLender API powers?

The PrecisionLender API powers allow you to return a promise using either the 'get' or 'delayGet' methods based on the defined parameters from the PrecisionLender API. You will not be able to post to the PrecisionLender API.

  • get (skillContext, url) - returns a promise that once the call is complete, the object received from the 'get' request will be returned

    • skillContext - this is a passed in parameter of the current skillContext (as defined in the export function) in run or shouldIRun. This parameter will be defined as skillContext.
    • url - entered as a string, is a parameter that defines the https source for the call. This parameter must be defined.
  • delayGet (skillContext, url, delayInSeconds) - returns a promise that once the call is complete after a defined wait period, the object received from the 'delayGet' request will be returned

    • skillContext - this is a passed in parameter of the current skillContext (as defined in the export function) in run or shouldIRun. This parameter will be defined as skillContext.
    • url - entered as a string, is a parameter that defines the https source for the call. This parameter must be defined.
    • delayInSeconds - entered as a number, is a parameter that defines the number of seconds to wait before requesting data from the API endpoint. This parameter must be defined. If there is no delay, use the 'get' method.
 
 

How to call the PrecisionLender API powers

The API powers will be called via the api property of the PrecisionLender powers.

//get
return skillContext.powers.precisionLender.api.get()

//delayGet
return skillContext.powers.precisionLender.api.delayGet()

Here's an example run code for a skill that uses the 'get' method to access PrecisionLender's API endpoint for relationship data after the relationship Id has been obtained from the opportunity model. Notice how in this example, the url is defined as a string in a variable, and then the variable is passed in as the url parameter. 

export function run(skillContext: andiSkills.ISkillContext): andiSkills.RunResponse {

    return  skillContext.powers.precisionLender.opportunity
                .getCurrentOpportunityModel()
                .then((opportunityModel) => {
                    if(!opportunityModel) { return null; }
                    return  opportunityModel.opportunityDetails.relationshipId;
                })
                .then((relationshipId) => {
                    if (!relationshipId) { return null; }
                    // get the relationship details using the precisionlender api endpoint for relationships
                    let relationshipUrl: string = "https://api.precisionlender.com/crm/v1/relationships/" + relationshipId;
                    return skillContext.powers.precisionLender.api.get(skillContext, relationshipUrl);
                })

Once the promise is returned, if the relationship has a current balance, then the current balance for the relationship is defined as a custom value for and displayed in a field tag

export function run(skillContext: andiSkills.ISkillContext): andiSkills.RunResponse {

    return  skillContext.powers.precisionLender.opportunity
                .getCurrentOpportunityModel()
                .then((opportunityModel) => {
                    if(!opportunityModel) { return null; }
                    return  opportunityModel.opportunityDetails.relationshipId;
                })
                .then((relationshipId) => {
                    if (!relationshipId) { return null; }
                    // get the relationship details using the precisionlender api endpoint for relationships
                    let relationshipUrl: string = "https://api.precisionlender.com/crm/v1/relationships/" + relationshipId;
                    return skillContext.powers.precisionLender.api.get(skillContext, relationshipUrl);
                })
                .then((result) => {
                    let currentLoanBalance: number = 0;
                    // check if the relationship current balance information exists
                    if(result && result.relationship && result.relationship.currentLoanBalance > 1)  {
                        currentLoanBalance = result.relationship.currentLoanBalance;
                    }

                    // send a field tag information about the current loan balance for selected relationship
                    // this field tag will only show when currentLoanBalance is greater than 0
                    return skillContext.powers.andi.fieldTag.sendFieldTag(
                        andiSkills.FieldTagTypes.Warning,
                        "relationship-current-loanbalance",
                        1,
                        "Current loan balance for selected relationship is " + currentLoanBalance + ".",
                        null,
                        null,
                        function (api, model, comparehash, custom) {
                            // use the custom value passed in to show or hide field tag
                            if (custom.currentLoanBalance > 0) {
                                return true;
                            }
                            return false;
                        },
                        null,
                        null,
                        {
                            // pass the local custom value into Andi context
                            currentLoanBalance: currentLoanBalance
                        }
                    );
                });
}

 

Was this article helpful?
1 out of 1 found this helpful