You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
Hello everyone,
I need to make a call to a php form located in an external system, in the call I also need to pass a parameter to receive a 0 as a result, since if I pass the empty parameter it returns a 1, is it possible to perform this task from a script? , I have tried making a rest call but I always get the value 1.
Script:
import groovyx.net.http.RESTClient;
import groovyx.net.http.HttpResponseDecorator;
import groovyx.net.http.HttpResponseException;
import com.atlassian.jira.util.json.JSONException
import com.atlassian.jira.util.json.JSONObject
import static groovyx.net.http.ContentType.*;
def body_req = [
"texto": "hola"
]
RESTClient client = new RESTClient('http://tic.eroski.es/');
HttpResponseDecorator respPost = (HttpResponseDecorator) client.post(
path : '/codigo/tic_finan/tic_finan_test.php',
body : body_req,
requestContentType: JSON
)
return respPost.getData()
Regards.
look like your request body json is not correct.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello again Danyal,
If you have any idea how to fix the body of the json request so that it makes the call correctly it would be of great help.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
the correct format should be availble in the REST API documentation. If you can't find it in the docs, try to get an existing record from the REST API with a GET request and see how the json is formatted.
I would investigate the REST Endpoint with Postman or any other rest client and make the POST Request work from Postman first.
some quick pointers:
- use a try catch block to catch the exception
- define the body directly directly when you make the call
- use respPost.responseData
- loose the quotation marks for Json Keys
- print the json string youo are posting to see how it look
- set the correct header:'application/json'
- check the status code ... respPost.statusCode. Is the api returning a 200?
def body_req = [
texto: "hola"
]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Danyal,
I just got the script to work for me, the error was when defining the content-type, I have changed the value of the header to 'application / x-www-form-urlencoded' and it works correctly, thank you very much for your help.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.