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.
Hello Danyal,
I am new to this kind of thing, any suggestions?
Regards.
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.