Service Virtualization

Expand all | Collapse all

How to use 'createService' REST API operation?

Jump to Best Answer
  • 1.  How to use 'createService' REST API operation?

    Posted 10-07-2016 03:06 PM

    Hi, community.

    We are facing a scenario where we need to create and update (i.e. re-create with overwrite) MANY virtual services based on RR pairs. Our ideia is use the REST API to do it automatically, but we can use commmad line calls if needed.

    POST /VSEs/{serviceName}/actions/createService

    On re-creation we need to keep the same listen port, to avoid change on consumer side every time.

     

    We found in the documentation the option to use a 'serviceProperties.xml' to set the listen port. For example:

    <listenPort>8900</listenPort>

     

    https://docops.ca.com/devtest-solutions/9-5/en/reference/rest-invoke-api/create-a-virtual-service-from-r-r-pairs-using-the-rest-invoke-api

     

    But I was unable to figure out how create the POST request to use the 'createService' API operation; specially how to 'upload' the files. In fact, our question is more retaled to REST use.

    Someone can show me an example?

     

    We will automate everything using Python or Java, but first we need to understand the messages formats.


    For testing purpose I tried to create on the Portal also, but it doesn't accept the 'serviceProperties.xml' file.

    Thank's in advance.

    Gabriel Stabel



  • 2.  Re: How to use 'createService' REST API operation?

    Posted 10-13-2016 03:07 PM

    We understood the API documentation and tried it with POSTMAN.

    Now we are getting an error like there is no file content:

            com.itko.lisa.invoke.api.exception.BadRequestException: File is not provided

     

    But, as you can see in the image below, the content is being sent:

     

    Postman and Fiddler



  • 3.  Re: How to use 'createService' REST API operation?

    Posted 10-13-2016 06:37 PM

    Can you show a listing of what you have inside the zip file?



  • 4.  Re: How to use 'createService' REST API operation?

    Posted 10-14-2016 10:28 AM

    I have tried with many ZIP files, always with RR pairs inside (sometimes without the serviceProperties.xml).

    For example, a ZIP file with two dummy files inside like this:

     

    File: order1-req.txt

    <order>
    <id>1-11</id>
    <name>Nut</name>
    <product>2mm nut</product>
    </order>

    File: order1-rsp.txt

    <order>
    <id>1-11</id>
    <name>Nut</name>
    <quantity>47</quantity>
    </order>

     

    I'm always getting a File is not provided error.

     

    Tks, Gabriel.



  • 5.  Re: How to use 'createService' REST API operation?
    Best Answer

    Posted 10-14-2016 11:45 AM

    I just used your RR pairs in a zip file and am able to invoke and create the VS.

     

    Here is a screenshot from Postman - 

     

     

    Based on the screenshot, go ahead and give it a shot and let me know if you are not able to still generate a VS.



  • 6.  Re: How to use 'createService' REST API operation?

    Posted 02-26-2018 04:25 AM

    Hi KOUSTUBH,

     Can you also please share, what details need to be add in Authorization and Headers tab? I'm getting 401 unauthorized error in response



  • 7.  Re: How to use 'createService' REST API operation?

    Posted 10-14-2016 11:37 AM

    <removed previous comment>  Updated: Koustubh was correct.  I got it to work when I switched to postman and used VSE for the serviceName.  Some of my properties file elements -- such as service name and port -- did not seem to take affect.  Will need to do some additional research.

     

     

     



  • 8.  Re: How to use 'createService' REST API operation?

    Posted 02-28-2017 06:52 AM

    Hi J_NeSmith , 

    did you find anything on your below comment

    " Some of my properties file elements -- such as service name and port -- did not seem to take affect.Will need to do some additional research.".  if so kindly share your findings.

     

    Regards,

    Balamurugan



  • 9.  Re: How to use 'createService' REST API operation?

    Posted 02-28-2017 07:22 AM

    Hi Balamurugan, I did not find anything out.  My guess is that I made an error during in the setup.



  • 10.  Re: How to use 'createService' REST API operation?

    Posted 10-16-2016 06:57 PM

    Thank you Koustubh.Warty. I paid attention in your print screen I saw that you use 'file' instead of 'body' in your variable's name. I changed and it works.
    As you can see in the image below, it is wrong in the APIs documentation. See below.

     



  • 11.  Re: How to use 'createService' REST API operation?

    Posted 02-28-2017 11:19 AM

    Hello Gabriel,

     

                 The body here refers to either the file or the file URI. If you look at the example shared by Koustubh, the file attachment goes into the body section of the request. Please let me know if that answers your question.  

     

    Form Parameters

    filejava.io.InputStream
    An uploaded zip file that contains request response pairs.
    fileURIstring
    URI to a zip file. Only "file" and "http" protocol are supported.