Group Abstract Group Abstract

Message Boards Message Boards

0
|
11.6K Views
|
3 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Submit a list as an argument to an APIFunction?

POSTED BY: Arnold Stillman
3 Replies
POSTED BY: Carlo Barbieri

Thanks. This answers my question. My input is actually json, so in desperation I solved my problem by importing the json directly with

APIFunction[{"d" -> "JSON"},  ToExpression[Take[Sort[Keys[#d]] /. #d, 9]] & , "String"]
POSTED BY: Arnold Stillman

There are two ways to go about this:

api1 = APIFunction["x" -> RepeatingElement["Integer"], Max[#d]&]
api2 = APIFunction["x" -> DelimitedSequence["Integer"], Max[#d]&]

and then

api1[{"x" -> "1", "x" -> "2", "x" -> "3", "x" -> "4"}]
api1[{"x" -> {"1", "2", "3", "4"}}]
api2["x" -> "1, 2, 3, 4"]

So the difference between RepeatingElement and DelimitedSequence is that the first takes repeated keys, while the second will split a string for you.

POSTED BY: Carlo Barbieri
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard