Exceljet

Quick, clean, and to the point

Excel WEBSERVICE Function

Excel WEBSERVICE function
Summary 

The Excel WEBSERVICE function returns data from a web service. The WEBSERVICE function is only available in Excel 2013 and later for Windows.

Purpose 
Get data from a web service
Return value 
Resulting data
Syntax 
=WEBSERVICE (url)
Arguments 
  • url - The url of the web service to call.
Version 
Usage notes 

The WEBSERVICE function returns data from a web service hosted on the internet. The WEBSERVICE function is only available in Excel 2013 and later for Windows.

A web service uses a protocol like HTTP to retrieve data in a machine-readable format like XML or JSON. For example, a formula that uses WEBSERVICE to call a fictitious web service hosted at somewebservice.com might look something like this:

=WEBSERVICE(“http://somewebservice.com/endpoint?query=xxxx”) 

The result from the WEBSERVICE function is returned directly to the worksheet. In cases where the result from a webservice is in XML format, you can use the FILTERXML function to parse the XML. 

Example

A simple example of a web service is RSS, which is used to syndicate content in XML format. RSS is widely available and does not require authentication, so it is an easy way to test the WEBSERVICE function. In the example above, WEBSERVICE is used to fetch breaking news from NASA. The formula in B4 is:

=WEBSERVICE("https://www.nasa.gov/rss/dyn/breaking_news.rss")

RSS uses XML, so the result is a long string of XML that contains the titles of the last 10 news articles published by NASA, along with meta information like description, date, url, and so on. The screen below shows this data in a text editor:

Sample rss in xml format

Parsing the result

When the result from WEBSERVICE is XML, you can use the FILTERXML function to parse the data. In the example shown, this is how the data and title of each article is extracted. The formula in B7 extracts the date, and trims extra characters with the MID function to create an Excel-friendly date:

=MID(FILTERXML(B4,"//item/pubDate"),6,11)

The formula in C7 extracts the title:

=FILTERXML(B4,"//item/title")

Notes

  • When WEBSERVICE can't retrieve data, it returns a #VALUE! error.
  • If the result from WEBSERVICE is more than 32767 characters, it returns a #VALUE! error.

Download 200+ Excel Shortcuts

Get over 200 Excel shortcuts for Windows and Mac in one handy PDF.