A Beginner's Guide to the NetXL API

A Beginner's Guide to the NetXL API

31 Mar 2022 | 3 min read

Quick Summary

A guide to getting started with the NetXL API, which trade account customers can use to query stock availability, request quotes and check pricing.

Checking product pricing, stock availability and even creating and confirming orders are repeat actions that take time.  As your networking business scales, automating some or all of these processes could generate significant ROI.

Our API is available for trade account customers to do just that, enabling networks professionals to pull real-time pricing data for our products, check stock availability, request quotes and create or confirm orders.

As we'll discuss in this introductory guide, no programming experience is necessary to use our API.  Graphical tools like Postman increase the accessibility of API tools so even non-technical members of staff can use them.

The NetXL API is, however, at its most powerful and flexible with a bit of hands-on programming.  In this brief article, we'll give you a rundown of the basics to get you started.

Authentication

Authenticating with the API is as simple as providing your API key with every request. You can read the Getting Started section of the API documentation for instructions on generating an API key for your account.

You can provide the API key for your requests by either setting an 'X-API-KEY' HTTP header or the 'api-key' query string parameter.

Code Example

The following example shows how to perform a simple GET request to the /customer endpoint using Python to fetch the basic details of your NetXL account (such as name, email, and credit terms). In this example, we'll provide the API key as an HTTP header.

 

import requests

BASE_URL = 'https://api.netxl.com'

# This is your private API Key that should be kept secret.
# If your code is public then you should not set your API key here, but instead
# store it separately e.g. in a configuration file or environment variable.
YOUR_API_KEY = 'YOUR_API_KEY'


def get_customer_details():
    # Create a dictionary of HTTP Headers to send with the request
    headers = {
        'X-API-KEY': YOUR_API_KEY,
        'Accept': 'application/json'
    }

    # Perform the API request using python's "requests" library
    response = requests.get(f'{BASE_URL}/customer', headers=headers)

    # Check if the API request was successful
    try:
        response.raise_for_status()
    except requests.HTTPError as e:
        # The API returned a 4xx or 5xx response code - print the details
        # A 401 response indicates that your API key is invalid
        print(e)
        return None

    # Read the response body into a python dictionary
    response_data = response.json()

    # Print the details for demonstrative purposes
    print(response_data)

    return response_data


if __name__ == '__main__':
    get_customer_details()

 

Using Graphical Tools

The API can also be used on an ad-hoc basis without any programming experience, by taking advantage of graphical API tools. Below is an example using Postman.

First, create a new request (or collection), and switch to the 'Authorization' tab. From the 'Type' dropdown choose 'API Key', then set the Key to 'X-API-KEY', and enter your account's API key in the 'Value' input box.

In the 'Enter request URL' input, enter the API endpoint you wish to query (we use 'https://api.netxl.com/customer' in this example). Finally, simply hit the 'Send' button, and your request will be sent to the API. A response will appear in the UI soon after.

 

View the full API documentation here.

A Beginner's Guide to the NetXL API