ktimbal-LNR
21 days agoMember
Proper Way of Creating API Interface Using Script
Hi, I would like to know the proper way of creating an API service using groovy script. I am using the code below, but when creating for a REST Request it seems that the endpoint is not showing even if I pass a value on it. I cannot also add environment and authorization profile to the interface. I also noticed when creating the interface manually the specification is in the form of JSON vs WADL when created via script. Any help is very appreciated, many thanks!
Edit
I am using version 3.59.0.
import com.eviware.soapui.impl.rest.RestServiceFactory
import com.eviware.soapui.impl.rest.RestRequestInterface
def project = context.testCase.testSuite.project
def endpoint = "https://sample.endpoint.com"
if (!project.getInterfaceByName("NewRESTService")) {
def restService = project.addNewInterface("NewRESTService", RestServiceFactory.REST_TYPE)
restService.addEndpoint(endpoint)
def resource = restService.addNewResource("NewResource", "/NewResource")
def method = resource.addNewMethod("Method 1")
method.method = RestRequestInterface.HttpMethod.POST
def request = method.addNewRequest("Request 1")
request.mediaType = "application/json"
// Following line of codes are tested to pass endpoint but to no avail
request.setEndpoint(endpoint)
request.endpoint = endpoint
request.setPropertyValue("Endpoint", endpoint)
log.info request.getEndpoint()
//---END---//
request.authProfile = "BasicAuthProfile"
log.info request.getAuthProfile()
}