Hi Guys,
Need your help in sending REST API from Scriptrunner script console.
I'm trying to see below POST HTTP request, but getting 404 error. I think some issue in my code, please help me in fixing the code :-
import groovy.json.JsonOutput
import groovyx.net.http.ContentType
import groovyx.net.http.HttpResponseDecorator
import groovyx.net.http.RESTClient
final externalUrl = "https://api.openai.com/v1/completions/"
def body = JsonOutput.toJson(
"""{
"model": "text-davinci-003",
"prompt": "Q:do you know if we have an Advanced Roadmap plugin running in Jira cloudand please share latest Atlassian Document Link?AI:",
"temperature": 0,
"max_tokens": 100,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0,
"stop": ["\n"]
}""")
def postResponse = post(externalUrl, "", body)
/*
if (getResponse) {
def responsePostMap = postResponse as Map
responsePostMap.each {}
assert responseStatus == 200
}*/
def post (def hostUrl, def endpointAndQuery, def bodyJson)
{
def client = new RESTClient(hostUrl)
client.setHeaders([
'Accept' : ContentType.JSON,
'Authorization' : "Bearer sk-j4qZQqwSRgElbkFJbALfxVk99xgsfiJmTlm4"
])
client.post(
path: endpointAndQuery,
contentType: ContentType.JSON,
body: bodyJson
)
}