Send JSON Package with httpPost Routine?

I'm currently attempting to use the httpPost routine in JJupin to send a JSON package to our internal portal. I've attached the following script to a post function on one of our workflow transitions (I removed the URL):

string url = "<INTERNAL VENDOR PORTAL URL>";
string [] headers = "Content-Type|application/json";
//Get field values for JSON Body
date shipStart = toTimeZone(customfield_11108,"UTC");
string format = "yyyy-mm-dd HH:mm:ss";
date shipEnd = toTimeZone(customfield_11109,"UTC");
string uuid = "12345-678910-ABCDEF-GHIJKL";
//Load the Product Names and place them into the product dynamic string
KPOption [] productNames = customfield_12401;
string product = "{\"name\":\""+productNames[0].value+"\"}";
if(arraySize(productNames) > 1) {
    for(number i = 1; i < arraySize(productNames); i = i+1) {
    product = product + ",{\"name\":\""+productNames[i].value+"\"}";
    }
}
//Load the origin UUID's and place them into the origin dynamic string
string [] originUUID = {"10005-600000-A0000F-G0000L", "12345-0987654-jgg8765-987o", "1234-98uwyeye-838483-oui22"};
string origins = "{\"uuid\":\""+originUUID[0]+"\"}";
if(arraySize(originUUID) > 1) {
    for(number j = 1; j < arraySize(originUUID); j = j+1) {
        origins = origins + ",{\"uuid\":\""+originUUID[j]+"\"}";
    }
}
//Load the destination UUID's and place them into the destination dynamic string
string [] destinationUUID = {"1234-98uwyeye-838483-oui22", "12345-0987654-jgg8765-987o"};
string destinations = "{\"uuid\":\""+destinationUUID[0]+"\"}";
if(arraySize(destinationUUID) > 1) {
    for(number k = 1; k < arraySize(destinationUUID); k = k+1) {
        destinations = destinations + ",{\"uuid\":\""+destinationUUID[k]+"\"}";
    }
}
//Construct the JSON Body
string json = "{\"rfq\":{\"jira_issue\":\""+key+"\",\"raw_data\":{\"jira_parent_issue\":\""+parent+"\",\"temperature\":\""+
temperature+"\",\"shipping_period_start\":\""+formatDate(shipStart, format)+" UTC\",\"shipping_period_finish\":\""+formatDate(shipEnd, format)+
" UTC\",\"total_loads\":"+totalLoads+",\"container_size\":\""+containerSize+"\",\"truck_type\":\""+truckType+"\",\"gross_weight\":\""+grossWeight+
"\",\"request_type\":\""+requestType+"\",\"origins\":["+origins+"],\"destinations\":["+destinations+"],\"products\":["+product+"],\"external_rfq\":[{\"jira_issue\":\""+
key+"\",\"vendor_uuid\":\""+uuid+"\"}]}}}";
//send the payload
string [] payload = {"rfq", json};
return httpPost(url, headers, payload);

Unfortunately, our internal portal wouldn't accept the message being send by JIRA because it's not being formatted as a JSON message - rather, it's being URL encoded, and the message can't be parsed correctly by the internal portal. Here's the error output we got when attempting to send this JSON:

I, [2016-07-06T20:21:59.980078 #5557]  INFO -- : Started POST "/rfqs.json" for 69.74.224.69 at 2016-07-06 20:21:59 +0000
D, [2016-07-06T20:21:59.981815 #5557] DEBUG -- : Error occurred while parsing request parameters.
Contents:

rfq=%7B%22rfq%22%3A%7B%22jira_issue%22%3A%22LOG-1424%22%2C%22raw_data%22%3A%7B%22jira_parent_issue%22%3A%22LOG-1423%22%2C%22temperature%22%3A%22Frozen%22%2C%22shipping_period_start%22%3A%222016-00-21+04%3A00%3A00+UTC%22%2C%22shipping_period_finish%22%3A%222016-00-28+04%3A00%3A00+UTC%22%2C%22total_loads%22%3A2%2C%22container_size%22%3A%2220%27%22%2C%22truck_type%22%3A%22FTL%22%2C%22gross_weight%22%3A%221200%22%2C%22request_type%22%3A%22Inquiry%22%2C%22origins%22%3A%5B%7B%22uuid%22%3A%2210005-600000-A0000F-G0000L%22%7D%2C%7B%22uuid%22%3A%2212345-0987654-jgg8765-987o%22%7D%2C%7B%22uuid%22%3A%221234-98uwyeye-838483-oui22%22%7D%5D%2C%22destinations%22%3A%5B%7B%22uuid%22%3A%221234-98uwyeye-838483-oui22%22%7D%2C%7B%22uuid%22%3A%2212345-0987654-jgg8765-987o%22%7D%5D%2C%22products%22%3A%5B%7B%22name%22%3A%22Alligator%22%7D%5D%2C%22external_rfq%22%3A%5B%7B%22jira_issue%22%3A%22LOG-1424%22%2C%22vendor_uuid%22%3A%2212345-678910-ABCDEF-GHIJKL%22%7D%5D%7D%7D%7D
F, [2016-07-06T20:21:59.982478 #5557] FATAL -- : 
ActionDispatch::ParamsParser::ParseError (795: unexpected token at 'rfq=%7B%22rfq%22%3A%7B%22jira_issue%22%3A%22LOG-1424%22%2C%22raw_data%22%3A%7B%22jira_parent_issue%22%3A%22LOG-1423%22%2C%22temperature%22%3A%22Frozen%22%2C%22shipping_period_start%22%3A%222016-00-21+04%3A00%3A00+UTC%22%2C%22shipping_period_finish%22%3A%222016-00-28+04%3A00%3A00+UTC%22%2C%22total_loads%22%3A2%2C%22container_size%22%3A%2220%27%22%2C%22truck_type%22%3A%22FTL%22%2C%22gross_weight%22%3A%221200%22%2C%22request_type%22%3A%22Inquiry%22%2C%22origins%22%3A%5B%7B%22uuid%22%3A%2210005-600000-A0000F-G0000L%22%7D%2C%7B%22uuid%22%3A%2212345-0987654-jgg8765-987o%22%7D%2C%7B%22uuid%22%3A%221234-98uwyeye-838483-oui22%22%7D%5D%2C%22destinations%22%3A%5B%7B%22uuid%22%3A%221234-98uwyeye-838483-oui22%22%7D%2C%7B%22uuid%22%3A%2212345-0987654-jgg8765-987o%22%7D%5D%2C%22products%22%3A%5B%7B%22name%22%3A%22Alligator%22%7D%5D%2C%22external_rfq%22%3A%5B%7B%22jira_issue%22%3A%22LOG-1424%22%2C%22vendor_uuid%22%3A%2212345-678910-ABCDEF-GHIJKL%22%7D%5D%7D%7D%7D'):
  actionpack (4.2.3) lib/action_dispatch/middleware/params_parser.rb:53:in `rescue in parse_formatted_parameters'
  actionpack (4.2.3) lib/action_dispatch/middleware/params_parser.rb:32:in `parse_formatted_parameters'
  actionpack (4.2.3) lib/action_dispatch/middleware/params_parser.rb:23:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/flash.rb:260:in `call'
  rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  activerecord (4.2.3) lib/active_record/query_cache.rb:36:in `call'
  activerecord (4.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.3) lib/active_support/callbacks.rb:84:in `run_callbacks'
  actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.3) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.3) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.3) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  railties (4.2.3) lib/rails/engine.rb:518:in `call'
  railties (4.2.3) lib/rails/application.rb:165:in `call'
  puma (3.1.1) lib/puma/configuration.rb:227:in `call'
  puma (3.1.1) lib/puma/server.rb:561:in `handle_request'
  puma (3.1.1) lib/puma/server.rb:406:in `process_client'
  puma (3.1.1) lib/puma/server.rb:271:in `block in run'
  puma (3.1.1) lib/puma/thread_pool.rb:111:in `call'
  puma (3.1.1) lib/puma/thread_pool.rb:111:in `block in spawn_thread'

We used the same syntax seen here to construct the JSON message and sending it using the httpPost routine. We made sure the output of the string matches the expected incoming message specifications of the internal portal. We also used Postman to send the same string as a JSON to the portal URL, and it handled the incoming JSON correctly, which means there's a problem at the the JJupin or JIRA level. Any thoughts on how we could get he httpPost routine to work correctly?

 

1 answer

JJupin does not yet support sending JSON in httpPost(), but according to developers they have added this feature to their internal tracker, so it might pop-up with some new version. You might want to look at and watch this issue:

https://bugs.kepler-rominfo.com/browse/IMJ-233

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

102 views 0 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you