Forum Discussion

RobertDAltman's avatar
RobertDAltman
Occasional Contributor
8 years ago

Calling a REST API from a keyword test

Ok... I've looked at the docs and searched the web, and I can't believe I haven't found an obvious answer to this question: Is there an easy way for me to call a REST API during my keyword test and easily extract an answer from the result? Here are a couple of scenarios I need to implement:

 

  • I want to call the API at https://validator.w3.org/nu to validate the HTML markup on each of my web pages
  • As part of my website's "Forgot my password" workflow, the user has to enter a validation code that I send to the user's phone. I would like to expose an API on my website that returns the validation code for my "test user" account, so that I can fetch the validation code and enter it on the page in my workflow where the user would read it from the phone and manually enter it.

 

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    In TestComplete 12.40+, you can use the Send Request operation to call REST APIs.

    • RobertDAltman's avatar
      RobertDAltman
      Occasional Contributor

      Not sure if it's better to "reply" or to post a new question.  Guess I'll find out...

       

      Ok, so now that I've successfully called my REST API from my keyword test, how do I parse the result (presumably JSON, although I can just as easily return XML)?  Do I need to roll my own script code or is there something in the world of keyword tests that will help me?  And if I need to write script code, is there anything in that world that makes it easy to parse parameter values out of the JSON returned by the previous operation?

      • RobertDAltman's avatar
        RobertDAltman
        Occasional Contributor

        Never mind the "follow up" question about parsing the result... I asked about that as a separate question.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    You can include the "WebServices" object in your project and utilize that for consuming API's.  

    • HKosova's avatar
      HKosova
      SmartBear Alumni (Retired)

      tristaanogre wrote:

      You can include the "WebServices" object in your project and utilize that for consuming API's.  


      The WebServices project item is for SOAP services only.