Highlighted
Regular Contributor.. Regular Contributor..
Regular Contributor..
1850 views

Create Web Services/REST API to call ScriptLibrary

Jump to solution

Hi Guys, 

Apologize if its basic configuration. I'm very new to HP SM and wanted to try create web services or REST API to call simple ScriptLibrary created. Is there any absolute beginner guide for this? I tried create External Access Definition and not sure on right values to fill in like Service Name, Object Name, Resource details and so on.

As for now, i only created simple script library to print something. Just managed to check URL http://localhost:13080/SM/7/rest. Stuck till here. 

Please help, thanks

0 Likes
1 Solution

Accepted Solutions
Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..
Hey,

Sorry for the late response.

Username and password can be set in the operator table (shortcut: operator).

Please ensure, that the user has the capability for The REST API (don't know the exact capability word ).

For the RESTful API the /SM/9/rest in the URL is required - SM/7/ is (if I'm not wrong) only for the SOAP API.

View solution in original post

5 Replies
Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..

Hi,

the URL for the RESTful endpoint is different to the SOAP endpoint.

For REST you have to use the following URL: http://localhost:13080/SM/9/rest/<ServiceName>

To the input fields:

  • Service Name: This is the name, which will be used later in the Url.
  • Name: this is the choosen dbdict table
  • Object Name: This will be used to define a unique Request name
    ( Example for extaccess - ServiceCatalogAPI -> Cart: <action><ObjectName>Request --> CreateCartRequest )

To call your own ScriptLibrary, you can call the ScriptLibrary directly. To do this, you have to create a new extaccess record. Please find below my steps:

  1. Fill General fields
    1. Service Name: ScriptLibrary
    2. Name: ScriptLibrary
    3. Object Name: ScriptLibrary
  2. Click "Add" (otherwise you can't see the available actions in the tab "Allowed Actions"
  3. Check the dropdown values for the column "Allowed Actions"
    1. Is the Action "execute" available?
      1. Yes --> continue with Step X
      2. No --> Continue with Step 4
  4. Open the Database Manager (shortcut "db")
  5. Open the table "Object" and open the record "ScriptLibrary"
  6. Via "Find", open the Default State (State: ScriptLibrary.view)
  7. Define a new Action
    1. Display Action: execute
    2. Process name: execute.javascript
    3. Condition: true
  8. Save the State
  9. Run a "Find" on the cell with the value "execute.javascript"
  10. In the tab "Initial Expressions", use the following script:
    $L.void=jscall(1 in $L.file)
  11. Click "Add" to create a new Process
  12. Open your created extaccess record again
  13. Define the following line:
    1. Allowed Actions: execute
    2. Action Names: Execute
    3. Action Type: <empty> (you can also use "Create only", "Update Only" or "Merge" - doesn't matter, because our action executes only the defined SL)
  14. In the Tab "RESTful" set the following:
    1. RESTful enabled: true
    2. Resource Collection Name: ScriptLibrary (this will be used later in the URL as name)
    3. Resource Name: ScriptLibrary (Will be used in the POST Request Content as Root Element Name)
    4. Unique Keys: name
  15. Save the extaccess
  16. Open SOAP UI or another restful client and run a GET request against "http://localhost:13080/SM/9/rest/ScriptLibrary"
    You should see all available ScriptLibraries
  17. Via a POST, call the following URL: http://localhost:13080/SM/9/rest/ScriptLibrary/test/action/execute
    "test" is my own library.
  18. The Content for the POST Request is:
    {
    	"ScriptLibrary" : {
    		"name" : "test"
    	}
    }

 My library "test" has the following content:

var fFile = new SCFile("ScriptLibrary");
var timestamp = new Date();
fFile["name"] = "test_"+timestamp.getTime();
fFile["package"] = "User";

var rcInsert = fFile.doAction("add");

 

My SOAP UI Response is:
XML:

<Response xmlns="http://localhost/SM/9/rest/ScriptLibrary/test/action/execute">
   <Messages>
      <e>Script Library record added.</e>
   </Messages>
   <ReturnCode>0</ReturnCode>
   <ScriptLibrary>
      <name>test</name>
      <package>User</package>
      <script>var fFile = new SCFile("ScriptLibrary");
var timestamp = new Date();
fFile["name"] = "test_"+timestamp.getTime();
fFile["package"] = "User";

var rcInsert = fFile.doAction("add");</script>
   </ScriptLibrary>
</Response>

JSON:

{
   "Messages": ["Script Library record added."],
   "ReturnCode": 0,
   "ScriptLibrary":    {
      "name": "test",
      "package": "User",
      "script": "var fFile = new SCFile(\"ScriptLibrary\");\nvar timestamp = new Date();\nfFile[\"name\"] = \"test_\"+timestamp.getTime();\nfFile[\"package\"] = \"User\";\n\nvar rcInsert = fFile.doAction(\"add\");"
   }
}

 

 

 (My response looks a bit different, because I have defined the available fields in the extaccess)

As you can see in the "Messages", the ScriptLibrary was executed and my new SL record was created successfully.

 

But you should also check the ServiceCatalogAPI Implementation, which uses the Action Type "Application Pass Through" and the "Custom Action to Perform".

The "Custom Action to perform" is defined in the table "extactions"

 

Hope that helps.

If there are any questions, feel free to ask 🙂

 

Highlighted
Regular Contributor.. Regular Contributor..
Regular Contributor..

Hi,

Thanks a bunch for your quick help with details steps. Really appreciate it man. 🙂

By the way, i followed your steps untill 15 and cannot continue from 16th. Opening "http://localhost:13080/SM/9/rest/ScriptLibrary" showing a blank page. URL "http://localhost:13080/SM/9/rest" working but "http://localhost:13080/SM/7/rest/ScriptLibrary" doesn't work.

I restarted the SM server and tried "http://localhost:13080/SM/9/rest/ScriptLibrary" and it prompts authentication. Where to set the auth user/password for this?

We are using HP SM 9.41. 

Help advice again, thanks

0 Likes
Highlighted
Honored Contributor.. Honored Contributor..
Honored Contributor..
Hey,

Sorry for the late response.

Username and password can be set in the operator table (shortcut: operator).

Please ensure, that the user has the capability for The REST API (don't know the exact capability word ).

For the RESTful API the /SM/9/rest in the URL is required - SM/7/ is (if I'm not wrong) only for the SOAP API.

View solution in original post

Highlighted
Regular Contributor.. Regular Contributor..
Regular Contributor..

Hi,

Thanks a lot for your great guidance. Appreciate it. 
Finally, i managed to call the simple Script from REST API. 🙂

Can u share if there is any documentation on steps to create sample ScriptLibrary as ur advice?

Thanks again.

0 Likes
Highlighted
Regular Contributor.. Regular Contributor..
Regular Contributor..

Hi,

I missed to ask about POST params. How to read POST parameter which sent via REST calls in scriptLibrary ?

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.