Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

REST API - Create PVA from Traffic File

Looking for examples of creating a PVA from a traffic file using the REST API. Any information or sample code would be greatly appreciated. Thanks, JT

Comments

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,
    It sounds like you would want to use the resource "POST /v6/files/pvas/traffic" which will need a traffic file uploaded to the server. An example payload might be
    { "repositoryConnectionSettings": { "port": 2424, "host": "dataRepositoryServer", "repositoryName": "createPvaFromTraffic", "password": "admin", "user": "admin" }, "name": "createPvaFromTraffic", "parent": { "id": "/CreateFromTraffic" }, "trafficFile": { "id": "/uploads/Traffic.txt" }, "characterEncoding": "UTF-8" }

    You'll want to replace most of these values with your own but in this example we are creating a pva called "createPvaFromTraffic" in a project named "CreateFromTraffic" in the workspace. We are using a traffic file in the workspace located at "/uploads/Traffic.txt" and the data for messages will be put into the repository with connection settings specified.

    To try it out there is a useful api documentation page that you can find on the server be opening a browser and going to http://::9080/soavirt/api and you can find the resource mention and test out different payloads.

    Hope this helps!

  • jefftuckerbofa
    jefftuckerbofa Posts: 229

    Thanks for the information. I am using the example you provided, adjusted slightly to match my setup. Getting a 404 stating that it can not find the /uploads/Traffic.txt file. Tells me to fix the trafficFile.id.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,
    Where did you upload your traffic file to? The traffic file needs to be in the workspace on the server and that id should be changed to be the id of where your traffic file is.

  • jefftuckerbofa
    jefftuckerbofa Posts: 229

    I was able to get it to find the traffic file. I'm at the point now where I am trying to create a template file to go along with the request.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    A template should not been needed if you specify the repository settings. If you need some non default settings then yes create a template using the desktop then upload it to the server.

    Hope this helps!

  • jefftuckerbofa
    jefftuckerbofa Posts: 229

    I created a data repository called createPvaFromTraffic in the embedded server. What port does that listen on? Thanks.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    The embedded data repository is not very portable. It's meant to be for your local testing but other servers won't be able to use that data repository. Is it possible to use a remote repository rather than the embedded one?

  • jefftuckerbofa
    jefftuckerbofa Posts: 229

    Not at the moment. My employer just recently inked the deal to migrate to this product and we don't have full access to the infrastructure. I'm one of the early adopters. I am ok using the embedded server at this stage. I realize it will not be used in the final implementation of the tools I am creating.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Ok, I think if you create the template it should have the settings for the embedded repository saved in it. In the payload to the REST api leave out the "repository" object and just set the template. It should find the settings in the template file.

  • jefftuckerbofa
    jefftuckerbofa Posts: 229

    I wasn't able to find where to create the template. Sorry, I've been a CA SV guy for quite some time. Trying to get familiar with a new product here.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    No worries :smile:

    To create a template proceed through the traffic wizard in the desktop to create the pva file. Go all the way to the last step of the wizard, before clicking finish click the box to say you want a template and pick a file name plus location. See attached screenshot.

  • jefftuckerbofa
    jefftuckerbofa Posts: 229

    Awesome. Thanks. I believe I should be able to take it from here. Much appreciated!

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Happy to help!

  • jefftuckerbofa
    jefftuckerbofa Posts: 229

    So, if I generate the VirtualAsset using /soavirt/api/v5/files/pvas/traffic without specifying a traffic template, is the default simply Fixed Message responders?

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Without a template I believe it will create parameterized responders and the api should require that you provide data repository information.

  • jefftuckerbofa
    jefftuckerbofa Posts: 229

    Thanks. I didn't see an option to download a traffic template when I went through the Fixed flow. And, looking at the template that was created in the Parameterized flow I didn't see anything that looked like a way to change to Fixed.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi,
    I don't think traffic templates are supported for fixed traffic wizard. The rest api mentioned is for parameterized responders and doesn't create fixed traffic.

    You want to automate the creation of fixed responders from traffic using the rest api?

  • jefftuckerbofa
    jefftuckerbofa Posts: 229

    I'll wait until I do a little more research on parameterized responders before I answer that.. ;-)

  • jefftuckerbofa
    jefftuckerbofa Posts: 229

    There was a script posted in another discussion that referenced a "v6" API endpoint. Is that in the GA release now? I get a 404 and I do not see it referenced in the API docs.

    Get the Deployment ID

    response=$(curl -vs \
    --user $VIRT_USER:$VIRT_PASS \
    -X GET \
    -H "Accept: application/json" \
    "http://$VIRT_HOST:$VIRT_PORT/soavirt/api/v6/virtualAssets?fields=id&pvaLocation=/VirtualAssets/$VA_SUBFOLDER/$ASSET_NAME.pva")

    DEP_ID=${response:25:50}
    echo $DEP_ID

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    That version of the api should be in the 9.10.7 release. Also v5 has that same resource so you should be able to use that older version.