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. PHP

Initialize the client

Let's begin by initializing the API client in our form.php file. Copy this code:

<?php
use Deskpro\API\DeskproClient;
use Deskpro\API\Exception\APIException;

include(__DIR__ . '/vendor/autoload.php');

// Pass the URL to your Deskpro instance when creating the client.
$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');

try {
    $resp = $client->get('/articles');
    print_r($resp->getData());
    print_r($resp->getMeta());
} catch (APIException $e) {
    echo $e->getMessage();
}

Run this page in your browser and you'll see a bunch of JSON output. Something like:

Array
(
    [0] => Array
        (
            [id] => 1
            [title] => "Mary Had a Little Lamb"
            ...
        )

    [1] => Array
        (
            [id] => 2
            [title] => "Baa Baa Black Sheep"
            ...
        )
)
Array
(
    [pagination] => Array
        (
            [total] => 2
            [count] => 2
            [per_page] => 10
            [current_page] => 1
            [total_pages] => 1
        )
)
PreviousPHPNextAdd a form

Last updated 6 years ago