Automation Testing

soapUI How to Post JSON to a REST Service

By Test Guild
  • Share:
Join the Guild for FREE
API Testing

Since my previous post on How to Test a REST Web Service, I've received a few requests asking for an example using JSON. I originally wrote this in 2013 and wanted to see if it still worked. 

In this post, I’ve shared:

  • how to setup Apache CouchDB – a kind of authentication
  • the updated steps for how to post JSON to a REST service using soapUI for 2022

INDEX
POST JSON to a REST service using soapUI
Setup – CouchDB
How to use soapUI to send JSON to a REST API|
Rest Easy

POST JSON to a REST service using soapUI

So as requested, here is a quick example of how POST JSON to a REST service using soapUI.

Setup – CouchDB

To make this example as easy as possible, without having to set up any sort of authentication, I've decided to use Apache CouchDB. 

CouchDB is easy to install, stores data as JSON documents, and has an easy-to-use API to interact with it.

This makes it a great application to use to teach us more about REST testing with soapUI and JSON.

To install CouchDB go to:

    1. http://couchdb.apache.org/
    2. Click on Download and choose the version you want to us
    3. Once it's installed, enter http://127.0.0.1:5984/_utils/ in a browser. This should bring up your local CouchDB Futton website.
    4. Next, click on the Create Database and name it “soapUI.
    5. Navigate back to http://127.0.0.1:5984/_utils/index.html. Notice that soapUI shows 0 docs.

CouchDB soapUI database example

Automation Testing Training Courses

How to use soapUI to send JSON to a REST API

Here are the steps to follow to get started using the free version of soapUI with REST testing:

  1. Create a new empty project in soapUI. Enter Project Name: JSON. Click OK
  2. Right Click on the JSON project we just created and select New REST Service from URI
  3. In the New REST Service screen enter:

URI: http://127.0.0.1:5984/

SoapUI REST URI

 

  1. In the Request 1 enter:
  • Method: Post
  • Resource: soapUI

SoapUI POST REST Settings

  1. This is where most people get confused – authentication. 

If you setup a username and password for your CouchDB install, click on the Request 1 Authentication tab. From the Authorization dropdown, select Basic. Enter your username and password as well as the Domain: http://127.0.0.1:5984/. Make sure to also click on the Authenticate pre-emptively radio button.

 

SoapUI REST Authentication

6. In the text area under the Media Type, enter your JSON that you want to post. Let's keep it simple and create a JSON value that contains one name/value pair string: {“name”:JoeColantonio”}

JSON Key Values for SoapUI

7. Submit the Request 1. Notice in the response how it returns the value ok and an id

SoapUI REST Response

8. Go back to CouchDB. The soapUI DB should now have a value of 1 and should contain the name you just submitted:


Rest Easy

That's it! You can now rest easy in the knowledge that you now know how to!

Work With Me

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  1. Hi,

    I am getting the following response while posting the JSON content through REST service.Please help me out

    html>

    Error Message

    A {
    FONT-WEIGHT: bold; FONT-SIZE: 10pt; COLOR: #005a80; FONT-FAMILY: tahoma
    }
    A:hover {
    FONT-WEIGHT: bold; FONT-SIZE: 10pt; COLOR: #0d3372; FONT-FAMILY: tahoma
    }
    TD {
    FONT-SIZE: 8pt; FONT-FAMILY: tahoma
    }
    TD.titleBorder {
    BORDER-RIGHT: #955319 1px solid; BORDER-TOP: #955319 1px solid; PADDING-LEFT: 8px; FONT-WEIGHT: bold; FONT-SIZE: 12pt; VERTICAL-ALIGN: middle; BORDER-LEFT: #955319 0px solid; COLOR: #955319; BORDER-BOTTOM: #955319 1px solid; FONT-FAMILY: tahoma; HEIGHT: 35px; BACKGROUND-COLOR: #d2b87a; TEXT-ALIGN: left
    }
    TD.titleBorderx {
    BORDER-RIGHT: #955319 0px solid; BORDER-TOP: #955319 1px solid; PADDING-LEFT: 8px; FONT-WEIGHT: bold; FONT-SIZE: 12pt; VERTICAL-ALIGN: middle; BORDER-LEFT: #955319 1px solid; COLOR: #978c79; BORDER-BOTTOM: #955319 1px solid; FONT-FAMILY: tahoma; HEIGHT: 35px; BACKGROUND-COLOR: #d2b87a; TEXT-ALIGN: left
    }
    .TitleDescription {
    FONT-WEIGHT: bold; FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: tahoma
    }
    SPAN.explain {
    FONT-WEIGHT: normal; FONT-SIZE: 10pt; COLOR: #934225
    }
    SPAN.TryThings {
    FONT-WEIGHT: normal; FONT-SIZE: 10pt; COLOR: #934225
    }
    .TryList {
    MARGIN-TOP: 5px; FONT-WEIGHT: normal; FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: tahoma
    }
    .X {
    BORDER-RIGHT: #955319 1px solid; BORDER-TOP: #955319 1px solid; FONT-WEIGHT: normal; FONT-SIZE: 12pt; BORDER-LEFT: #955319 1px solid; COLOR: #7b3807; BORDER-BOTTOM: #955319 1px solid; FONT-FAMILY: verdana; BACKGROUND-COLOR: #d1c2b4
    }
    .adminList {
    MARGIN-TOP: 2px
    }

    X

    Network Access Message:
    The page cannot be displayed

    Explanation:

    The Web server refused the connection.

    Try the following:

    Refresh page:
    Search for the page again by clicking the Refresh button. The timeout could have occurred due to Internet congestion.

    Check spelling:
    Check that the Web page address is spelled correctly. The address may have been mistyped.

    Access from a link:
    If there is a link to the page you are looking for, try accessing the page from that link.

    Contact website:
    You may want to contact the website administrator to make sure the Web page still exists. You can do this by using the e-mail address or phone number listed on the website home page.

    If you are still not able to view the requested page, try contacting your administrator or Helpdesk.

    Technical Information (for support personnel)

    Error Code 10061: Connection refused
    Background: The server you are attempting to access has refused the connection with the gateway. This usually results from trying to connect to a service that is inactive on the server.
    Date: 10/30/2013 8:45:58 AM [GMT]
    Server: INICG0029.in.int.atosorigin.com
    Source: Remote server

  2. Hi,

    I am trying to post some json data into a server using soap UI and REST api. I have created a POST request by passing the URL into Endpoint & Resource text fields at the top of soap UI. Parameters text filed i left it as empty. I had given json data like {“type”:”endpoint_resume”} to resume the paused end point but it doesn’t work. Even after running the test case, that particular endpoint was still in “paused” mode. Can some help me on this please ????

    Note : This is working when I used the curl command(post data using curl command) but not working using soap UI. FYI, there is no typo mistakes in URL too.. I need to check something else!!!!!!!!

  3. Great post!

    Well written and easy to follow.

    Helped me get my head around JSON in SOUPUI.

    Thank you for taking the time to do this post and other.

    A

  4. I enjoyed your video as well as the blog. Thanks for sharing. Unfortunately, SoapUI 4.6.4 is not bug free and cannot POST a JSON request: “Cancelled request due to invalid content”. I have resorted to using the RESTClient Add-On for Firefox for just this basic request/response. I might try and download an older version of SoapUI to get back on my feet.

  5. Hi Joe,
    Can you please leave some tips on building a test suite and automating them using SOAPUI and this is specifically for the REST API services and/or using Groovy scripts. I would be glad if I dont have to even use Groovy to setup my automation on SOAPUI.

    Thanks,
    Savitha

  6. if anyone is facing below error.
    cannot POST a JSON request: “Cancelled request due to invalid content”.

    then please go to settings/preferences – > Editor settings
    and uncheck “Abort invalid request” check box

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Continuous Testing in DevOps Bootcamp (2024 Guide)

Posted on 05/23/2024

One issue I often hear about on my podcast is the fact that ...

Mastering AI in Test Automation: Expert Tips!

Posted on 05/14/2024

Over the last couple of years, many of my podcast guests who work ...

What is Synthetic Monitoring? (2024 Guide)

Posted on 04/18/2024

I've found over the years many testers are unsure about what is synthetic ...