Web function

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)
ArgumentWhat it means
urlRequiredThe 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

C2fx=WEBSERVICE("https://api.example.com/rate?from=" & A2 & "&to=" & B2)
ABC
1FromToResponse
2EURUSDThe 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

B2fx=FILTERXML(WEBSERVICE("https://shop.example.com/stock.xml?sku=" & ENCODEURL(A2)), "//available")
AB
1Product codeStock
2P-103The 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.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 13 KB

Common errors and how to fix them

ErrorWhy it happensFix
#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.

LanguageFunction name
DanishWEBTJENESTE
FinnishVERKKOPALVELU
FrenchSERVICEWEB
GermanWEBDIENST
HungarianWEBSZOLGÁLTATÁS
ItalianSERVIZIO.WEB
Norwegian (Bokmål)NETTJENESTE
Portuguese (Brazil)SERVIÇOWEB
Portuguese (Portugal)SERVIÇOWEB
RussianВЕБСЛУЖБА
SpanishSERVICIOWEB
SwedishWEBBTJÄNST
TurkishWEBHİZMETİ