Does anybody have good ModScript example of using a Rest API for external app or website. For example the following javascript code using XMLHttpRequest.
Cybersecurity
DevOps Cloud
IT Operations Cloud
If an answer to your question is correct, click on "Verify Answer" under the "More" button. The answer will now appear with a checkmark. Please be sure to always mark answers that resolve your issue as verified. Your fellow Community members will appreciate it!  Learn more
Does anybody have good ModScript example of using a Rest API for external app or website. For example the following javascript code using XMLHttpRequest.
Hi Jason, check out these resources:
https://docs.microfocus.com/doc/Solutions_Business_Manager/12.0/ttst_about_rest_data_sources
https://docs.microfocus.com/doc/Solutions_Business_Manager/12.0/modscript_introductiontoteamscript
https://community.microfocus.com/it_ops_mgt/sbm/w/sbm_tips/3577/sbm-modscript-part-8---rest-callouts
https://docs.microfocus.com/doc/Solutions_Business_Manager/12.0/modscript_restdatasource
https://docs.microfocus.com/doc/Solutions_Business_Manager/12.0/modscript_samplerestdatasource
In short, this will take you through the topics of setting up a REST Data source and consuming it via ModScript.
Hi Garry,
Thank you for your reply, I saw those examples earlier. I tried to follow the along with the example but doesn't make sense. SBM Modscript examples for reset callouts seems like missing the sample application.
I am new to modscript and these documentation are not very clear. I would like to see more simple examples for GET, POST, PUT, DELETE for rest API to other applications.
Can you clarify your intended use cases? The example (https://docs.microfocus.com/doc/Solutions_Business_Manager/12.0/modscript_samplerestdatasource) basically shows how to consume a REST Data source to read items from SBM using the REST/JSON API call GetItemsByListingReport.
It assumes that the Data source has already been defined in Composer (and in this case is named "AE")
https://docs.microfocus.com/doc/Solutions_Business_Manager/12.0/modscript_restdatasource shows the supported object methods and http methods (namely GET and POST, not PUT nor DELETE).
This example (https://community.microfocus.com/it_ops_mgt/sbm/w/sbm_tips/3577/sbm-modscript-part-8---rest-callouts) is more advanced, but still doesn't get you to a point of using additional HTTP methods.
Garry,
Thanks for your response, I'll look at those examples.
My intended use case is to have SBM make Rest API call into another system (Ticketing system). I will be passing few SBM fields into this system (For example, Title, Description etc.,). When making the Rest Post call, it should receive back Ticketing System ID in SBM for reference. I currently have it working through JavaScript at transition. I would like to get it working at state form where they click a button or quick transition. Currently if I call the JavaScript from a button or quick transition, it does not update field in SBM for the return Ticketing System ID.
I think Orchestrations may be the ideal place for that type of integration. Javascript approaches are based on form technology and that does not support quick transition use cases. You could probably also use Modscript instead of orchestrations for what you have described so far.
And if you were trying to say that you were putting javascript on a state form with the intention of updating SBM, that generally won't work. You need to be IN a transition to update an SBM record (aka Transition form). The only way via a State form would be to invoke an SBM transition via your javascript - at this point technically you would be using web services to update SBM, not the Javascript API operations like SetFieldValue.
Orchestrations is something I looked at and ran into a issue. I tried setting up endpoint in repository to get the access token using OAuth2 Authentication but that will not work since it does not have all the required fields I need to make the request. The external app API requires body text to be sent when requesting token. Which consist of username/password, client_secret, and client_id, and grant_type.
I was able to get the token access using orchestrations by creating a post request then getting the token back and then creating another service post step to create ticket into the external app API. This seems to fail at sending the correct headers with token. I do have the debugging on and seems like JSON data its passing is formatted correctly by pasting same data into postman.
Following is the required headers:
("Accept", "application/json")
("Content-type", "application/json")
("Authorization", "Bearer " + token)
Any suggestions ?
Hi Jason, Your questions are starting to get deeper than I can easily support via the forum.
This section of the help discusses the RESTCaller: https://docs.microfocus.com/doc/Solutions_Business_Manager/12.0/ttst_restcaller_chapter
This portion of the help talks about the options for building the request body and passing headers: https://docs.microfocus.com/doc/Solutions_Business_Manager/12.0/ttst_restcaller_arguments
The process of authenticating that you described resembles how you would authenticate to SBM's RESTful services as well. This can be achieved via an orchestration: https://docs.microfocus.com/doc/Solutions_Business_Manager/12.0/json_api_requesting_security_token
I do not have first hand experience with OAuth2 and the RESTCaller. However, this page may help: https://docs.microfocus.com/doc/Solutions_Business_Manager/12.0/ar_configuring_oauth_security
In general, try to let the endpoint definition do as much of the heavy lifting as possible.
I work in Micro Focus Professional Services. If you think you would like some dedicated assistance from our team, let me know and we can schedule a call to help scope the effort and provide a quote.