# Wolfram API Examples

This section is designed for Excel users and developers of Wolfram APIs. It uses pre-deployed Wolfram APIs to show how a Wolfram Cloud can be called from Excel.

If you have not installed the CloudConnector for Excel, please see the Setup and Getting Started section for more details on the installation process.

## Excel Users

This section is for Excel users and shows how to run through the example spreadsheet, which contains Excel functions that call Wolfram APIs. To download the example spreadsheet, go to the CloudConnector for Excel resources webpage.

### Example: Basic

This example shows the basics of how to call a Wolfram API from Excel. It calls a Wolfram API with two parameters and adds them together.

Load the example spreadsheet and go to the Basic worksheet.

Altering one of the parameter values will trigger a recalculation, calling the Wolfram Cloud. Parameters and must be numbers.

The worksheet contains a formula with the Excel function, WolframAPI, which calls the Wolfram Cloud. The following is the formula used in the Excel worksheet:

=WolframAPI("/Documentation/Example/AddTwo", Parameter("x", D9), Parameter("y", D10))

This formula contains the name of the Wolfram API and references to the two parameters the API requires.

If this fails to execute correctly, please see the Troubleshooting section.

If you want to learn more about the Excel functions, see the Calling Wolfram APIs section.

If you want to learn how to write this API, see Developers > Example: AddTwo.

### Example: Grid of Data

This example takes two numbers and uses them to generate a matrix of random data corresponding to the parameter values.

Load the example spreadsheet and go to the Grid of Data worksheet.

Altering one of the parameter values will trigger a recalculation, calling the Wolfram Cloud. Parameters nrows and ncols must be numbers.

The worksheet contains a formula with the Excel function WolframAPI (located at E8), which calls the Wolfram Cloud. The following is the formula used in the Excel worksheet:

=WolframAPI("/Documentation/Example/GenerateMatrix", Parameter("nrows", C9), Parameter("ncols", C10))

This formula contains the name of the Wolfram API and references to the two parameters the API requires. The result is a formula array that fills out from the top-left cell, the size of which is specified by the parameters given.

If this fails to execute correctly, please see the Troubleshooting section.

If you want to learn more about the Excel functions, see the Calling Wolfram APIs section.

If you want to learn how to write this API, see Developers > Example: Grid of Numbers.

### Example: Plot Numbers

This example takes a vector of numbers and generates a plot of the selected data.

Altering one of the parameter values will cause a recalculation, calling the Wolfram Cloud. Parameters of data must be a number.

The worksheet contains a formula with the Excel function WolframAPI (located at E8), which calls the Wolfram Cloud. The following is the formula used in the Excel worksheet:

=WolframAPI("/Documentation/Example/PlotNumbers", Parameter("data", C9:C17))

This formula contains the name of the Wolfram API and references to the parameters the API requires. The result is a plot in a floating window above the spreadsheet. Underneath the plot is the cell containing the formula for calling the Wolfram API. It is important to leave this, should there be any changes to the parameters.

If this fails to execute correctly, please see the Troubleshooting section.

If you want to learn more about the Excel functions, see the Calling Wolfram APIs section.

If you want to learn how to write this API, see Developers > Example: Plot Numbers.

### Example: Grid of Plots

This example takes a vector of numbers and generates a matrix of plots.

Altering one of the parameter values will trigger a recalculation, calling the Wolfram Cloud. Parameters of data must be a number.

The worksheet contains a reference to the Excel function that calls the cloud, WolframAPI (located at E8). The following is the formula used in the Excel worksheet:

=WolframAPI("/Documentation/Example/GridOfPlots", Parameter("values", C9:C24))

This formula contains the name of the Wolfram API and references to the parameters the API requires. The result is a plot in a floating window above the spreadsheet. Underneath the plots is a group of cells, containing the formula array for calling the Wolfram API. It is important to leave this, should there be any changes to the parameters.

If this fails to execute correctly, please see the Troubleshooting section.

If you want to learn more about the Excel functions, see the Calling Wolfram APIs section.

If you want to learn how to write this API, see Developers > Example: Grid Of Plots.

### Example: Authenticated API

This example gives two IDs relating to your cloud account. You have to be signed in access the Wolfram API.

Load the example spreadsheet and go to the Authenticated API worksheet.

Before running the API, please sign in. To run the API, press F2 and press Enter. This will trigger a recalculation, calling the Wolfram Cloud.

The worksheet contains a formula with the Excel function WolframAPI (located at C9), which calls the Wolfram Cloud. The following is the formula used in the Excel worksheet:

=WolframAPI("/Documentation/Example/AuthenticatedAPI")

If this fails to execute correctly, please see the Troubleshooting section.

If you want to learn more about the Excel functions, see the Calling Wolfram APIs section.

If you want to learn how to write this API, see Developers > Example: Authenticated API.

## Developers

This section is for developers and contains information about how to write and deploy APIs from the example spreadsheet. To deploy these examples from your cloud account and use them in Excel, you will need to use the Wolfram Cloud or a Wolfram Language desktop environment. Please see the Setup and Getting Started section for more details.

### Example: Basic

To run the pre-deployed Wolfram API in Excel, see Excel User > Example: Basic.

The API will add two numbers together and return this result into a single cell within Excel.

The following is the code required to deploy the Wolfram API:

CloudDeploy[

APIFunction[

{"x""Real","y""Real"},

#x+#y&,

AllowedCloudExtraParameters All

],

"TestExample/AddTwo",

Permissions "Public"

]

It contains two parameters, "x" and "y", which both have Interpreter types of "Real".

When constructing Wolfram APIs, make sure you have included AllowedCloudExtraParameters->All to allow operation with CloudConnector for Excel. To deploy, wrap the CloudDeploy function around the APIFunction. Supply a URI to identify your Wolfram API and set the Permissions of the API to "Public".

More information on writing APIs for CloudConnector for Excel is seen in the Writing Wolfram APIs section.

### Example: Grid of Numbers

To run the pre-deployed Wolfram API in Excel, see Excel Users > Example: Grid of Numbers.

The API will create an array of randomized values between 0 and 1024.

The following is the code required to deploy the Wolfram API:

CloudDeploy[

APIFunction[

{"nrows" -> "Integer", "ncols" -> "Integer"},

RandomInteger[{0, 1024}, {#nrows, #ncols}] &,

AllowedCloudExtraParameters -> All

],

"TestExample/GridOfNumbers",

Permissions "Public"

]

It contains two parameters, nrows and ncols, which both have Interpreter types of "Real".

When constructing Wolfram APIs, make sure you have included AllowedCloudExtraParameters->All to allow operation with CloudConnector for Excel. To deploy, wrap the CloudDeploy function around the APIFunction. Supply a URI to identify your Wolfram API and set the Permissions of the API to "Public".

More information on writing APIs for CloudConnector for Excel is seen in the Writing Wolfram APIs section.

### Example: Plot Numbers

To run the pre-deployed Wolfram API in Excel, see Excel Users > Example: Plot Numbers.

The API will create an ListLinePlot from a column of numbers.

The following is the code required to deploy the Wolfram API:

CloudDeploy[

APIFunction[

{"data" -> RepeatingElement["Number"]},

ListLinePlot[#data] &,

AllowedCloudExtraParameters -> All

],

"TestExample/PlotNumbers",

Permissions "Public"

]

It contains a single parameter that has the Interpreter type RepeatingElement["Number"]. This means the API can take any number of values that have the Interpreter type "Number".

When constructing Wolfram APIs, make sure you have included AllowedCloudExtraParameters->All to allow operation with CloudConnector for Excel. To deploy, wrap the CloudDeploy function around the APIFunction. Supply a URI to identify your Wolfram API and set the Permissions of the API to "Public".

More information on writing APIs for CloudConnector for Excel is seen in the Writing Wolfram APIs section.

### Example: Grid of Plots

To run the pre-deployed Wolfram API in Excel, see Excel Users > Example: Grid of Plots.

The API will create a matrix of plots from a column of numbers.

The following is the code required to deploy the Wolfram API:

CloudDeploy[

APIFunction[

{"data" -> RepeatingElement["Number"]},

{{ListLinePlot[#data],BarChart[#data]},{ListPlot[#data]}} &,

AllowedCloudExtraParameters -> All

],

"TestExample/GridOfPlots",

Permissions "Public"

]

It contains a single parameter that has the Interpreter type RepeatingElement["Number"]. This means the API can take any number of values that have the Interpreter type "Number".

### Example: Authenticated API

To run the pre-deployed Wolfram API in Excel, see Excel Users > Example: Authenticated API.

The API will create two values, the $RequesterWolframID and $RequesterWolframUUID, which are values specific to the caller of the API.

The following is the code required to deploy the Wolfram API:

CloudDeploy[

APIFunction[

{},

{$RequesterWolframID, $RequesterWolframUUID }& ,

AllowedCloudExtraParameters -> All

],

"TestExample/AuthenticatedAPI",

Permissions "Authenticated"{"Read"}

]

It contains no parameters, and to use it, the caller must be authenticated to the Wolfram Cloud.