PHPackages                             moesif/moesifapi-php - 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. moesif/moesifapi-php

ActiveLibrary[API Development](/categories/api)

moesif/moesifapi-php
====================

Log HTTP API Requests/Responses to Moesif

v1.2.0(10mo ago)43501Apache-2.0PHPPHP &gt;=5.4.0CI failing

Since Apr 9Pushed 10mo ago5 watchersCompare

[ Source](https://github.com/Moesif/moesifapi-php)[ Packagist](https://packagist.org/packages/moesif/moesifapi-php)[ Docs](https://moesif.com)[ RSS](/packages/moesif-moesifapi-php/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (3)Versions (22)Used By (1)

MoesifApi Lib for PHP
=====================

[](#moesifapi-lib-for-php)

[![Built For](https://camo.githubusercontent.com/1576180116dddb71bc45d9aeb798e4197fc6be5b6f0adbdf1070e76acd545f03/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c74253230666f722d7068702d626c75652e737667)](http://www.php.net/)[![Latest Version](https://camo.githubusercontent.com/e5649cfb07c57bd51cffdf3a8afd7c3f5fd372f0f176a111d29416d982ae680f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f657369662f6d6f657369666170692d7068702e737667)](https://packagist.org/packages/moesif/moesifapi-php)[![Software License](https://camo.githubusercontent.com/109222cb0d1f59ed2e77b56722653623fa45f93e2bb201a6eef8561d26a52185/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d417061636865253230322e302d677265656e2e737667)](https://raw.githubusercontent.com/Moesif/moesifapi-php/master/LICENSE)[![Source Code](https://camo.githubusercontent.com/6612ee314176605fbd3857d0cedd7cf570dadae536c90c94dd85e5588b9edd62/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f6d6f657369662f6d6f657369666170692d7068702e7376673f7374796c653d736f6369616c)](https://github.com/moesif/moesifapi-php)

[Source Code on GitHub](https://github.com/moesif/moesifapi-php)

**Check out Moesif's [Developer Documentation](https://www.moesif.com/docs) and [PHP API Reference](https://www.moesif.com/docs/api?php) to learn more**

How To Install
--------------

[](#how-to-install)

Install via Composer

```
composer require moesif/moesifapi-php
```

How To Use:
-----------

[](#how-to-use)

For using this SDK do the following:

1. Use Composer to install the dependencies. See the section "How To Build".
2. See that you have configured your SDK correctly. See the section "How To Configure".
3. Depending on your project setup, you might need to include composer's autoloader in your PHP code to enable autoloading of classes.

    ```
    require_once "vendor/autoload.php";
    ```
4. Import the SDK client in your project:

    ```
    use Moesif\Sender\MoesifApi;
    ```
5. Instantiate the client. After this, you can now access the Moesif API and call the respective methods:

    ```
    $client = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
    ```

Your Moesif Application Id can be found in the [*Moesif Portal*](https://www.moesif.com/). After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.

You can always find your Moesif Application Id at any time by logging into the [*Moesif Portal*](https://www.moesif.com/), click on the top right menu, and then clicking *Installation*.

Create a Single API Event
-------------------------

[](#create-a-single-api-event)

```
use Moesif\Sender\MoesifApi;

$reqdate = new DateTime();
$rspdate = new DateTime();

$event= array(
    "request" => array(
        "time" => $reqdate->format(DateTime::ISO8601),
        "uri" => "https://api.acmeinc.com/items/reviews/",
        "verb" => "PATCH",
        "api_version" => "1.1.0",
        "ip_address" => "61.48.220.123",
        "headers" => array(
          "Host" => "api.acmeinc.com",
          "Accept" => "_/_",
          "Connection" => "Keep-Alive",
          "User-Agent" => "moesifapi-php/1.1.0",
          "Content-Type" => "application/json",
          "Content-Length" => "126",
          "Accept-Encoding" => "gzip"),
         "body" => array(
          "review_id" => 132232,
          "item_id" => "ewdcpoijc0",
          "liked" => false
        )
    ),
    "response" => array(
        "time" => $rspdate->format(DateTime::ISO8601),
        "status" => 500,
        "headers" => array(
          "Date" => "Tue, 12 June 2020 23:46:49 GMT",
          "Vary" => "Accept-Encoding",
          "Pragma" => "no-cache",
          "Expires" => "-1",
          "Content-Type" => "application/json; charset=utf-8",
          "X-Powered-By" => "ARR/3.0",
          "Cache-Control" => "no-cache",
          "Arr-Disable-Session-Affinity" => "true"),
          "body" => array(
            "item_id" => "13221",
            "title" => "Red Brown Chair",
            "description" => "Red brown chair for sale",
            "price" => 22.23
        )
    ),
    "metadata" => array(
        "foo" => "bar"
    ),
    "user_id" => "12345",
    "company_id" => "67890",
    "session_token" => "23jdf0owekfmcn4u3qypxg09w4d8ayrcdx8nu2ngs98y18cx98q3yhwmnhcfx43f"
);

$apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
$apiClient->createEvent($event);
```

Update a Single User
--------------------

[](#update-a-single-user)

Create or update a user profile in Moesif. The metadata field can be any customer demographic or other info you want to store. Only the `user_id` field is required.

```
use Moesif\Sender\MoesifApi;

// Only userId is required.
// Campaign object is optional, but useful if you want to track ROI of acquisition channels
// See https://www.moesif.com/docs/api#users for campaign schema
// metadata can be any custom object
$user = array(
    "user_id" => "12345",
    "company_id" => "67890", // If set, associate user with a company object
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "email" => "john@acmeinc.com",
        "first_name" => "John",
        "last_name" => "Doe",
        "title" => "Software Engineer",
        "sales_info" => array(
            "stage" => "Customer",
            "lifetime_value" => 24000,
            "account_owner" => "mary@contoso.com"
        )
    )
);

$apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
$apiClient->updateUser($user);
```

Update Users in Batch
---------------------

[](#update-users-in-batch)

Similar to update user, but used to update a list of users in one batch. Only the `user_id` field is required.

```
use Moesif\Sender\MoesifApi;

$userA = array(
    "user_id" => "12345",
    "company_id" => "67890", // If set, associate user with a company object
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "email" => "john@acmeinc.com",
        "first_name" => "John",
        "last_name" => "Doe",
        "title" => "Software Engineer",
        "sales_info" => array(
            "stage" => "Customer",
            "lifetime_value" => 24000,
            "account_owner" => "mary@contoso.com"
        )
    )
);

$userB = array(
    "user_id" => "1234",
    "company_id" => "6789", // If set, associate user with a company object
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "email" => "john@acmeinc.com",
        "first_name" => "John",
        "last_name" => "Doe",
        "title" => "Software Engineer",
        "sales_info" => array(
            "stage" => "Customer",
            "lifetime_value" => 24000,
            "account_owner" => "mary@contoso.com"
        )
    )
);

$users = array($userA, $userB);

$apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
$apiClient->updateUsersBatch($users);
```

Update a Single Company
-----------------------

[](#update-a-single-company)

Create or update a company profile in Moesif. The metadata field can be any company demographic or other info you want to store. Only the `company_id` field is required.

```
use Moesif\Sender\MoesifApi;

// Only companyId is required.
// Campaign object is optional, but useful if you want to track ROI of acquisition channels
// See https://www.moesif.com/docs/api#update-a-company for campaign schema
// metadata can be any custom object
$company = array(
    "company_id" => "67890",
    "company_domain" => "acmeinc.com", // If domain is set, Moesif will enrich your profiles with publicly available info
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "org_name" => "Acme, Inc",
        "plan_name" => "Free",
        "deal_stage" => "Lead",
        "mrr" => 24000,
        "demographics" => array(
            "alexa_ranking" => 500000,
            "employee_count" => 47
        )
    )
);

$apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
$apiClient->updateCompany($company);
```

Update Companies in Batch
-------------------------

[](#update-companies-in-batch)

Similar to update company, but used to update a list of companies in one batch. Only the `company_id` field is required.

```
use Moesif\Sender\MoesifApi;

$companyA = array(
    "company_id" => "67890",
    "company_domain" => "acmeinc.com", // If domain is set, Moesif will enrich your profiles with publicly available info
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "org_name" => "Acme, Inc",
        "plan_name" => "Free",
        "deal_stage" => "Lead",
        "mrr" => 24000,
        "demographics" => array(
            "alexa_ranking" => 500000,
            "employee_count" => 47
        )
    )
);

$companyB = array(
    "company_id" => "6789",
    "company_domain" => "acmeinc.com", // If domain is set, Moesif will enrich your profiles with publicly available info
    "campaign" => array(
        "utm_source" => "google",
        "utm_medium" => "cpc",
        "utm_campaign" => "adwords",
        "utm_term" => "api+tooling",
        "utm_content" => "landing"
    ),
    "metadata" => array(
        "org_name" => "Acme, Inc",
        "plan_name" => "Free",
        "deal_stage" => "Lead",
        "mrr" => 24000,
        "demographics" => array(
            "alexa_ranking" => 500000,
            "employee_count" => 47
        )
    )
);

$companies = array($companyA, $companyB);

$apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
$apiClient->updateCompaniesBatch($companies);
```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance55

Moderate activity, may be stable

Popularity16

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 60% 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 ~232 days

Recently: every ~511 days

Total

14

Last Release

301d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b0b32ccd8f8b52e30bef1135e332fb06e0197436e66ffe2555f5a49cda532ea?d=identicon)[xingwang](/maintainers/xingwang)

![](https://www.gravatar.com/avatar/01d3256f8e2dc2c3e1a7934d4b11d9dccc7936c1b80dea9a0880e73d3448eeae?d=identicon)[moesif](/maintainers/moesif)

![](https://www.gravatar.com/avatar/fc618c4daa24676ee9242436cafb63fec92912c550d2c26c09debdd6d00e65c1?d=identicon)[dkm199](/maintainers/dkm199)

![](https://www.gravatar.com/avatar/fb928dd5f778f90a12145682b148d6ca4ba5e8a037f82b00c5ea289f85ae2b92?d=identicon)[keyur9](/maintainers/keyur9)

---

Top Contributors

[![dgilling](https://avatars.githubusercontent.com/u/9476006?v=4)](https://github.com/dgilling "dgilling (24 commits)")[![keyur9](https://avatars.githubusercontent.com/u/9168390?v=4)](https://github.com/keyur9 "keyur9 (7 commits)")[![dkm199](https://avatars.githubusercontent.com/u/6922402?v=4)](https://github.com/dkm199 "dkm199 (3 commits)")[![matthewoates](https://avatars.githubusercontent.com/u/3092315?v=4)](https://github.com/matthewoates "matthewoates (3 commits)")[![grahamburgsma](https://avatars.githubusercontent.com/u/9092289?v=4)](https://github.com/grahamburgsma "grahamburgsma (2 commits)")[![xinghengwang](https://avatars.githubusercontent.com/u/6666687?v=4)](https://github.com/xinghengwang "xinghengwang (1 commits)")

---

Tags

apisdkMoesif API

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/moesif-moesifapi-php/health.svg)

```
[![Health](https://phpackages.com/badges/moesif-moesifapi-php/health.svg)](https://phpackages.com/packages/moesif-moesifapi-php)
```

###  Alternatives

[bandwidth/sdk

Bandwidth's set of APIs

16948.8k1](/packages/bandwidth-sdk)[messagemedia/messages-sdk

The MessageMedia Messages API provides a number of endpoints for building powerful two-way messaging applications.

13390.6k](/packages/messagemedia-messages-sdk)

PHPackages © 2026

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