The second argument to APIFunction should be a function. The most common way to give the function is as a pure/anonymous function. To make a pure/anonymous function, you are missing the apersand:
I don’t believe I am hardcording the website into the code. Let me rewrite and explain the code a bit.
This line defines an APIFunction expression called “f”. The APIFunction “f” takes an argument called Website which it will interpret as a “SemanticURL”. This means it’ll convert input like “Facebook” automatically to “https://www.facebook.com/”. It tries to convert anything reasonable into a website url. The second argument is a function that takes that URL and does something with it. The third argument specified how the function should be returned. In this case, it’ll be returned as a “JPEG”:
f = APIFunction[{"Website" -> "SemanticURL"}, First@Import[#Website, "Images"] &, "JPEG"]
Here is an example how we would call f in Mathematica (running locally on your computer). In this case we call f with google:
f[<|"Website" -> "http://www.google.com"|>]
or
f[<|"Website" -> "google"|>]
We can deploy f to the wolfram cloud with CloudDeploy. This will allow us to run the APIFunction in the cloud as an API:
myDeployment = CouldDeploy[f]
This will return a CloudObject with a url. If you go to the URL by clicking it, you’ll see some instructions on how to use it. Let’s say that the URL was:
The bad news is that the Import function doesn’t seem to work right now on the cloud side. So this example won’t work until that’s fixed - I’m not aware of a workaround. I’ve forwarded the issue to the relevant people to make sure they’re aware of it. I included the code above to hopefully give a better example of how APIFunction works.
Ah ok. I already tried both
CloudDeploy[f] and the ?Website=
and I could not get it to work. I’m glad that you told me that it was broken. Again, thanks for taking your time to explain it to a newbi like me.
This still seems to be an issue, see http://mathematica.stackexchange.com/q/97751/1635 Any ideas for a workaround when you want a program to run in the cloud, gather data from a website x that is a parameter to the program?
Previous update on 12/14/15 confirmed Sean Clarke’s API was working, but the CloudObject had default “Private” permissions, which works fine from a browser signed into the Wolfram Development Platform, but gives an signin error from URLExecute.
Import of website images now works from a cloud deployed APIFunction, FormPage, etc. Last week my reply to Sean Clarkes post missed this fact, but Ive updated it to show that his API function is now working.