Hot answers tagged

11

Update: Full Flow So after much wrangling here is the full OAuth 1.0 flow. (* Get the token *) $consumerKey = "key"; $consumerSecret = "secret"; $oauthTokenResponseString = URLRead[ OAuthSigning`Private`HMACSha1SignatureService[ "http://www.khanacademy.org/api/auth2/request_token", "HMAC", "GET", $consumerKey, $consumerSecret, ""(*token ...


7

Update on June 29th, 2020 Since API has changed, the new code is here: getFKey[] := First@StringCases[ URLRead[HTTPRequest["https://stackexchange.com"]]["Body"], "fkey: '" ~~ Shortest[fkey___] ~~ "'" :> fkey] uploadImageSE[imagePath_] := Module[{req}, req = HTTPRequest[ "https://mathematica....


6

If you call the API with the image encoded as a URL parameter there will be image size limitations. The solution is to instead post multipart/form-data to the API: With[{cloudobject = FileNameJoin[{$CloudRootDirectory, "ImageEffectAPI"}]}, CloudDeploy[ APIFunction[{"x" -> "Image"}, ImageEffect[#x, "Charcoal"] & ], ...


6

This should do the trick if you fill in the appropriate authentication headers: url = "https://developers.betfair.com/api.betfair.com/exchange/betting/json-rpc/v1"; json = "[{\"jsonrpc\": \"2.0\", \"method\": \"SportsAPING/v1.0/listEvents\", \"params\": {\"filter\":{}}, \"id\": 1}]"; URLFetch[url, {"StatusCode", "Headers", "Content"}, "Body" -&...


5

Google Cloud Platform uses the RS256 algorithm to send JWT and retrieve the tokens, all that is needed is to make a function that builds the JWT and creates a signature using GenerateDigitalSignature[]. FixB64[str_?StringQ] := StringReplace[StringSplit[str, "="][[1]], {"+" -> "-", "/" -> "_"}]; ...


5

You can create an APIFunction with a very similar syntax and return e.g. a png" CloudDeploy[ APIFunction[ {{"ex", "Upload WAV file:"} -> Restricted["UploadedFile", "WAV"]} , HTTPResponse[ExportString[AudioPlot@Import[#ex, "WAV"], "PNG"]] & ] , "api/audioPlot" , Permissions -> "Public" ]; Can't say how to call it from Python but from WL ...


5

This should work with ServiceConnect. In[6]:= twitter = ServiceConnect["Twitter"] Out[6]= ServiceObject["Twitter", "ID" -> "connection-5c77beed5f5bfdf02b1a8074d281a438"] In[10]:= twitter["Tweet", "Message" -> "Hi Twitter!", "Image" -> Import["ExampleData/spikey.tiff"] ] Out[10]= "Hi Twitter! https://t.co/YYXZ58lQwJ" Make sure you use ...


5

Using URLFetch[]: smmsUpload[img_, detailed : (True | False) : False] := Module[{raw}, raw = ImportString[URLFetch["https://sm.ms/api/upload", Method -> "POST", "MultipartElements" -> {{"smfile\"; filename=\"tmp.png", "image/png"} -> ExportString[img, "PNG"]}], "RawJSON"]; ...


5

The : is used for named patterns, it's not part of any key-value data structure in Mathematica. You will not find it used in the way you propose anywhere in the documentation. You could use either a list of rules: ExportString[{ "key1" -> "value1", "key2" -> "value2" }, "JSON"] "{ "key1": "value1", "key2": "value2" }" Or an Association: ...


4

You can do something like this (encoding the PNG in Base64): randomClock[t_] := Rasterize[ Graphics[ Rotate[ClockGauge[t][[1]], RandomReal[{0, 2 \[Pi]}], {0, 0}], ImagePadding -> 0], ImageSize -> 300]; randomClockDeploy[] := With[{t = RandomChoice /@ Range /@ {12, 60, 60}}, <| "img" -> ExportString[randomClock[t], {"Base64", ...


4

You can use the channel framework to communicate between your local session and the cloud api you deploy. First create a channel listener with public permissions in your local session: channel = ChannelListen["test", Permissions -> "Public"] Next get the hard coded URL to deploy with your api: In[54]:= channel["URL"] Out[54]= "https://channelbroker....


4

I found the answer in here https://community.wolfram.com/groups/-/m/t/1055892 api1 = APIFunction["x" -> RepeatingElement["Integer"], Max[#d]&] But instead of a list, I decided to pass a string and just change it to a list in the function. As characters takes less space than numbers, this worked just fine. If anyone is interested the code is ...


3

This request works: qry = ExportString[{"query" -> "1 cup of flour"}, "JSON"]; results = URLExecute[ HTTPRequest[ urlRoot, <| Method -> "POST", headers, "Body" -> qry, "ContentType" -> "application/json" |>] ] {"foods" -> {{"...


3

So after some digging and breaking "MQTTLink`" for while I found that "MQTTLink`" is passing garbage out to its handler functions. The heart of the problem is what's passed to that "AsyncHandler" you found. MQTT must work via some message / topic framework, as we find this in the source, when configuring the server: MQTTLink`TopicSubscribe[client, "...


3

Alright, I got into contact with the support for the API, and the problem was resolved on their end. Apparently, it was an error in the routers' networking configuration.


3

Here's a starting point: after getting your own client ID from here, use the following code, which uses URLFetch[] like in this previous answer: imgurUpload[img_] := Module[{clientID = "93d5e807261cc90", raw}, raw = ImportString[URLFetch["https://api.imgur.com/3/image", Method -> "POST", "Headers" -> {"Authorization" -&...


3

In Mma 11, you can use this function URLRead[]. e.g. image = "E:/yourPic.jpg";(*Your Picture*) url = "https://sm.ms/api/upload";(*Picture Bed URL*) req = HTTPRequest[url, <|"Body" -> {"smfile" -> <|"Content" -> File[image], "Name" -> FileNameTake[image]|>}|>];(*Upload Request, the "Name" is unnecessary*) res = URLRead[req, "...


2

Deploy your API with public permissions or add Username and Password options to URLFetch: With[{cloudobject = FileNameJoin[{$CloudRootDirectory, "FactorIntegerAPI"}]}, CloudDeploy[ APIFunction[{"x" -> "Integer"}, FactorInteger[#x] &], cloudobject, Permissions -> "Public"]; URLFetch[URLBuild[cloudobject, {"x" -> "1"}]]]


2

As @Kuba had commented, ImportString[#, "HTTPRequest"]& does not turn POST parameters to rules. So the property "FormRules", which FormFunction utilizes, can't be generated. Here is a function to finish this convertion when needed: MakeFormRules[request_HTTPRequest] := With[ { makeFormRules = <| URLQueryDecode@StringTrim@...


2

The documentation shows using Apply to allow passing every parameter on FormPage via APIFunction, as in: CloudDeploy[APIFunction @@ FormPage["x" -> "String", Identity]] But if you'd like to pass fewer parameters via APIFunction than are used in your FormPage, then you'll want wrap APIFunction around FormPage, as in the example below: ...


1

After a bit of playing around, I think I have a workable solution to share. Firstly, let's create a classifier using the titanic datset. cl = Classify[ ResourceData["Sample Data: Titanic Survival"] -> "SurvivalStatus"] Let's now define an API function. Within the function, we want to define the independent variables that are passed ...


1

I have expanded the initial thoughts into a draft package. (* ::Package:: *) (* ::Title:: *) (*Mathematica WakaTime Plugin*) (* ::Author:: *) (*Author: Gravifer*) (*Date: 2021-02-21*) (*Version: 0.0.3*) BeginPackage["WakaTime`"] ClearAll[Evaluate[Context[] <> "*"]] Begin["`Private`"] ClearAll[Evaluate[Context[] <>...


1

The answer is in their FAQ: https://www.wolfram.com/cdf/faq/ Why can't I edit text in CDF Player? CDF Player is intended as a deployment option. If you want to edit or create applications or documents, then you need Mathematica or any other CDF content creator, such as Wolfram|Alpha.


1

This is not a full answer As @b3m2a1 suggested, I looked into the paclet and tried updating the functions: p = PacletFind["Service*_*Fl*"] p[[1]]["Location"] Which looks like this: Then I added this to Flickr.m: flickrdata["RawFaves"] := { "URL" -> "https://api.flickr.com/services/rest?method=flickr.favorites.getlist", "...


1

It is "hidden" (in plain sight) at the bottom of the reference doc page. Here is a direct link: https://reference.wolfram.com/language/guide/AlphabeticalListing


1

Try changing IntegerString[Hash[StringJoin[opad,ExportString[IntegerDigits[Hash[StringJoin[ipad, message], method], 256],"Binary"]],method],16] to Developer`EncodeBase64[ FromCharacterCode[ IntegerDigits[ Hash[ StringJoin[ opad, ExportString[ IntegerDigits[ Hash[ StringJoin[ipad, message], "SHA512" ...


Only top voted, non community-wiki answers of a minimum length are eligible