Hello,
I successfully deployed a public API Function[] in Wolfram's Cloud.
Working with HTTP POST procedure, I can effectively post data using Form URL Encoded content-type (Like : param1=value1¶m2=value2
) toward the API URL, and the API does its job nicely.
Sadly, I'm dealing with an external service that also uses HTTP POST using either plain text or JSON.
JSON being an industry standard for API stuff for some time now, and also being very easy to manipulate, I was happy to deal with this type of data.
But I don't succeed.
This is my code example :
api=APIFunction[{"Chiffre"->"String"},StringSplit[#Chiffre]&]
(* Testing the API : Strings are splitted after each space, returns : {"Il","neige","au","Printemps"} *)
api[<|"Chiffre"->"Il neige au Printemps"|>]
(* Deploying the API in the Cloud *)
CloudDeploy[api,Permissions->"Public"]
Using a HTTP GET works fine (adding ?Chiffre="Il neige au Printemps"
in the URL), and so does HTTP POST using Form URL Encoded (sending Chiffre="Il neige au Printemps"
).
But sending a JSON content fails to be treated by the API. My JSON request is :
{"Chiffre": "Il neige au Printemps"}
I get this response from API :
{
"Success": false,
"Failure": "The API could not be evaluated because there is no input for fields: \"Chiffre\".",
"Fields": {
"Chiffre": {
"AllowedExtensions": [
"json"
],
"AutoSubmitting": false,
"CodeLanguage": "Automatic",
"Default": null,
"Enabled": true,
"Failure": "This field is required.",
"Help": null,
"Hidden": false,
"Hint": null,
"Input": null,
"Interpreter": "String",
"Label": "Chiffre",
"Required": true,
"Type": "Element"
}
}
}
Can somebody suggest something for dealing with JSON as input for cloud-hosted API ? Or should I use plain text and then parse the information inside the API ?
Thank you.