Deskpro Developer Starter
  • Introduction
    • Introduction
  • Embeddables
    • Website Widget
    • Form Embed
  • API Basics
    • API Introduction
    • Auth
      • API Keys
      • API Tokens
        • OAuth
        • Token Exchange Endpoint
      • Access Control
    • API Reference
    • Request Format
    • Batch Requests
    • Sideloading
    • SDKs
  • Getting Started with the API
    • PHP
      • Initialize the client
      • Add a form
      • Create an article
      • Tickets
      • Methods
    • JavaScript
      • Initialize the client
      • Add a form
      • Create an article
      • Methods
Powered by GitBook
On this page
  1. Getting Started with the API
  2. JavaScript

Initialize the client

Let's begin by creating the index.html file, and initializing the client. Copy this code:

<!DOCTYPE>
<html>
  <head>
    <script src="https://unpkg.com/@deskpro/deskpro-api-client-javascript@2.0.0/dist/index.js"></script>
  </head>
  <body>
    <script>
      // Pass the URL to your Deskpro instance when creating the client.
      var client = new DeskproClient('http://deskpro.company.com');

      // Many API methods require authentication. Set the ID of the user
      // to authenticate with and either the auth key or token.
      client.setAuthKey(1, 'dev-admin-code');
      // client.setAuthToken(1, 'AWJ2BQ7WG589PQ6S862TCGY4');

      client.get('/articles')
          .then(function(resp) {
            console.log(resp.data);
          })
          .catch(function(err) {
            console.error(err.message);
          });
    </script>
  </body>
</html>

Open the index.html in your browser and open the debug console. You'll see a bunch of JSON output. Something like:

[
    {
        "id": 107,
        "title": "This is a title",
        ...
    },
    {
        "id": 106,
        "title": "This is a title",
        ...
    }
]
PreviousJavaScriptNextAdd a form

Last updated 6 years ago