PHPackages                             ianfortier/basic-freshsales-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. ianfortier/basic-freshsales-api

ActiveLibrary[API Development](/categories/api)

ianfortier/basic-freshsales-api
===============================

A basic REST Freshsales API wrapper.

14PHP

Since May 5Pushed 6y ago1 watchersCompare

[ Source](https://github.com/ianfortier/Basic-Freshsales-API)[ Packagist](https://packagist.org/packages/ianfortier/basic-freshsales-api)[ RSS](/packages/ianfortier-basic-freshsales-api/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Basic Freshsales API
====================

[](#basic-freshsales-api)

A simple API wrapper for Freshsales using Guzzle. It supports both the REST API provided by Freshsales, and basic rate limiting abilities. Also supported: asynchronous requests through Guzzle's promises.

This library required PHP &gt;= 7.

PS: This project is largely inspired (aka copy &lt;3 ) from [osiset/Basic-Shopify-API](https://github.com/osiset/Basic-Shopify-API).

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)\* [REST (sync)](#rest-sync)\* [REST (async)](#rest-async)
    - [Making requests](#making-requests)\* [If sync is true (regular rest call):](#if-sync-is-true-regular-rest-call)\* [If sync is false (restAsync call):](#if-sync-is-false-restasync-call)
    - [Checking API limits](#checking-api-limits)
    - [Rate Limiting](#rate-limiting)
        - [Enable Rate Limiting](#enable-rate-limiting)
        - [Disabiling Rate Limiting](#disabiling-rate-limiting)
        - [Checking Rate Limiting Status](#checking-rate-limiting-status)
        - [Getting Timestamps](#getting-timestamps)
    - [Errors](#errors)
    - [Logging](#logging)
- [Documentation](#documentation)
- [LICENSE](#license)

Installation
------------

[](#installation)

The recommended way to install is [through composer](http://packagist.org).

```
composer require ianfortier/basic-freshsales-api

```

Usage
-----

[](#usage)

Add `use ianfortier\BasicFreshsalesAPI;` to your imports.

#### REST (sync)

[](#rest-sync)

For REST calls, the shop domain and access token are required.

```
$api = new BasicFreshsaleAPI();

// Now run your requests...
$resul = $api->rest(...);
```

#### REST (async)

[](#rest-async)

For REST calls, the shop domain and access token are required.

```
$api = new BasicFreshsaleAPI();

// Now run your requests...
$promise = $api->restAsync(...);
$promise->then(function ($result) {
  // ...
});
```

### Making requests

[](#making-requests)

#### REST

[](#rest)

Requests are made using Guzzle.

```
$api->rest(string $type, string $path, array $params = null, array $headers = [], bool $sync = true);
```

- `type` refers to GET, POST, PUT, DELETE, etc
- `path` refers to the API path, example: `/api/leads`
- `params` refers to an array of params you wish to pass to the path, examples: `['email' => 'customer@email.com']`
- `headers` refers to an array of custom headers you would like to optionally send with the request, example: `['X-Freshsales-Test' => '123']`
- `sync` refers to if the request should be synchronous or asynchronous.

You can use the alias `restAsync` to skip setting `sync` to `false`.

##### If sync is true (regular rest call):

[](#if-sync-is-true-regular-rest-call)

The return value for the request will be an object containing:

- `response` the full Guzzle response object
- `body` the JSON decoded response body (array)
- `bodyObject` the JSON decoded response body (stdClass)

*Note*: `request()` will alias to `rest()` as well.

##### If sync is false (restAsync call):

[](#if-sync-is-false-restasync-call)

The return value for the request will be a Guzzle promise which you can handle on your own.

The return value for the promise will be an object containing:

- `response` the full Guzzle response object
- `body` the JSON decoded response body (array)
- `bodyObject` the JSON decoded response body (stdClass)

```
$promise = $api->restAsync(...);
$promise->then(function ($result) {
  // `response` and `body` available in `$result`.
});
```

##### Passing additional request options

[](#passing-additional-request-options)

If you'd like to pass additional request options to the Guzzle client created, pass them as the second argument of the constructor.

```
$api = BasicFreshsaleAPI(true, ['connect_timeout' => 3.0]);
```

In the above, the array in the second argument will be merged into the Guzzle client created.

### Checking API limits

[](#checking-api-limits)

After each request is made, the API call limits are updated. To access them, simply use:

```
// Returns an array of left, made, and limit.
// Example: ['left' => 79, 'made' => 1, 'limit' => 80]
$limits = $api->getApiCalls('rest');
```

### Rate Limiting

[](#rate-limiting)

This library comes with a built-in basic rate limiter, disabled by default. It will sleep for *x* microseconds to ensure you do not go over the limit for calls with Freshsales.

By default the cycle is set to 500ms, with a buffer for safety of 100ms added on.

#### Enable Rate Limiting

[](#enable-rate-limiting)

Setup your API instance as normal, with an added:

```
$api->enableRateLimiting();
```

This will turn on rate limiting with the default 500ms cycle and 100ms buffer. To change this, do the following:

```
$api->enableRateLimiting(0.25 * 1000, 0);
```

This will set the cycle to 250ms and 0ms buffer.

#### Disabiling Rate Limiting

[](#disabiling-rate-limiting)

If you've previously enabled it, you simply need to run:

```
$api->disableRateLimiting();
```

#### Checking Rate Limiting Status

[](#checking-rate-limiting-status)

```
$api->isRateLimitingEnabled();
```

### Errors

[](#errors)

This library internally catches only 400-500 status range errors through Guzzle. You're able to check for an error of this type and get its response status code and body.

```
$call = $api->rest('GET', '/xxxx/non-existant-route-or-object');

if ($call->errors) {
  echo "Oops! {$call->status} error";
  var_dump($call->body);

  // Original exception can be accessed via `$call->exception`
  // Example, if response body was `{"error": "Not found"}`...
  /// then: `$call->body` would return "Not Found"
}
```

### Logging

[](#logging)

This library accepts a PSR-compatible logger.

```
$api->setLogger(... your logger instance ...);
```

LICENSE
-------

[](#license)

This project is released under the MIT [license](https://github.com/ianfortier/Basic-Freshsales-API/blob/master/LICENSE).

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/06abf3ec43b9436d5233e60d8f66aee65e0f93f23b68c3d201023cfc192e80ea?d=identicon)[ianfortier](/maintainers/ianfortier)

---

Tags

api-wrapperfreshsalesfreshsales-apilaravelrest-api

### Embed Badge

![Health badge](/badges/ianfortier-basic-freshsales-api/health.svg)

```
[![Health](https://phpackages.com/badges/ianfortier-basic-freshsales-api/health.svg)](https://phpackages.com/packages/ianfortier-basic-freshsales-api)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
