Free Trial

Alteryx Designer Desktop Discussions

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

How do I pass JSON to Download tool without using JSON Build tool?

avanibhatnagar
8 - Asteroid

Hi, I have a workflow where I'm reading data from SQL server and manipulating to get what I need - user ids. Then I need to pass these user ids to an API call to delete users. Now I have tested this API call on postman and it works without any issue.  I need to pass a JSON in the body:
{"userIds":[1234]}

This works no problem in Postman (but there I can select JSON as the format). But when I create this using the formula tool and I checked using Browse that it looks exactly like this and pass this as Payload using "Take Query String/Body from Field" (see 1.png). I have tried passing it in various ways using Formula tool to format it like JSON, but it fails with "400: Bad Request"

I also tried using the JSON Build to build the JSON but that either creates it in this format if I keep that ID as Double: {"userIds":1234} (so without the square brackets but I need the square brackets)
If I try to keep that ID as string it creates it in this format: {"userIds":"[1234]"}, but I don't want the quotes around the id. I've tried created using JSON Parse and then using a formula tool to add square brackets or remove quotes but none of that works and returns a Bad Request. 

Any ideas on how to approach this? 

 

 

6 REPLIES 6
apathetichell
19 - Altair

you do not need the json build tool.

you should be able to pass this in--- but if you have postman - toggle to the developer panel to curl.

see what the content type is. add that to the conent-type in your download tool (ie application/json).

 

try again.

 

does the json in postman have brackets surrounding it (ie [{"userIds":[1234]}] - add thse in the formula tool. Is there URL encoding? account for that. Postman will do it automatically. Probably it's just the content-type.

 

if this does not work - post the API you are using.

apathetichell
19 - Altair

keep in mind that each record is an api call - if you can bunch this into {userIds": [val1,val2... valN]}

 

it would be more efficient. you do this by using a summarize tool to concatenate your values - and then contrsuct your json around it. note for strings you'll need to add the quotes around your json in the summarize tool. for numbers - you'll need to convert to string (and don't add quotes) prior to your summarize tool.

avanibhatnagar
8 - Asteroid

 

@apathetichell I was initially doing a summarize and it kept failing so I was like let me get 1 working first so stopped using that, but once it's working I do plan on using the Summarize tool to get {userIds": [val1,val2... valN]}
Re: adding the content-type - the issue is that it is a "DELETE" call. so the content-type is greyed out. I believe that is only enabled for POST requests. 

In postman I don't have brackets surrounding it. It's just this in the body passed as JSON in Postman and raw type: {"userIds":[104941]}

This is the curl in postman:

curl --location --request DELETE 'https://api.suralink.com/v1/firm/user/?acs_tkn=token' \
--header 'Content-Type: application/json' \
--data '{"userIds":[value]}'

 

patrick_digan
17 - Castor
17 - Castor

@avanibhatnagar APIs are fun when they don't work :) For what it's worth, I'd suggest the following. I tested this out with a PUT request for an alteryx API successfully:

1) On the headers tab, specifying json like so. In my experience this lets you get around the greyed content-type box on the payload tab. I confirmed with Fiddler that it sent the JSON contenttype header like I wanted.

 

image.png

2) setting up the payload tab using the delete and your data just manually typed into the bottom box.

image.png

avanibhatnagar
8 - Asteroid

@patrick_digan Still no luck. I'm starting to think I'm just going to have to use a Python tool and make my calls in there. 

apathetichell
19 - Altair

I don't use DELETE actions all that often - but playing around with it - I don't see adding a content-type application/json header greyed out.

I'd reocmmend togglint it to post. adding the header. toggling back to DELETE.

 

Can you confirm that Alteryx is providing an integer in the payload ie that the string you are sending in your body is EXACTLY the same as what you see in Postman. No extra quotes or anything?

 

Download tool may be a pain but I've never seen an situation where it couldn't replicate Postman - given the proper formatting and headers.

Labels
Top Solution Authors