Trying to install pipedrive API with PHP and composer

update- i was able to resolve by manual installation (download files from github, install in separate directory, run composer update)

–––––

I’m using the following code from the example (GitHub - pipedrive/client-php: Pipedrive API client for PHP). I’m running PHP 7.4.3 and get this error

“Uncaught Error: Call to undefined method Pipedrive\Configuration::setApiKey()”

$ssdpath = get_stylesheet_directory();

use Pipedrive\Configuration;

require_once($ssdpath . '/vendor/autoload.php');


// Create a Configuration object and set the API key as an array

// Configure API key authorization: api_key
$config = (new Pipedrive\Configuration())->setApiKey('api_token', 'YOUR_API_KEY');

$apiInstance = new Pipedrive\Api\ActivitiesApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client(),
    $config
);

try {
    $result = $apiInstance->getActivities();
    echo '<pre>';
    print_r($result);
    echo '</pre>';
} catch (Exception $e) {
    echo 'Exception when calling ActivitiesApi->getActivities: ', $e->getMessage(), PHP_EOL;
}

If I use just this code, i do not get any error:

$ssdpath = get_stylesheet_directory();

use Pipedrive\Configuration;

require_once($ssdpath . '/vendor/autoload.php');


// Create a Configuration object and set the API key as an array
$config = new \Pipedrive\Configuration();

So it seems like for whatever reason the setApiKey method is not available?

I have tried uninstalling pipedrive with composer and then reinstalling, and get the same result.

If it’s of any consequence, I am using composer via SSH on a wpengine server. Thanks


I attempted to install the API with openapi generator:

openapi-generator generate -i https://developers.pipedrive.com/docs/api/v1/openapi.yaml -g php -o ./

which seemed to install something…

but it’s not at all clear to me how to include an autoload.php or equivalent file after installing it.

Please help!

Hello @handiwork , welcome to the community!

I tried here with a blank project, using the example code, and it worked for me.

Here is my code:

<?php
use Pipedrive\Configuration;

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

// Configure API key authorization: api_key
$config = (new Pipedrive\Configuration())->setApiKey('api_token', 'YOUR_API_KEY');

$apiInstance = new Pipedrive\Api\ActivitiesApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client(),
    $config
);

try {
    $result = $apiInstance->getActivities();
    echo '<pre>';
    print_r($result);
    echo '</pre>';
} catch (Exception $e) {
    echo 'Exception when calling ActivitiesApi->getActivities: ', $e->getMessage(), PHP_EOL;
}

?>

composer.json contents:

{
    "autoload": {
        "psr-4": {"Test\\": "public/"}
    },
    "require": {
        "pipedrive/pipedrive": "*"
    }
}

The file structure looks like this: