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.

Upload test case from local to remote using soatest rest api

asingh
asingh Posts: 14

Is it possible to upload your test cases from local to remote server using soatest rest api?

I found one api but I am not sure about the message body

http://paraosoft:9080/soavirt/api/v5/tools/copy

{
      "from": {
        "id": ""
      },
      "to": {
        "parent": {
          "id": ""
        },
        "name": ""
      }
    }

Could some one please help?

Tagged:

Comments

  • KrzysztofMarczyk
    KrzysztofMarczyk Posts: 6

    Hello,
    You can use soavirt/api/v5/files/upload endpoint to upload file to the remote server. You can find documentation and sample request under http://paraosoft:9080/soavirt/api#!/files/filesUpload

  • asingh
    asingh Posts: 14

    Thanks @KrzysztofMarczyk, can you also give me a example of request, look bit confusing to me?

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited May 2018

    The best way to see an example is to use the REST API docs: http://your_host_name:9080/soavirt/api#!/files/filesUpload

    The REST API docs have an explanation for each parameter in the message that you must configure. Additionally, there is a form where you can enter the value for each of those parameters and as well as a "Try it out!" button which will send the request. The request is a multi-part MIME message that looks something like this:

    POST /soavirt/api/v5/files/upload?deploy=false&replace=false HTTP/1.1
    Host: your_host_name:9080
    Content-Type: multipart/form-data; boundary=some_mime_boundary
    
    --some_mime_boundary
    Content-Disposition: form-data; name="data"
    
    data_param_value_goes_here
    
    --some_mime_boundary
    Content-Disposition: form-data; name="file"; filename="some_file_you_are_uploading"
    Content-Type: application/octet-stream
    
    contents_of_file_you_are_uploading_goes_here
    
    some_mime_boundary--
    
  • OmarR
    OmarR Posts: 233 admin

    To add to @benken_parasoft comment, You may choose to format the "Definition of fileUploadRequest" or the "data" section of the multi-part MIME message in XML or JSON.

    Below are two examples of a POST call to upload a file to a local server under the "/TestAssets" folder. The file will be called "myFileUpload.txt" and will contain the text "File Uploaded Successfully".

    Example 1:
    http://localhost:9080/soavirt/api/v5/files/upload?deploy=false&replace=false

    -----------------------------11241990
    Content-Disposition: form-data; name="data"
    Content-Type: application/json
    
    {"parent":{"id":"/TestAssets"}}
    -----------------------------11241990
    Content-Type: application/octet-stream
    Content-Disposition: form-data; name="file"; filename="myFileUpload.txt"
    
    File Uploaded successfully!!!!
    
    -----------------------------11241990--
    

    Example 2:
    http://localhost:9080/soavirt/api/v5/files/upload?deploy=false&replace=false

    -----------------------------11241990
    Content-Disposition: form-data; name="data"
    
    <?xml version="1.0" encoding="UTF-8"?><ns1:fileUploadRequest xmlns:ns1="http://www.parasoft.com/api/files/messages"><ns1:parent><ns2:id xmlns:ns2="http://www.parasoft.com/api/common/messages">/TestAssets</ns2:id></ns1:parent></ns1:fileUploadRequest>
    -----------------------------11241990
    Content-Disposition: form-data; name="file"; filename="myFileUpload_2.txt"
    Content-Type: text/plain
    
    File 2 Uploaded successfully!!!!
    
    -----------------------------11241990--
    

    If possible, I recommend trying any one of the above calls locally prior to uploading to a remote server. You may use a REST client or messaging client to get started. Let us know if you have any questions.

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited June 2018

    You may use a REST client or messaging client to get started

    If you do this, please read what I wrote here: How to send file in the REST client

  • asingh
    asingh Posts: 14
    edited June 2018

    @OmarR @benken_parasoft does that mean I have to paste entire tst xml in the message body using external tool like curl perhaps?

  • asingh
    asingh Posts: 14
    edited June 2018

    I found the answer, its simpler with curl

    curl -H 'Content-Type: multipart/form-data' -F data=@/mytest/data.txt -F file=@/mytest/mytest.tst http://parasoft:9080/soavirt/api/v5/files/upload?deploy=false&replace=true

    where data.txt is attached.

  • OmarR
    OmarR Posts: 233 admin

    nice! Thanks for sharing.

  • rvmseng
    rvmseng Posts: 89

    I think it would be very good if this feature be added in new version.

    This feature exist for "visualize" and also SOATest need it.