Unable to send API request due to sendRequest is not being recognized

def response = WS.sendRequest(findTestObject(‘IRN’, [(‘irn’) : GlobalVariable.irn, (‘breederReference’) : GlobalVariable.breederReference
, (‘token’) : GlobalVariable.token, (‘attachmentUrl’) : GlobalVariable.attachmentUrl]))

I am unable to send API request due to sendRequest is not being recognized.
This keyword was working earllier. Am I missing something here?

Earlier I was using version 8.3.5 and now updated to 8.6.8

1 Like

I do not see what you mean “is not being recognized”. Please elaborate this.

WS.sendRequest is underlined

1 Like

Possibly you need the following import statement:

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

Thanks but I am already using this import statement :slightly_frowning_face:

When I am executing the script, I am getting below error:

Caused by: com.kms.katalon.core.exception.StepFailedException: Unable to send request (Root cause: java.lang.IllegalArgumentException: URI is not absolute

Same script was working fine earlier but not working now

The underline in Katalon Studio does not necesarrily mean that “sendRequest” is not recognized.

Katalon Studio is a bit buggy for the underlining.

You should show the error messages you got. The message would tell others what your problem really is.

You have raised a topic for the same issue already:

Why did you make a dual post?

You shouldn’t do it.

@himanisaxena19

Can u share the URL you added in the Global variable?

It is a pre-signed url, which will generate in runtime.
URL’s value is not fixed, it will change in every execution

@himanisaxena19

even if it is a pre-signed URL it will be temporary try to print the URL and check manually the URL is valid or not

2023-10-17 12:48:47.693 DEBUG testcase.CreateIRN API - 14: println(attachmentUrl)
null

I am getting null when tried printing the url.
Earlier same script was generating pre-signed url

the issue is due to the URL is not generated out of it i think pls check with your developers for the same.

Same request is working fine with Postman

I am using below script:

def response = WS.sendRequest(findTestObject(‘IRN’, [(‘irn’) : GlobalVariable.irn, (‘breederReference’) : GlobalVariable.breederReference
, (‘token’) : GlobalVariable.token, (‘attachmentUrl’) : GlobalVariable.attachmentUrl]))

WS.verifyResponseStatusCode(response, 200)

println(GlobalVariable.irn)
println(GlobalVariable.breederReference)
println(GlobalVariable.token)
println(GlobalVariable.attachmentUrl)

GlobalVariable.attachmentUrl = WS.getElementPropertyValue(response, ‘apiResponseData.attachmentUrl’, FailureHandling.STOP_ON_FAILURE)

println(GlobalVariable.attachmentUrl)

def respnsePut = WS.sendRequest(findTestObject(‘SendAttachment’, [(‘attachmentUrl’) : GlobalVariable.attachmentUrl]))

is it ok or some issue with the script?

Could you please try the below script @himanisaxena19

// Define the global variables.
def irn = GlobalVariable.irn
def breederReference = GlobalVariable.breederReference
def token = GlobalVariable.token
def attachmentUrl = GlobalVariable.attachmentUrl

// Send the first request to get the attachment URL.
def response = WS.sendRequest(findTestObject(‘IRN’),
[(‘irn’): irn, (‘breederReference’): breederReference, (‘token’): token])

// Verify the response status code.
WS.verifyResponseStatusCode(response, 200)

// Get the attachment URL from the response.
attachmentUrl = WS.getElementPropertyValue(response, ‘apiResponseData.attachmentUrl’, FailureHandling.STOP_ON_FAILURE)

// Update the global variable with the attachment URL.
GlobalVariable.attachmentUrl = attachmentUrl

// Send the second request to send the attachment.
def responsePut = WS.sendRequest(findTestObject(‘SendAttachment’), [(‘attachmentUrl’): attachmentUrl])

// Verify the response status code for the second request.
WS.verifyResponseStatusCode(responsePut, 200)

I am getting below error after updating request

Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/C:/Users/hsaxena/Desktop/Updated%20Test%20Pack/automation-test/Scripts/API%20Test%20Cases/CreateIRN%20API/Script1672121117054.groovy: 35: Invalid variable name. Must start with a letter but was: ‘IRN’
. At [35:46] @ line 35, column 46.
WS.sendRequest(findTestObject(‘IRN’),

Yes , check the variable IRN name once whether it is as per your script? i think it is in lower case : irn

Please adjust and then check.

Getting same issue with lower case :
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/C:/Users/hsaxena/Desktop/Updated%20Test%20Pack/automation-test/Scripts/API%20Test%20Cases/CreateIRN%20API/Script1672121117054.groovy: 35: Invalid variable name. Must start with a letter but was: ‘irn’
. At [35:46] @ line 35, column 46.
WS.sendRequest(findTestObject(‘irn’),

I need unique value in irn so I am using below line:
GlobalVariable.irn = (‘XU_’ + CustomKeywords.‘commonFunctions.CommonMethods.dateGenerator’())

Is the issue related to the declaration?

i assume yes , it is not being correctly declared. can u solve this and then again check. Is your custom keyword returning a valid value?

I need unique values for each run, If I will use
def irn = GlobalVariable.irn
for declaration, how the values will get generated?

Below line was also working earlier
GlobalVariable.irn = (‘XU_’ + CustomKeywords.‘commonFunctions.CommonMethods.dateGenerator’())

GlobalValue.irn doesnot seem to be an issue here