<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to use Morpheus API through Plugin in HPE Morpheus Enterprise</title>
    <link>https://community.hpe.com/t5/hpe-morpheus-enterprise/how-to-use-morpheus-api-through-plugin/m-p/7251589#M4763</link>
    <description>&lt;P&gt;Thanks, this helped!!&lt;/P&gt;</description>
    <pubDate>Mon, 09 Oct 2023 08:53:33 GMT</pubDate>
    <dc:creator />
    <dc:date>2023-10-09T08:53:33Z</dc:date>
    <item>
      <title>How to use Morpheus API through Plugin</title>
      <link>https://community.hpe.com/t5/hpe-morpheus-enterprise/how-to-use-morpheus-api-through-plugin/m-p/7251587#M4761</link>
      <description>&lt;P&gt;We need to collect some information from onprem service which the Morpheus App node has access. Hence, workflow/ task is the only option to get that info in Morpheus UI. Now, this info I want to put it under a instance tab.&lt;/P&gt;
&lt;P&gt;To do this I need to execute a workflow using REST Api. So, any suggestions on how can this be achieved from Plugin code.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2023 13:28:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/hpe-morpheus-enterprise/how-to-use-morpheus-api-through-plugin/m-p/7251587#M4761</guid>
      <dc:creator />
      <dc:date>2023-10-05T13:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Morpheus API through Plugin</title>
      <link>https://community.hpe.com/t5/hpe-morpheus-enterprise/how-to-use-morpheus-api-through-plugin/m-p/7251588#M4762</link>
      <description>&lt;P&gt;In the Morpheus Uplink plugin I use this to auth to Morpheus API:&lt;/P&gt;
&lt;PRE style="background : #f0f1f2;"&gt;&lt;CODE class="lang-auto"&gt;def login(HttpApiClient client, rpcConfig) {
        def rtn = [success:false]
        try {
            HttpApiClient.RequestOptions requestOptions = new HttpApiClient.RequestOptions(ignoreSSL: rpcConfig.ignoreSSL,contentType: 'form')

            def username = rpcConfig.username.toString()
            def password = rpcConfig.password.toString()

            requestOptions.queryParams = ['client_id':'morph-automation','grant_type':'password','scope':'write']
            requestOptions.headers = ['Content-Type':'application/x-www-form-urlencoded']

            // requestOptions.body = "username=${username}&amp;amp;password=${password}"
            requestOptions.body = ['username':username,'password':password]

            def apiUrl = cleanServiceUrl(rpcConfig.serviceUrl)
            def apiPath = getServicePath(rpcConfig.serviceUrl) + authPath

            def results = client.callJsonApi(apiUrl,apiPath,requestOptions,'POST')
            if(results?.success &amp;amp;&amp;amp; results?.error != true) {
                log.debug("login: ${results}")
                rtn.token = results.data?.access_token?.trim()
                rtn.success = true
            } else {
                return ServiceResponse.error("Get Token Error")
            }
        } catch(e) {
            log.error("Get Token Error: ${e}", e)
            return ServiceResponse.error("Failed to authenticate to Morpheus")
        }
        return rtn
    }
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is an example of using the token generated to list all networks in a Morpheus:&lt;/P&gt;
&lt;PRE style="background : #f0f1f2;"&gt;&lt;CODE class="lang-auto"&gt;private ServiceResponse listZones(HttpApiClient client, String token, NetworkPoolServer poolServer, Map opts = [:]) {
        def rtn = new ServiceResponse()
        rtn.data = [] // Initialize rtn.data as an empty list
        try {
            def rpcConfig = getRpcConfig(poolServer)
            def apiUrl = cleanServiceUrl(rpcConfig.serviceUrl)
            def apiPath = getServicePath(rpcConfig.serviceUrl) + networkDomainsPath
            def hasMore = true
            def attempt = 0
            def doPaging = opts.doPaging != null ? opts.doPaging : true
            def start = 0
            def maxResults = opts.maxResults ?: 1000

            log.debug("url: ${apiUrl} path: ${apiPath}")

            if(doPaging == true) {
                
                while(hasMore &amp;amp;&amp;amp; attempt &amp;lt; 1000) {
                    attempt++
                    HttpApiClient.RequestOptions requestOptions = new HttpApiClient.RequestOptions(ignoreSSL: rpcConfig.ignoreSSL)
                    requestOptions.headers = [Authorization: "Bearer ${token}".toString()]
                    requestOptions.queryParams = [max:maxResults.toString(),offset:start.toString()]

                    def results = client.callJsonApi(apiUrl,apiPath,null,null,requestOptions,'GET')

                    if(results?.success &amp;amp;&amp;amp; results?.error != true) {
                        rtn.success = true
                        if(results.data?.networkDomains?.size() &amp;gt; 0) {
                            rtn.data += results.data.networkDomains

                            if(doPaging == true) {
                                start += maxResults
                                hasMore = true
                            } else {
                                hasMore = false
                            }

                        } else {
                            hasMore = false
                        }
                    } else {
                        hasMore = false

                        if(!rtn.success) {
                            rtn.msg = results.error
                        }
                    }
                }
            } else {
                HttpApiClient.RequestOptions requestOptions = new HttpApiClient.RequestOptions(ignoreSSL: rpcConfig.ignoreSSL)
                requestOptions.headers = [Authorization: "Bearer ${token}".toString()]
                requestOptions.queryParams = [max:maxResults.toString(),offset:start.toString()]

                def results = client.callJsonApi(apiUrl,apiPath,null,null,requestOptions,'GET')

                if(results?.success &amp;amp;&amp;amp; results?.error != true) {
                    rtn.success = true
                    if(results.data?.networkDomains?.size() &amp;gt; 0) {
                        rtn.data = results.data.networkDomains
                    }
                } else {
                    if(!rtn.success) {
                        rtn.msg = results.error
                    }
                }
            }
        } catch(e) {
            log.error("listZones error: ${e}", e)
        }

        log.debug("List Zones Results: ${rtn}")
        return rtn
    }
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can check out the example here:&lt;/P&gt;&lt;ASIDE class="onebox allowlistedgeneric" data-onebox-src="https://github.com/gomorpheus/morpheus-morpheusuplink-plugin"&gt;
  &lt;HEADER class="source"&gt;
      &lt;IMG src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="32" height="32" /&gt;

      &lt;A href="https://github.com/gomorpheus/morpheus-morpheusuplink-plugin" target="_blank" rel="noopener"&gt;GitHub&lt;/A&gt;
  &lt;/HEADER&gt;

  &lt;ARTICLE class="onebox-body"&gt;
    &lt;DIV class="aspect-image" style="--aspect-ratio:690/344;"&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="c7b83753626bd7c06bd21019688d621149b441be.png"&gt;&lt;img src="https://community.hpe.com/t5/image/serverpage/image-id/150105i594C3049A415D1FF/image-size/large?v=v2&amp;amp;px=2000" role="button" title="c7b83753626bd7c06bd21019688d621149b441be.png" alt="c7b83753626bd7c06bd21019688d621149b441be.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;

&lt;H3&gt;&lt;A href="https://github.com/gomorpheus/morpheus-morpheusuplink-plugin" target="_blank" rel="noopener"&gt;GitHub - gomorpheus/morpheus-morpheusuplink-plugin: This is the source code...&lt;/A&gt;&lt;/H3&gt;

  &lt;P&gt;This is the source code for the plugin version of the Morpheus Remote IPAM and DNS Integration - GitHub - gomorpheus/morpheus-morpheusuplink-plugin: This is the source code for the plugin version o...&lt;/P&gt;


  &lt;/ARTICLE&gt;

  &lt;DIV class="onebox-metadata"&gt;
    
    
  &lt;/DIV&gt;

  &lt;DIV style="clear: both"&gt;&lt;/DIV&gt;
&lt;/ASIDE&gt;</description>
      <pubDate>Thu, 05 Oct 2023 13:38:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/hpe-morpheus-enterprise/how-to-use-morpheus-api-through-plugin/m-p/7251588#M4762</guid>
      <dc:creator>cbunge</dc:creator>
      <dc:date>2023-10-05T13:38:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Morpheus API through Plugin</title>
      <link>https://community.hpe.com/t5/hpe-morpheus-enterprise/how-to-use-morpheus-api-through-plugin/m-p/7251589#M4763</link>
      <description>&lt;P&gt;Thanks, this helped!!&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 08:53:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/hpe-morpheus-enterprise/how-to-use-morpheus-api-through-plugin/m-p/7251589#M4763</guid>
      <dc:creator />
      <dc:date>2023-10-09T08:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Morpheus API through Plugin</title>
      <link>https://community.hpe.com/t5/hpe-morpheus-enterprise/how-to-use-morpheus-api-through-plugin/m-p/7251590#M4764</link>
      <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;
&lt;P&gt;I see a function name getRpcConfig.&lt;BR /&gt;
&lt;CODE style="background : #f0f1f2;"&gt;def rpcConfig = getRpcConfig(poolServer)&lt;/CODE&gt;&lt;BR /&gt;
Can I know what other ways can I get this rpcConfig. I am referring to &lt;A href="https://developer.morpheusdata.com/api/index.html" rel="noopener nofollow ugc"&gt;https://developer.morpheusdata.com/api/index.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2023 06:07:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/hpe-morpheus-enterprise/how-to-use-morpheus-api-through-plugin/m-p/7251590#M4764</guid>
      <dc:creator />
      <dc:date>2023-10-06T06:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Morpheus API through Plugin</title>
      <link>https://community.hpe.com/t5/hpe-morpheus-enterprise/how-to-use-morpheus-api-through-plugin/m-p/7251591#M4765</link>
      <description>&lt;P&gt;Yes, the cypher service is accessible from within plugins. The following is a snippet from an older version of the DataDog plugin code that referenced cypher for credentials.&lt;/P&gt;
&lt;ASIDE class="onebox allowlistedgeneric" data-onebox-src="https://developer.morpheusdata.com/api/com/morpheusdata/core/cypher/MorpheusCypherService.html"&gt;
  &lt;HEADER class="source"&gt;

      &lt;A href="https://developer.morpheusdata.com/api/com/morpheusdata/core/cypher/MorpheusCypherService.html" target="_blank" rel="noopener"&gt;developer.morpheusdata.com&lt;/A&gt;
  &lt;/HEADER&gt;

  &lt;ARTICLE class="onebox-body"&gt;
    

&lt;H3&gt;&lt;A href="https://developer.morpheusdata.com/api/com/morpheusdata/core/cypher/MorpheusCypherService.html" target="_blank" rel="noopener"&gt;MorpheusCypherService (Morpheus Plugin API)&lt;/A&gt;&lt;/H3&gt;

  &lt;P&gt;declaration: package: com.morpheusdata.core.cypher, interface: MorpheusCypherService&lt;/P&gt;


  &lt;/ARTICLE&gt;

  &lt;DIV class="onebox-metadata"&gt;
    
    
  &lt;/DIV&gt;

  &lt;DIV style="clear: both"&gt;&lt;/DIV&gt;
&lt;/ASIDE&gt;

&lt;PRE style="background : #f0f1f2;"&gt;&lt;CODE class="lang-auto"&gt;		// Define the Morpheus account/tenant in which
		// to search for the DataDog credentials. The plugin
		// assumes the master account shoud be searched.
		def account = new Account(id: 1)
		def cypherAccess = new CypherAccess(account)

		// Retrieve the DataDog API key from Cypher
		// The plugin expects the name of the secret to be dd-api-key
		def intApiKey = morpheus.getCypher().read(cypherAccess, "secret/dd-api-key")
		def apiKey = ""
		intApiKey.subscribe(
			{ secretData -&amp;gt; 
                 apiKey = secretData
        	},
        	{ error -&amp;gt;
                 println error.printStackTrace()
        	}
		)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Nov 2023 03:04:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/hpe-morpheus-enterprise/how-to-use-morpheus-api-through-plugin/m-p/7251591#M4765</guid>
      <dc:creator />
      <dc:date>2023-11-06T03:04:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Morpheus API through Plugin</title>
      <link>https://community.hpe.com/t5/hpe-morpheus-enterprise/how-to-use-morpheus-api-through-plugin/m-p/7251592#M4766</link>
      <description>&lt;P&gt;&lt;A class="mention" href="https://community.hpe.com/u/cbunge"&gt;@cbunge&lt;/A&gt; is there any way we can use cyphers in Plugin code?&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2023 13:19:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/hpe-morpheus-enterprise/how-to-use-morpheus-api-through-plugin/m-p/7251592#M4766</guid>
      <dc:creator>rajmartha</dc:creator>
      <dc:date>2023-11-03T13:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Morpheus API through Plugin</title>
      <link>https://community.hpe.com/t5/hpe-morpheus-enterprise/how-to-use-morpheus-api-through-plugin/m-p/7251593#M4767</link>
      <description>&lt;P&gt;Am I right that the results variable is of type ServiceResponse?&lt;/P&gt;
&lt;P&gt;If so, why is it possible to access its private variables which we can see in the following?&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;if(results?.success &amp;amp;&amp;amp; results?.error != true)&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 07 Mar 2024 13:26:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/hpe-morpheus-enterprise/how-to-use-morpheus-api-through-plugin/m-p/7251593#M4767</guid>
      <dc:creator />
      <dc:date>2024-03-07T13:26:52Z</dc:date>
    </item>
  </channel>
</rss>

