Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Call to php form from script

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.

form1.png

 

script1.png

 

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.

1 answer

1 accepted

1 vote
Answer accepted
Danyal Iqbal Community Leader Feb 17, 2021

look like your request body json is not correct.

Hello Danyal,

I am new to this kind of thing, any suggestions?

 

Regards.

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.

Danyal Iqbal Community Leader Feb 18, 2021

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"
]

Like Pedro J_ Acosta likes this

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Software

Presenting the "Best of 2020" Jira Software roundup!

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

7,018 views 8 28
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you