WEBSERVICE function
Downloads the text returned by a web address (for example an API) straight into a cell.
Available in Excel 2013 and later for Windows, including Microsoft 365 for Windows; not available in Excel for the web or Excel for Mac
Excel 2013 and laterNot in Google Sheets
Syntax
WEBSERVICE(url)| Argument | What it means | |
|---|---|---|
url | Required | The full http or https address to call, as text. It may be up to 2,048 characters long. |
Returns: The raw text that the web service sends back - XML, JSON, CSV or plain text.
How WEBSERVICE works
WEBSERVICE calls a web address and returns whatever the server sends back, as text in the cell. Point it at an API that returns an exchange rate, a stock level from your web shop, or a status message, and the value appears in your sheet. Combined with FILTERXML for XML responses, it lets you build simple live lookups without macros.
The address must be publicly reachable with a simple GET request: WEBSERVICE cannot sign in, send headers or post data. The response must be text no longer than 32,767 characters. Because the results come from outside, the examples below show typical responses rather than fixed values. The function recalculates when the workbook recalculates, so heavy use can slow a file down and may run into the service's rate limits.
Build query values with ENCODEURL so spaces and symbols do not break the address. For JSON, larger data or anything that needs authentication, Power Query (Data > Get Data > From Web) is the better tool.
Examples
1Call a simple API
| A | B | C | |
|---|---|---|---|
| 1 | From | To | Response |
| 2 | EUR | USD | The text returned by the service, e.g. 1.0842 |
Result: The text returned by the service, e.g. 1.0842
The address is built from the two currency codes. The cell shows the server's reply as text - for a service that returns just the rate, something like 1.0842.
2Read one value from an XML reply
| A | B | |
|---|---|---|
| 1 | Product code | Stock |
| 2 | P-103 | The available quantity reported by the shop, e.g. 42 |
Result: The available quantity reported by the shop, e.g. 42
WEBSERVICE downloads an XML document, and FILTERXML picks out the available element. Because FILTERXML converts numbers, the result can be used in calculations.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#VALUE! | The service could not be reached, the response is longer than 32,767 characters, the URL is longer than 2,048 characters, or the protocol is not http/https. | Test the URL in a browser, shorten the request, or use Power Query for larger responses. |
#VALUE! | The service needs a login, API key header or POST request. | WEBSERVICE only does anonymous GET requests; use Power Query or VBA. |
#NAME? | The file is open in Excel for the web or Excel for Mac. | Use Power Query instead. |
Tips
- Put the API key (if it goes in the URL) in a separate cell, and never share the workbook with real keys in it.
- Wrap the call in IFERROR so a temporary network problem does not break dependent formulas.
Google Sheets
Use IMPORTDATA, IMPORTXML or IMPORTHTML, or UrlFetchApp in Apps Script for APIs.
WEBSERVICE in other languages
In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.
| Language | Function name |
|---|---|
| Danish | WEBTJENESTE |
| Finnish | VERKKOPALVELU |
| French | SERVICEWEB |
| German | WEBDIENST |
| Hungarian | WEBSZOLGÁLTATÁS |
| Italian | SERVIZIO.WEB |
| Norwegian (Bokmål) | NETTJENESTE |
| Portuguese (Brazil) | SERVIÇOWEB |
| Portuguese (Portugal) | SERVIÇOWEB |
| Russian | ВЕБСЛУЖБА |
| Spanish | SERVICIOWEB |
| Swedish | WEBBTJÄNST |
| Turkish | WEBHİZMETİ |