Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to setup integration between ServiceNow and LeanIX using GraphQL API

sarikab
Tera Contributor

Hello, i have a requirement where i need to integrate between servicenow  PDI and leanIX demo instance using GraphQL API.Whenever there is a record created in ServiceNow , a factsheet should be created on LeanIX end.Any leads would be appreciated.Thanks in advance.

3 REPLIES 3

Yashsvi
Kilo Sage

Hi @sarikab,

please check  below step:

  • Set Up LeanIX GraphQL API:

    • Obtain LeanIX API endpoint and authentication token.
    • Familiarize with the GraphQL mutation to create a factsheet.
  • Create a Script Include in ServiceNow:

 

var LeanIXIntegration = Class.create();
LeanIXIntegration.prototype = {
    initialize: function() {
        this.endpoint = 'YOUR_LEANIX_API_ENDPOINT';
        this.token = 'YOUR_LEANIX_API_TOKEN';
    },
    createFactSheet: function(record) {
        var payload = {
            query: `mutation {
                createFactSheet(input: {
                    type: "YOUR_FACTSHEET_TYPE",
                    name: "${record.name}",
                    description: "${record.description}"
                }) {
                    factSheet {
                        id
                        name
                    }
                }
            }`
        };
        var request = new sn_ws.RESTMessageV2();
        request.setEndpoint(this.endpoint);
        request.setHttpMethod('POST');
        request.setRequestHeader('Authorization', 'Bearer ' + this.token);
        request.setRequestHeader('Content-Type', 'application/json');
        request.setRequestBody(JSON.stringify(payload));
        request.execute();
    },
    type: 'LeanIXIntegration'
};

 

Create a Business Rule in ServiceNow:

  • Table: Specify the table (e.g., Incident, Task).
  • When: After Insert.

 

(function executeRule(current, previous) {
    var leanIX = new LeanIXIntegration();
    leanIX.createFactSheet(current);
})(current, previous);

 

Thank you, please make helpful if you accept the solution.

Hello @Yashsvi ,

Thanks for the response,

I have already tried this but i believe we have to do field mapping,setting the direction(source and target) etc.I have tried the setup in LeanIX as you mentioned and tried creating a factsheet from postman but i am getting a 405 method not found error. So i am trying to follow this document 

https://docs-eam.leanix.net/docs/setup-in-servicenow#create-an-integration-user but the thing is,according to the document we need to use a plugin for servicenow which i cant be able to do it in my personal instance.May i know if there is any alternative to plugin installation so that i can implement it in my PDI?

sarikab
Tera Contributor

Hello @Yashsvi 

Thanks for the response,

If i try the above setup mentioned,may i know where can i do field mappping,setting up the direction(source and target) etc? and i have tried the same setup you mentioned in leanIX and tried to create a factsheet from Postman but i am getting a 405 method not found error in response.So i am trying to follow this document https://docs-eam.leanix.net/docs/setup-in-servicenow#create-an-integration-user  but the thing is there is a plugin installation in the servicenow setup which i cant be able to do it in my PDI so may i know if there is any alternative to plugin installation that i can implement in my PDI?