XLConnect
  • XLConnect Documentation
  • Using XLConnect
    • Getting Started
    • Using XLConnect
    • Manage Users
    • Manage Your Subscription (Owners)
    • XLConnect Security
    • Troubleshooting
  • Developing with XLConnect
    • Getting Started
    • The Bigger Picture
    • Import Scripts
    • Scripts
    • Cloud Systems
    • Javascript
      • Javascript Studio
      • Javascript language
      • Calling API's with HTTP Requests
      • Working with JSON data
      • The xlc object
      • Advanced Javascript
    • Modules
      • HTTP module
      • FILE module
    • Maps
    • JSON Data Format
    • Data Lake
    • Excel modelling
    • VBA
    • The XLConnect API
  • Reference
    • Change log
Powered by GitBook
On this page
  • A sample Web request using XLConnect
  • Anatomy of an HTTP request
  • URI
  • Headers
  • Content
  1. Developing with XLConnect
  2. Javascript

Calling API's with HTTP Requests

How to talk to web API's using HTTP requests

PreviousJavascript languageNextWorking with JSON data

Last updated 1 year ago

The Language of the Web

You are probably already familiar with the Hyper Text Transfer Protocol (HTTP) as that is how your web browser talks to web servers over the internet to show you web pages. Your browser sends an http request to a web server, that responds with a http response with html data that will be rendered in your browser for you to read.

This same technology can also be used to request and serve data, that better suited for programs to read. Instead of serving html they respond with data, typically json or xml. These are call Application Programming Interfaces or API's.

XLConnect has a built in HTTP client that allows Excel to call these API's with minimal technical friction.

A sample Web request using XLConnect

In the , this code will execute an HTTP request and display the data.

Copy and paste it into a new Javascript Studio window and hit F5 to execute it.

http = require('http.js')                // use the http module with wrapper methods 
uri = 'https://swapi.dev/api/people/'    // uri with details about starwars characters
sw = http.get(uri)                       // get the data and assign to sw variable 

This code grabs data (click to see the raw data) about Star Wars characters. Double click the results element to drill down to the actual characters.

Please not this uses the method that handles

Anatomy of an HTTP request

An HTTP request has three major parts:

  1. The Unique Resource Identifier URI (sometimes also called URL for Locator)

  2. The Headers

  3. The Content

API's have not really converged to a uniform way of using these elements to make it work, so be prepared to use all of them.

URI

You will have seen many uri's in your life, to make sure you understand exactly what each part means, below is a short summary.

Headers

Headers are key-value properties that be sent and received, this allows both client and server to add properties to a request. Xero for instance requires that every request has a property xero-tenant-id to indicate for which tenant the request is meant for. Another often used property is

Content

The Content of a web request is the actua thing you wat to send and/ or recieve, in today's

Javascript Studio
here
HTTP module GET
GETting a uri and displaying the results.
Anatomy or a URI