A basic example for APIFunction[] is

doubled = APIFunction[{"x" -> "Real"}, #x*2&]; doubled["x"->6.5]

which shows the output 13. in a notebook. When I deploy this using


I get back a CloudObject. Calling it in a browser like "https://www.wolframcloud.com/obj/707...?x=6.5" will return 13. as a response.

Now I tried the same with an association, but cannot get it to work:

content = APIFunction[Association["lampstatus"-> "on", "temp" -> 37.2][#x]&]; 

will give the expected output on, but in the browser "https://www.wolframcloud.com/obj/707...?x=lampstatus" will not output this single value.

Thanks for any help...

Of course this gave no better results (questions/159215):

URLExecute[content, {"x" -> "lampstatus"}]


URLBuild[First@content, {"x" -> "lampstatus"}] // Echo // SystemOpen
  • $\begingroup$ Could you point me in the documentation where the format APIFunction[Association[...]] is supported? Only list can be given as parameters. Association is needed when you apply those parameters like APIFunction[....][<|..|>]. $\endgroup$
    – dsingh
    Apr 13, 2020 at 13:57
  • $\begingroup$ I did not find any documentation. Trial and error (and lack of own debugging skills) led me to "APIFunction[<|...|>[#x]&]", which obviously works per se, but not inside CloudDeploy[]. Regarding your solution "APIFunction[....][<|..|>]", where should I put the pure function and the #x ? $\endgroup$
    – hbetz
    Apr 14, 2020 at 19:10
  • $\begingroup$ P.S.: If I try APIFunction[{}] with an empty list, the error message says "APIFunction expects a rule, a list of rules or an association as input..." So not only list is a valid parameter... $\endgroup$
    – hbetz
    Apr 14, 2020 at 19:20
  • $\begingroup$ You can find the documentation below at reference.wolfram.com/language/ref/APIFunction.html. APIFunction does not use the Association as a parameter. $\endgroup$
    – dsingh
    Apr 15, 2020 at 18:14
  • $\begingroup$ You are right, thanks for the hint, this does the trick: content = APIFunction[{"x"->"String"},<|"lampstatus"-> "on", "temp" -> 37.2|>[#x]&]; $\endgroup$
    – hbetz
    Apr 16, 2020 at 17:51

1 Answer 1


content = APIFunction[{"x"->"String"},<|"lampstatus"-> "on", "temp" -> 37.2|>[#x]&]; CloudDeploy[content]


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.