PHPackages                             phplicengine/bitly - 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. phplicengine/bitly

ActiveLibrary[API Development](/categories/api)

phplicengine/bitly
==================

Bitly API v4

v1.0.5(3y ago)22305.0k↑141.1%82Apache-2.0PHPPHP &gt;=7.3

Since Nov 1Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/phplicengine/bitly)[ Packagist](https://packagist.org/packages/phplicengine/bitly)[ RSS](/packages/phplicengine-bitly/feed)WikiDiscussions master Synced yesterday

READMEChangelog (6)DependenciesVersions (7)Used By (0)

[![Build Status](https://camo.githubusercontent.com/6cd6a07fc1ba133f8ec4971c6a216eda21493dd18d944647a7e70cfbccb02112/68747470733a2f2f6170702e7472617669732d63692e636f6d2f7068706c6963656e67696e652f6269746c792e7376673f6272616e63683d6d6173746572)](https://app.travis-ci.com/phplicengine/bitly)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3e3e37c8e6b206049e9c0772de03446d16576211e0b200a4a368db919a87a097/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068706c6963656e67696e652f6269746c792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phplicengine/bitly/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/f413d1df32faf88614d63de576af2a8b89d63000d410339854e8527e317c7d02/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068706c6963656e67696e652f6269746c793f6c6162656c3d76657273696f6e)](https://packagist.org/packages/phplicengine/bitly)[![Total Downloads](https://camo.githubusercontent.com/ba86d13595db3625b1d0dce4b9f4628ebe589cdedcb1cda6c39224c29125df85/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068706c6963656e67696e652f6269746c793f636f6c6f723d626c7565)](https://packagist.org/packages/phplicengine/bitly)[![php](https://camo.githubusercontent.com/b296199f908e3a57f63dbb993c176f7921bbda319961305edcb24296bb87f872/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7068706c6963656e67696e652f6269746c79)](https://packagist.org/packages/phplicengine/bitly)[![License](https://camo.githubusercontent.com/aa1c1897375861849c8aeba0349e20417618b9473660067925c5a1638dabb395/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068706c6963656e67696e652f6269746c79)](https://packagist.org/packages/phplicengine/bitly)

Bitly API v4
============

[](#bitly-api-v4)

Contents
--------

[](#contents)

- [Installation](#installation)
- [Usage](#usage)
- [Manual](#manual)
- [Contributing and Support](#contributing-and-support)
- [License](#license)

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

[](#installation)

```
composer require phplicengine/bitly

```

Usage
-----

[](#usage)

```
use PHPLicengine\Api\Api;
use PHPLicengine\Service\Bitlink;

$api = new Api("API KEY GOES HERE");
$bitlink = new Bitlink($api);
$result = $bitlink->createBitlink(['long_url' => 'http://www.example.com']);

// if cURL error occurs.
if ($api->isCurlError()) {

    print($api->getCurlErrno().': '.$api->getCurlError());

} else {

    // if Bitly response contains error message.
    if ($result->isError()) {

        print("Error:");
        print($result->getResponse());
        print($result->getDescription());

    } else {

        // if Bitly response is 200 or 201
        if ($result->isSuccess()) {

            print("SUCCESS:");
            print($result->getResponse());
            print_r($result->getResponseArray());

        } else {

            print("FAIL:");
            print($result->getResponse());
            print_r($result->getResponseArray());

        }
    }
}

// for debug only.
print("INFO:");

// returns response exactly as it is. e.g. json.
$resj = $result->getResponse();
print($resj."");

// returns decoded json.
$reso = $result->getResponseObject();
print_r($reso);

// returns header of server.
$resh = $result->getHeaders();
print_r($resh);

// returns request.
$resr = $api->getRequest();
print_r($resr);
```

Manual
------

[](#manual)

#### Service Classes

[](#service-classes)

In [Bitly API v4](https://dev.bitly.com/api-reference) documentations, resources are classified under serveral categories:

Bitlink, Group, Organization, User, Custom, Campaign, Bsd, OAuth, Auth, Webhook

We made each of them as a separate service class. Method names are the same as the last part of documentation url. For example if you want to use [Get Metrics for a Bitlink by Country](https://dev.bitly.com/api-reference#getMetricsForBitlinkByCountries), this one is classified under Bitlink category in documentation and the last part of its url is `getMetricsForBitlinkByCountries`, so you can call it this way:

```
use PHPLicengine\Api\Api;
use PHPLicengine\Service\Bitlink;

$api = new Api("API KEY GOES HERE");
$bitlink = new Bitlink($api);
$result = $bitlink->getMetricsForBitlinkByCountries('bit.ly/34nRNvl', ['unit' => 'day', 'units' => -1]);
```

All Path parameters, must be passed as string in first argument of methods if necessary and all Query parameters must be passed as array in second argument of methods if necessary. If Path parameter is not needed, Query parameters will be first argument of methods.

Another example:

[Retrieve Group Shorten Counts](https://dev.bitly.com/api-reference#getGroupShortenCounts) is classified under Group category, and the last part of its link is `getGroupShortenCounts`, so you can call it this way:

```
use PHPLicengine\Api\Api;
use PHPLicengine\Service\Group;

$api = new Api("API KEY GOES HERE");
$group = new Group($api);
$result = $group->getGroupShortenCounts($group_guid);
```

Here is [list of available service classes and methods](Services.md).

#### Custom cURL Options

[](#custom-curl-options)

By default cURL timeout is 30. You can change it with:

```
$api->setTimeout(30);
```

If you need to add some CURLOPT\_\* constants that are not enabled by default, you can call setCurlCallback() method to add them.

```
use PHPLicengine\Api\Api;
use PHPLicengine\Service\Bitlink;

$api = new Api("API KEY GOES HERE");
$api->setCurlCallback(function($ch, $params, $headers, $method) {
      curl_setopt($ch, CURLOPT_*, 'some value');
});
$bitlink = new Bitlink($api);
```

This is added for your convenience, but you should not need it.

Contributing and Support
------------------------

[](#contributing-and-support)

For all issues or feature request or support questions please open a new [issue](https://github.com/phplicengine/bitly/issues). All pull requests are welcome.

License
-------

[](#license)

PHPLicengine Api is distributed under the Apache License. See [License](LICENSE).

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance59

Moderate activity, may be stable

Popularity50

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.9% of commits — single point of failure

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.

###  Release Activity

Cadence

Every ~240 days

Recently: every ~300 days

Total

6

Last Release

1233d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.2

v1.0.5PHP &gt;=7.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13603184?v=4)[PHPLicengine](/maintainers/phplicengine)[@phplicengine](https://github.com/phplicengine)

---

Top Contributors

[![phplicengine](https://avatars.githubusercontent.com/u/13603184?v=4)](https://github.com/phplicengine "phplicengine (338 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (22 commits)")

---

Tags

apiapi-clientapi-restapi-serverapi-servicebitlinksbitlybitly-apibitly-clientbitly-v4link-shortenerphpphp7php72shorten-urlsshortenershortens-linksshorturlurl-shortenerurlshortenerphpapibitlyshortenerapi clienturl shortenerPHP7api-servicerestapiShorturlurlshortenerapi-servershorten-urlsapi-restphp72bitlinksbitly-apibitly-v4bitly-clientshortens-linkslink-shortener

### Embed Badge

![Health badge](/badges/phplicengine-bitly/health.svg)

```
[![Health](https://phpackages.com/badges/phplicengine-bitly/health.svg)](https://phpackages.com/packages/phplicengine-bitly)
```

###  Alternatives

[fabian-beiner/todoist-php-api-library

A PHP client library that provides a native interface to the official Todoist REST API.

4812.3k](/packages/fabian-beiner-todoist-php-api-library)[uderline/openapi-php-attributes

Automatically render your OpenApi 3 file describing your PHP API using attributes

2137.1k](/packages/uderline-openapi-php-attributes)[jeffreyhyer/bamboohr

PHP SDK for the BambooHR API

1087.8k1](/packages/jeffreyhyer-bamboohr)[jeffreyhyer/alpaca-trade-api-php

PHP SDK for the Alpaca trade API

285.6k](/packages/jeffreyhyer-alpaca-trade-api-php)

PHPackages © 2026

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