# How to CloudDeploy an APIFunction that takes audio as input?

I have a function whose argument is Audio and I'd like to deploy it as an API (and then call it from Python). This works as with FormPage[] as follows:

CloudDeploy[
AudioPlot@Import[#ex] &]]


But I'm not sure how to set it up with APIFunction[] and then call it as a HTTP GET request. I can assume they are WAV files if that makes it easier.

You can create an APIFunction with a very similar syntax and return e.g. a png"

CloudDeploy[
APIFunction[
, HTTPResponse[ExportString[AudioPlot@Import[#ex, "WAV"], "PNG"]] &
]
, "api/audioPlot"
, Permissions -> "Public"
];


Can't say how to call it from Python but from WL it goes like this:

req = HTTPRequest[
CloudObject["api/audioPlot"]
, <|"Body" -> {"ex" -> File[path/to/file.wav]}|>
];

URLExecute[req, "PNG"]


• Hi, this answer doesn't seem to work in V12, the URLExecute now returns a Failure object with the message "Import::fmterr: Cannot import data as PNG format."
– M.R.
Sep 25 '19 at 16:03
• Has something changed in APIFunction or URLExecute?
– M.R.
Sep 25 '19 at 20:02