Download the PHP package mycomm/mycomm-php without Composer

On this page you can find all versions of the php package mycomm/mycomm-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mycomm-php

MyComm PHP SDK

The official PHP client for the MyComm messaging API: send and track messages, manage contacts and conversations, receive webhooks, and (for partners) provision customer accounts.

Requires PHP 8.2 or later. Using Laravel? Install mycomm/mycomm-laravel instead: it adds configuration, a facade and a webhook route on top of this package.

Install

The SDK talks HTTP through any PSR-18 client. If your project has none yet:

Quick start

Create the key in the MyComm portal under Developers → API keys. Keep it on your server: never ship it in a browser or a mobile app.

How the SDK maps to the API

Each resource of the API reference is a property of the client and each operation a method. The reference names an operation with a verb in camelCase (sendMessage); the SDK groups the operations by resource, so the same call reads messages->send():

Operation id in the reference Call
sendMessage $mycomm->messages->send(...)
upsertContactByIdentity $mycomm->contacts->upsertByIdentity(...)
blockContactIdentity $mycomm->contacts->identities->block($contactId, $identityId)
rotateWebhookEndpointSecret $mycomm->webhookEndpoints->rotateSecret($id)
provisionManagedAccount $mycomm->partner->accounts->provision(...)

generator/config.php holds the full table of operation ids.

Arguments are named like the API's fields (reference_id, send_after), so the reference and your editor's autocompletion agree. Ids in the path come first; everything else is best passed by name.

Sending messages

Check what a send would do without sending it:

Send up to 1,000 messages in one call. Items are accepted or rejected one by one:

Follow a message afterwards with $mycomm->messages->show($id), or let MyComm tell you through webhooks.

What the SDK checks before sending

The API documents limits and rules for what you send: ranges, lengths, which fields exclude each other, which need another. The SDK checks them first, so a mistake fails at once with the field named, instead of as a 422 from the server:

Rule Example
Ranges and lengths expires_in 60 to 604800; reference_id 1 to 100 characters without spaces; limit 1 to 200
Allowed values category is transactional or marketing; lane is high, normal or bulk
Formats ids are UUIDs
Sizes metadata at most 50 keys, 2048 bytes as JSON, scalar values only
Exactly one of to or contact_id
At least one of content, body, media_ids or template_id
Needs another field variables needs template_id; category is required when lane is bulk

The rules are generated from the API's OpenAPI document, so they follow the API. Nothing is sent when one fails. Rules the SDK does not know about, such as an opt-out, are still answered by the server (see Errors).

If the API relaxes a rule before you have updated the SDK, turn the checks off with new Client(..., validate: false). Values the API may add later (the enum of a response, an unknown error code) are never rejected.

Verify your settings

verify() checks that a key works and, when you give it a number to test with, that a message to that number would be accepted. It sends nothing: the second check is a dry run.

A dry run does not know whether the phone is online or whether the carrier delivers; a hold it can predict is in $result->holdReason. See the guide Verify your integration.

Lists and pagination

A list method returns one Page. Loop over it for the items of that page, or use all() to walk every page; the next page is fetched only when the loop reaches it.

$page->next_cursor, $page->hasMore() and $page->next() are there when you page by hand, and $page->autoPaging() does what all() does for lists that are not named list ($mycomm->conversations->messages($id)->autoPaging()).

Leaving a field out or clearing it

An update changes only the fields you pass. Where a field can be cleared, null clears it:

Errors

Every error answer of the API becomes an exception. Branch on code() (or errorCode, the same value as text), which is stable; the message says what happened and what to do, in English, and may change. echo $e and $e->summary() give one line with the code, status, message, details and request id.

Exception When
BadRequestException 400: malformed request, invalid cursor
InvalidHeaderException 400 INVALID_HEADER (extends BadRequestException): details['header'] says which
UnsupportedMediaTypeException 415 (extends BadRequestException): the body is not in the format the endpoint takes
AuthenticationException 401: key missing, unknown, revoked or expired
PermissionDeniedException 403: ability, scope, IP allow-list, suspended account
NotFoundException 404
ConflictException 409, for example REFERENCE_ID_EXISTS
PayloadTooLargeException 413
UnprocessableException 422: a rule refuses the request
ValidationException 422 VALIDATION_FAILED (extends UnprocessableException)
RateLimitException 429, after the retries
ServerException 5xx, after the retries

All of them extend ApiException, which extends MyCommException, the base of everything the SDK throws. InvalidArgumentException also extends MyCommException, but it is not an ApiException: no request was made.

Retries and idempotency

The SDK retries a call twice (configurable) when the network fails, when MyComm answers 429 or 503 (waiting as long as Retry-After asks) and on other 5xx answers, with exponential backoff.

That is safe for sends because every POST carries an Idempotency-Key, and a retry repeats the same key: MyComm then replays the first answer instead of sending a second message. Pass your own key to make a whole operation of yours repeatable, for example across a queue job's attempts:

Webhooks

Verify each delivery with the signing secret of your webhook endpoint, then handle the typed event. Always pass the raw request body.

Good to know:

Create the endpoint in the portal or with the API. The secret is shown once:

Partners

A partner key (mc_partner_...) provisions managed accounts and then acts as them on the normal API:

Or mint a key for the customer's own integration: $partner->partner->accountKeys->create($account->id, name: 'ERP').

Uploading files

Testing your code

MyCommFake gives you a real client that never touches the network. Every operation answers with the example of the API reference until you say otherwise.

FakeResponse also has page(), validationError(), noContent(), connectionError() and json(). To test your webhook receiver, MyComm\Testing\FakeWebhook::make('message.delivered', secret: $secret) gives you a signed payload and its MyComm-Signature header.

Configuration

When you pass your own HTTP client, set its timeout yourself: PSR-18 has no setting for it.

What every result carries

MyComm adds fields and values without a new API version. The SDK is built for that: a field it does not know yet is still in raw(), and an enum value it does not know arrives as a plain string instead of an enum case, so $channel->status === ChannelStatus::Active keeps working and nothing throws.

Versioning

The SDK follows semantic versioning. It is generated from the same OpenAPI documents that the API is tested against; CHANGELOG.md lists what each release added.

Contributing

Most of src/ is generated. See docs/development.md before changing anything.

License

MIT. See LICENSE.


All versions of mycomm-php with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-json Version *
php-http/discovery Version ^1.20
psr/http-client Version ^1.0
psr/http-client-implementation Version *
psr/http-factory Version ^1.0
psr/http-factory-implementation Version *
psr/http-message Version ^1.1 || ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mycomm/mycomm-php contains the following files

Loading the files please wait ...