Automic Workload Automation

 View Only
Expand all | Collapse all

AE 12.1 - Test Automation Engine REST API with SOAP UI - beginner level

Legacy User

Legacy UserDec 06, 2017 05:17 AM

  • 1.  AE 12.1 - Test Automation Engine REST API with SOAP UI - beginner level

    Posted Dec 05, 2017 06:46 AM
    Hello,

    As some support cases recently came in about this feature, I thought it may be interesting to see a simplified use case of the AE REST API.

    We'll see how to generate a REST API call to activate a script and pass a variable at activation.


    1 - Create a simple job or script with the following attributes

    • "Generate at runtime" is enabled
    jt5xv89q4dos.pnghttps://us.v-cdn.net/5019921/uploads/editor/ff/jt5xv89q4dos.png" width="1600">

    • Process or pre-process tab contains one or several:READscript statements to receive the variable sent by the API.

    Example : SCRI.STARTED.VIA.REST_API
    :READ &VARA_SENT_BY_REST#,,
    :PRINT &VARA_SENT_BY_REST#


    2 - Create a new REST Project under SOAPUI


    The url must be <Automation Engine's server hostname>:<port of the JCP>

    wvi5fp9c41ub.pnghttps://us.v-cdn.net/5019921/uploads/editor/eb/wvi5fp9c41ub.png" width="471">


    Set the request as follows:
    • Method : POST
    • Resource : ae/api/v1/<client #>/executions

    sgham4m5i0pa.pnghttps://us.v-cdn.net/5019921/uploads/editor/bv/sgham4m5i0pa.png" width="734">


    Set the "media Type" to "application/json" and type in the query below:

    t26j6joica9w.pnghttps://us.v-cdn.net/5019921/uploads/editor/9y/t26j6joica9w.png" width="435">

    {
         "object_name":"SCRI.STARTED.VIA.REST_API",
         "inputs":
         {
              "VARA_SENT_BY_REST#":"Variable successfully sent"
         }

    }

    Type in your AE user credentials in the "Request Properties"

    egu2uvlolyin.pnghttps://us.v-cdn.net/5019921/uploads/editor/1h/egu2uvlolyin.png" width="429">


    3 - Run the REST call


    Your objects should now be ready to use. Just hit the "Play" button :

     la5p84v954n3.png

    And look for the results in the JSON section:

    ozp8kwhea0j2.pnghttps://us.v-cdn.net/5019921/uploads/editor/gc/ozp8kwhea0j2.png" width="202">


    You can see the task was activated in the Process Monitoring tab:

    4h5l8vbv261s.pnghttps://us.v-cdn.net/5019921/uploads/editor/95/4h5l8vbv261s.png" width="1160">

    And the variable set in the REST call was successfully passed on to the script:

    u6xptt11ad72.pnghttps://us.v-cdn.net/5019921/uploads/editor/rd/u6xptt11ad72.png" width="718">


    Best regards,
    Antoine



  • 2.  AE 12.1 - Test Automation Engine REST API with SOAP UI - beginner level

    Posted Dec 05, 2017 07:39 AM
    ... or just start powershell.exe (v3+) and type:
    Invoke-RestMethod `      -Headers @{'Authorization'= ('Basic ' + [convert]::ToBase64String((usr:pwd').ToCharArray()))} `      -Uri 'http://server:8080/ae/api/v1/8000/executions' `      -Method POST `      -Body (ConvertTo-Json -Depth 5 -Compress @{ object_name = "OBJECT_TO_START" }) `      -ContentType 'application/json'
    Replace usr / pwd / server / OBJECT_TO_START accordingly :-). Cheerio Joel


  • 3.  AE 12.1 - Test Automation Engine REST API with SOAP UI - beginner level

    Posted Dec 05, 2017 10:02 AM
    Hi Joel,

    Thanks for your interesting input, but... It doesn't work at my end.

    I tried using this :
    Invoke-RestMethod '
    -Headers @{'Authorization'= ('Basic' + [convert]::ToBase64String(('
    <user>:<pw>').ToCharArray()))} `
         -Uri 'http://vviesup06:8088/ae/api/v1/22/executions''
         -Method 'POST'
         -Body (ConvertTo-Json -Depth 5 -Compress @{ "object_name" = "SCRI.STARTED.VIA.REST_API" }) `
         -ContentType ('application/json')''

    And got these errors:
    Invoke-RestMethod : A positional parameter cannot be found that accepts argument 'Authorization= (Basic +
    [convert]::ToBase64String((<user>:<pw>).ToCharArray()))} `
         -Uri http://<server>:8088/ae/api/v1/22/executions'.
    At C:\Users\saa\Desktop\REST_CALL_Powershell_2.ps1:1 char:1
    + Invoke-RestMethod '
    + ~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Invoke-RestMethod], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

    -Method : The term '-Method' is not recognized as the name of a cmdlet, function, script file, or operable program.
    Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At C:\Users\saa\Desktop\REST_CALL_Powershell_2.ps1:4 char:6
    +      -Method 'POST'
    +      ~~~~~~~
        + CategoryInfo          : ObjectNotFound: (-Method:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException

    -Body : The term '-Body' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
    the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At C:\Users\saa\Desktop\REST_CALL_Powershell_2.ps1:5 char:6
    +      -Body (ConvertTo-Json -Depth 5 -Compress @{ "object_name" = "SCRI.STARTED.V ...
    +      ~~~~~
        + CategoryInfo          : ObjectNotFound: (-Body:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException

    I'm using Powershell 4.

    Best regards,
    Antoine


  • 4.  AE 12.1 - Test Automation Engine REST API with SOAP UI - beginner level

    Posted Dec 05, 2017 11:06 AM
      |   view attached

    Hi Antoine

    On the first line of your code you have a ' instead of a `. Then you seem to have added a few more ' in the code. I attached the code as text-file including a one-liner with less `-es ;-).

    Attachment(s)

    txt
    rest.txt   701 B 1 version


  • 5.  AE 12.1 - Test Automation Engine REST API with SOAP UI - beginner level

    Posted Dec 05, 2017 11:22 AM
    Thanks Joel,

    I works a lot better, but I now get :
    Invoke-RestMethod : { "code" : 45107, "error" : "Cannot logon to Automation Engine.", "details" : "The credentials
    (user/dept/pwd) are not valid." }
    At line:1 char:1
    + Invoke-RestMethod -Headers @{'Authorization'= ('Basic' + [convert]::ToBase64Stri ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
       eption
        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
    I tried different combinations:

    • '<user>:<pw>'
    • '<user/dept>':'<pw>'
    • '<user>':'<dept>':'<pw>'
    • '<user>:<dept>:<pw>'
    • ...
    But always end getting the same error. Credentials should be valid, but I wonder if the issue could be coming from the convert part?
    [convert]::ToBase64String(('user/dept:pwd').ToCharArray()))

    Best regards,
    Antoine


  • 6.  AE 12.1 - Test Automation Engine REST API with SOAP UI - beginner level

    Posted Dec 05, 2017 11:28 AM

    Hi Antoine

    You already received the JSON answer from Invoke-RestMethod. This means that the request has been successfully sent to the AE REST service and the service returned an errorneous http code and a JSON response:

     { "code" : 45107, "error" : "Cannot logon to Automation Engine.", "details" : "The credentials
    (user/dept/pwd) are not valid." }

    The errorneous http code causes the invoke-restmethod to throw an error, that's why everything turns red :-).

    Did you replace the "user/dept:pwd" string according your username/department/password?

    Regards
    Joel



  • 7.  AE 12.1 - Test Automation Engine REST API with SOAP UI - beginner level

    Posted Dec 05, 2017 11:44 AM

    Did you replace the "user/dept:pwd" string according your username/department/password?

    Of course I did :)

    Same user/dept/password work fine when logging in the AWI, or with SOAPUI... Obviously it's "corrupted" in the way (or I need some rest - without the API :D)


    Best regards,

    Antoine



  • 8.  AE 12.1 - Test Automation Engine REST API with SOAP UI - beginner level

    Posted Dec 05, 2017 04:59 PM
    Without getting into the details of this specific use-case, I just wanted to throw out there that I'm successfully using the Powershell Invoke-RestMethod command from UC4 to post messages to Slack;

    $postSlackMessage = @{token="[PutYourLegacyTokenHere]";channel="#&SLACKCHANNEL#";text="&SLACKTEXT#";username="&SLACKUSERNAME#"}
    Invoke-RestMethod -Uri https://slack.com/api/chat.postMessage -Body $postSlackMessage



  • 9.  AE 12.1 - Test Automation Engine REST API with SOAP UI - beginner level

    Posted Dec 06, 2017 01:54 AM

    Hi Antoine

    If you used the one-liner - I just saw that 'Basic' is missing a space ('Basic '). That would explain that the authentication fails.

    Regards
    Joel



  • 10.  AE 12.1 - Test Automation Engine REST API with SOAP UI - beginner level

    Posted Dec 06, 2017 04:12 AM
    Hi Joel,

    Tried again this morning and it worked !!
    Thanks very much :)

    Best regards,
    Antoine


  • 11.  AE 12.1 - Test Automation Engine REST API with SOAP UI - beginner level

    Posted Dec 06, 2017 05:17 AM
    Seems like the REST was necessary ;-)


  • 12.  AE 12.1 - Test Automation Engine REST API with SOAP UI - beginner level

    Posted Jan 23, 2018 12:33 PM
    Hi all,

    Many thanks to Joel and to Antoine for all this precious information and hints!

    I am now able to trigger a job either via SOAP UI:

    k2h9fllp17a9.pnghttps://us.v-cdn.net/5019921/uploads/editor/sy/k2h9fllp17a9.png" width="1126">

    or via the powershell instruction:

    Invoke-RestMethod -Headers @{'Authorization'= ('Basic ' + [convert]::ToBase64String(('***/***:***').ToCharArray()))} -Uri 'http://192.168.41.***:8088/ae/api/v1/22/executions'-Method 'POST' -Body (ConvertTo-Json -Depth 5 -Compress @{object_name = "JOBS.UNIX.JOB" }) -ContentType 'application/json'

                                                                                                                     run_id

                                                                                                                     ------

                                                                                                                    1062008

    My customer wants to be able to trigger the execution of his job at a special time. This can be achieved in One Automation via 'Execute Once'.

    qo0guwjp7yea.pnghttps://us.v-cdn.net/5019921/uploads/editor/5n/qo0guwjp7yea.png" width="581">

    How is it possible to integrate in a json API call this kind of parameters?


    Best Regards

    Pascal









  • 13.  AE 12.1 - Test Automation Engine REST API with SOAP UI - beginner level

    Posted Feb 16, 2018 04:25 AM
    Hi Pascal

    AFAIK this is yet not possible with the REST API. What you could do is:
    - use an inbetween object that is started immediately and takes a promptset input parameter with start time. Then in the objects' script use :ACTIVATE_UC_OBJECT with start time in future
    - refer to my WorkflowCommander Powershell module (see more details in footer or PM me) which is capable of doing that w/o the REST API ;-)

    Regards
    Joel


  • 14.  RE: AE 12.1 - Test Automation Engine REST API with SOAP UI - beginner level

    Posted Apr 12, 2022 08:14 AM
    Edited by Antony Beeston Apr 13, 2022 08:45 AM
    Thank you for your information .