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

Same issue after updating to lower case

if you have already declared the variables , could you please remove this part below and then check again

def irn = GlobalVariable.irn
def breederReference = GlobalVariable.breederReference
def token = GlobalVariable.token
def attachmentUrl = GlobalVariable.attachmentUrl

I already tried this but no luck…same issue

is the below custom keyword working ok now (not asking about previous execution). can u check it somehow that it is working

CustomKeywords.‘commonFunctions.CommonMethods.dateGenerator’())

I hope this dateGeneartor doesnot result in invalid characters

Not sure how to do this but this time I tried after removing custom keyword line and getting same issue

I am using below script

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import internal.GlobalVariable

String breederRef

WebUI.refresh()

String token = 'Bearer ’ + WebUI.executeJavaScript(‘return sessionStorage.getItem(“id_token”)’, null)

println(token)
def irn = GlobalVariable.irn

breederRef = GlobalVariable.irn

breederRef = breederRef.substring(breederRef.length() - 3)

GlobalVariable.breederReference = (‘REF XXX’ + breederRef)

GlobalVariable.token = token

// Define the global variables.

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
println(GlobalVariable.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)

Try the below last time :slight_smile:

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.model.FailureHandling

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

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import internal.GlobalVariable

String breederRef

WebUI.refresh()

String token = 'Bearer ’ + WebUI.executeJavaScript(‘return sessionStorage.getItem(“id_token”)’, null)

println(token)

// Get the value of the irn global variable

def irn = GlobalVariable.irn

// Modify the breederReference

breederRef = irn

breederRef = breederRef.substring(breederRef.length() - 3)

GlobalVariable.breederReference = ‘REF XXX’ + breederRef

GlobalVariable.token = token

// Define the global variables.

def attachmentUrl = GlobalVariable.attachmentUrl

// Send the first request to get the attachment URL.

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

// 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

println(GlobalVariable.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)

Hi @himanisaxena19
if you use same variable names inside the custom keyword as well as in the script you will get Multiple compilation error

i faced this once in katalon studio

multiple compilation error means you declared 2 or more variables in the same name.
but we used to identify only inside the scripts but the fact is katalon also consider the variable you used in custom keyword too.

pls check in the custom keyword as well as in the api script and make sure you don’t have same variable names

Now getting below error

file:/C:/Users/hsaxena/Desktop/Updated%20Test%20Pack/automation-test/Scripts/API%20Test%20Cases/CreateIRN%20API/Script1672121117054.groovy: 26: Invalid variable name. Invalid character at position: 4 of value: ’ in name: XXX’
. At [26:40] @ line 26, column 40.
GlobalVariable.breederReference = ‘REF XXX’ + breederRef

Please use the Code Formatting syntax when you copy & paste a code snippet in order to avoid mistyping.

In the quoted line you see

‘REF XXX’ 

But I think the program source code should rather be typed as:

'REF XXX'

Please find that the ' characters in the text you pasted were silently converted to a or a by Discourse (the Wiki engine used for this forum site).

' is named as ‘APOSTROPE’ (in UNICODE U+27)
is named as ‘LEFT SINGLE QUOTATION MARK’ (in UNICODE U+2018)
is named as ‘RIGHT SINGLE QUTATION MARK’ (in UNICODE U+2019)

In all of program source codes we use the APOSTROPH.
Discourse silently converted the APOSTROPH to other characters.
So you got confused.

If you carelessly copy and past a LEFT SINGLE QUOTATION MARK into your program source, then you will encounter an error

Invalid character at position: 4 of value

That’s the reason why @himanisaxena19 got the error

1 Like

Tried again after some minor changes and now getting “Unable to send request (Root cause: java.lang.IllegalArgumentException: URI is not absolute”

I think some issue while fetching value of attachmentUrl from the response of 1st request.
Do we have any other way?

This is resolved, I was using incorrect authority in 1st API request.

Thanks everyone for the help :slight_smile:

@himanisaxena19 : please mark the solution which resolved this. I see you have marked your own statement as the resolution. It will aid others to check and counter similar problems.