community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.

How to POST JSON to REST API

Meteoroid

I have a REST API with method POST that expects data in JSON format in the body. I am trying send data from Alteryx (DownloadTool) to this API calling the POST method, but with no success. I receive various errors 400 / 415 etc. Could you please explain how to configure DownloadTool to post to REST API?

 

Example errors:

 

DownloadData
{"Errors":["The request entity's media type 'application/x-www-form-urlencoded' is not supported for this resource."],"StatusCode":415}

 

DownloadHeaders
HTTP/1.1 415 Unsupported Media Type
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 135
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
P3P: policyref="/w3c/p3p.xml", CP="NON COR CURa ADMa DEVa OUR NOR"
Date: Sat, 20 May 2017 15:16:52 GMT

 

Kind regards,

Piotr

Alteryx
Alteryx

Hi Piotr,

 

Not a direct answer to your problem, but have you seen this great post on the Slack REST API? (https://community.alteryx.com/t5/Portland-ME/Meeting-2-in-the-books/gpm-p/32526#M14)

 

It gives you a pretty good example (including a workflow) of using a POST action on an external API

 

Cheers,

Nick

Nick Jewell | Alteryx Product Strategy
Meteoroid

Hi Nick,

 

Thank you, but I reviewed community discussions before posting my question. My fault, I should have mentioned that the above error(s) are the result of setting up workflow the same way as in the link you posted. 

 

If I use postman I can send information to this API without any problems. It's just not efficient for me to have this external solution instead of a method incorporated int Alteryx workflow.

 

Kind regards,

Piotr

 

 

ACE Emeritus
ACE Emeritus

Hi Oberon

 

I just finished setting up a POST connection to a REST API last week. 

 

 

Hard to diagnose without more detail. Feel free to DM me and perhaps we can have a call or VC. 

 

cheers

 

Alteryx Everything, Leave no one behind.
ACE Emeritus
ACE Emeritus

Actually

 

just had a look at your error message. 

 

It prob has to do with this. 

 

Try using the option circled in blue to deliver the payload. 

Capture.JPG

kr

 

Alteryx Everything, Leave no one behind.
Meteoroid

Hi Gavin,

 

Sorry for late answer. I managed to POST data via Dwonload Tool, however it required few adjustments of the data which I wish to load. First of all I have to format data by myself via formula to fit it into {} then concatenate in into one cell and add [ ] - at that stage I have JSON file (please note that JSON Pharse or JSON Build tools do not create correct JSON format from my data because it gives me the output in two columns (Name & ValueString) and I cannot use 'Compose Query String/Body' to actually point at more than one column, this is due to lack of correct 'Content-Type' (there are only two pre-defined types and none of it is true in my case, I need application/json)). Then I add Header information, Payload and + Basic (printscreens below).

 

And this is where the fun begins because I can send up to 104 rows of my data (which I concatenate later on in the workflow into one cell)  but if I add more (I think it depends on the number of characters maybe?) then I get this error:

 

HTTP/1.1 200 Connection established



HTTP/1.1 100 Continue



HTTP/1.1 400 Bad Request

Cache-Control: no-cache

Pragma: no-cache

Content-Length: 109

Content-Type: application/json; charset=utf-8

Expires: -1

Server: Microsoft-IIS/8.5

P3P: policyref="/w3c/p3p.xml", CP="NON COR CURa ADMa DEVa OUR NOR"

Date: Fri, 26 May 2017 13:27:01 GMT


 

I also get the response (DownloadData):

 

4 Bytes

6D000000

If I send less than data, everything works fine and I can see below message only:

 

HTTP/1.1 200 Connection established



HTTP/1.1 100 Continue



HTTP/1.1 200 OK

Cache-Control: no-cache

Pragma: no-cache

Content-Length: 0

Expires: -1

Server: Microsoft-IIS/8.5

P3P: policyref="/w3c/p3p.xml", CP="NON COR CURa ADMa DEVa OUR NOR"

Date: Fri, 26 May 2017 13:30:09 GMT



If I check the output from Download Data via Browse Tool It looks like the whole JSON content is included in POST, disregarding the volume of the data I choose to send. 

 

Printscreens:

 

1. Data (just before the use of Download Tool):

 

image.png

 

2. Download Tool config:

 

image.png

image.png

image.png

image.png

 

I would appreciate some suggestions.

 

Kind regards,

Piotr

 

I also use 

ACE Emeritus
ACE Emeritus

Hi 

 

Good stuff. Ah the joys of Json sting building... Yes similarly i also use formula tool etc...to build the string i need.  

 

 I found using the Crew Jason Create was much better than the inbuilt tools (they have the various data matrixing requirements built in). Would certainly recommend for future json string building. The data then streams to the next tool.

 

Capture 1.JPGCapture 2.JPG

 

 

 

The 104 rows may be an API limitation. I had a similar problem where i was only allowed to upload 200 records per call. To solve this i built a macro that splits up the records into chunks of 200 and writes the json string for each one. When fed to the download tool, this then creates a call per 200, keeping it within limit. 

 

Hope that helps. 

 

kr

Alteryx Everything, Leave no one behind.
Atom

Hi All , 

 

I'm facing issue while getting the data JSON response from REST API .

 

-------------------------------------------------------------------------

 

<HTML><HEAD><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><script >
function IWTop(){
if ((parent != self) && (parent != null)) {
try {
return parent.IWTop();
} catch (e) {
return window;
}
} else {
return window;
}
}
IWTop().document.writeln('<!DOCTYPE html><html><head> <title>##key##rwp_name_int_err###Retain Web Portal - Internal Error</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="./Files/static/css/RetainSS.css" rel="stylesheet" type="text/css"></head><body class="redux"> <div class="layout-master--centred"> <div class="content-article"> <div class="primary-content"> <h1 class="h1">Unexpected error</h1> <p>Sorry, the application produced an unexpected error.</p> <p>Please try closing your browser and reconnecting to TalentLink, "err_advice".</p> <h2 class="h4">Error details:</h2> <div class="hint--warn"> <p>Unknown browser type.</p> <p>Depending on the error condition, it might be possible to restart the application.</p> </div> </div> </div> <div class="layout-footer"> <p>TalentLink powered by Capita &copy; 2005-2016</p> </div> </div> <!--<p>&nbsp;</p><table width="800" align="center" border="1" cellpadding="20"> <tr> <td align="center" bgcolor="#9999FF"><img src="Files/retain_logo.jpg" width="347" height="31" align="center"></td> </tr> <tr> <td height="265"><p><span id="##key##err_sorry##">We are sorry, but the application produced an unexpected error.</span></p> <p><span id="##key## ##">Please close the browser and connect again to Retain Web Portal", "err_advice", </span></p></td> </tr> <tr> <td align="right" bgcolor="#9999FF"><span id="##key##err_warning##">The application has reported the error:</span> Unknown browser type. - Depending on the error condition, it might be possible to restart the application. </td> </tr></table><p>&nbsp;</p>--></body></html>');
</script></head></html>

-----------------------------------------------------------------------------------

 

Could any one advice on how I can get the actual JSON response . This Rest API is password authenticated , so i have given user id password in Download tool configuration . 

 

Moderator
Moderator

@deethesh - I see this from the response:

 

NyofIur

 

does the Documentation for this REST API tell you what browser types are allowable? Does it give you ways that you can connect to this REST API using cURL? If so, you may need to send the username and password differently, The documentation should point you in the right direction

Sophia Fraticelli
Customer Support Engineer
Alteryx, Inc.
Alteryx
Alteryx

The unidentified browser issue might require that the Download tool gets a header parameter for 'User Agent' too - this effectively provides a browser type for the remote API service. See https://community.alteryx.com/t5/Data-Preparation-Blending/Download-Data-from-website/td-p/7030/page... for more details. 

 

Cheers,

Nick

Nick Jewell | Alteryx Product Strategy
Labels