Can you send JSON as the payload for a SIL httpPost request?

Chris Kast May 18, 2015

Is there any way to send json as the payload for the an httpPost method in a SIL script? I've tried setting the header to:

string [] headers = "Content-Type|application/json";

And the payload to:

string [] payload = {"text", "This is a test"};

but I get a 500 response from the server.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Alexandru Geageac
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 20, 2015

Hi Chris,

You can send json via httpPost if it is manually created, see the script below:

string url = "https://slack.com/api/chat.postMessage";
string [] headers = "Content-Type|application/json";
string json = "{\"name\": \"value\"}";
//The following JSON example defines an employees object, with an array of 3 employee records:
string jsonArr = "{\"employees\": [" +
                    "{\"firstName\": \"John\", \"lastName\": \"Doe\"}" + 
                    "{\"firstName\": \"Anna\", \"lastName\": \"Smith\"}" + 
                    "{\"firstName\": \"Peter\", \"lastName\": \"Jones\"}" + 
                "]}";
string [] payload = {"myJson", json};
return httpPost(url, headers, payload);

Best regards,

Alex

anton ronin May 13, 2016

still not implemented?

nice job

Fernando del Río September 29, 2016

how make the basic auth in httpPost?

Gregory Kneller
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 18, 2018

You shall add to headers

Authorization|Basic X==

X a string of  base64-encoded username:password

Walid Djama March 26, 2019

It's not working, i have the folowing error :

IO exception performing HTTP POST: peer not authenticated.

Cristian Pintea March 26, 2019

Hi Walid,

Since the 4.1.0 version of Power Scripts (May 2018) we have added a bunch of new routines that should make it a lot easier for you to deal with HTTP requests from SIL.

For the description of the new routines and some usage examples, please consult the docs at the following address:

https://confluence.cprime.io/display/SIL/HTTP+routines

Like Alexandru Geageac likes this
0 votes
Alexandru Geageac
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 23, 2015

Hi Chris,

It seems like at this moment you cannot do this. We will create an internal ticket for that and we will update this ticket when the feature is production ready so you can get notified.

Regards,

Alex

Chris Kast June 24, 2015

Excellent. Thanks Alexandru

TAGS
AUG Leaders

Atlassian Community Events