Skip to content

API reference

This page summarizes the public API. For implementation details, view the source repository. For the release history, read the changelog.

Member Returns Purpose
__construct(string $apiKey, string|array $baseUrlOrOptions, array $options = []) Client Configure credentials, base URL, and Guzzle options
getBaseUrl() string Return the normalized URL ending in /v1/
sendSms(SmsRequest|array $payload) SmsResponse Send immediately or schedule
getBalance() BalanceResponse Retrieve credits
getBalanceInCredits() BalanceResponse Alias for getBalance()
listSmsCreditSales(SmsCreditSalesQuery|array $query = []) SmsCreditSalesResponse List one page of credit orders
iterateSmsCreditSales(SmsCreditSalesQuery|array $query = []) Generator<SmsCreditSale> Iterate over every matching credit order
listMessages(MessagesQuery|array $query = []) MessagesResponse List one page of sent messages
iterateMessages(MessagesQuery|array $query = []) Generator<Message> Iterate over every matching sent message
checkStatus(?string $serverId, ?string $clientId) SmsDeliveryStatusItem[] Query using exactly one identifier
checkStatusByServerRequestId(string $id) SmsDeliveryStatusItem[] Query by server ID
checkStatusByClientRequestId(string $id) SmsDeliveryStatusItem[] Query by client ID
deleteSchedule(string $id) DeleteScheduleResponse Delete a schedule with no delivery history
deleteSmsRequestSchedule(string $id) DeleteScheduleResponse Alias for deleteSchedule()
disableSchedule(string $id) ScheduleStateChangeResponse Pause an active schedule
disableSmsRequestSchedule(string $id) ScheduleStateChangeResponse Alias for disableSchedule()
enableSchedule(string $id) ScheduleStateChangeResponse Resume a disabled schedule
enableSmsRequestSchedule(string $id) ScheduleStateChangeResponse Alias for enableSchedule()

Constants: Client::DEFAULT_TIMEOUT is 10.0; Client::API_VERSION_PREFIX is v1.

Constructor:

new SmsRequest(
string $fromLabel,
string $smsBody,
string|array|null $toMobileNumber = null,
string|array|null $toGroup = null,
?string $clientRequestId = null,
?bool $callbackWhenProcessedFlag = null,
?bool $simulateSendFlag = null,
?bool $concatFlag = null,
SmsSchedule|array|null $schedule = null
);

Factory and serialization: fromArray(), validate(), toArray(), jsonSerialize().

Getters correspond to every constructor field. SmsRequest::MAXIMUM_SMS_LENGTH is 1000.

Use the factories to build valid API schedule definitions:

SmsSchedule::oneOff(DateTimeInterface|string $startsAt);
SmsSchedule::recurring(
string $expression,
string $timezone,
DateTimeInterface|string $startsAt,
DateTimeInterface|string|null $endsAt = null
);

SmsSchedule::fromArray() accepts the equivalent one_off or recurring API shape. The model provides toArray(), jsonSerialize(), and getters for type, startsAt, expression, timezone, and endsAt.

Both query models validate their parameters when they are built and throw RayoException for invalid values. Both provide fromArray(), withCursor(?string $cursor) (returns a copy for the next page), toArray() (leaves out unset parameters), jsonSerialize(), and a getter for every parameter. SORT_ASC and SORT_DESC hold asc and desc.

new SmsCreditSalesQuery(
?string $sort = null,
DateTimeInterface|string|null $dateFrom = null,
DateTimeInterface|string|null $dateTo = null,
?string $cursor = null
);

See Listing credit orders for the parameters.

new MessagesQuery(
?string $sort = null,
?int $limit = null,
DateTimeInterface|string|null $dateFrom = null,
DateTimeInterface|string|null $dateTo = null,
string|array|null $status = null,
?string $mobileNumber = null,
?string $clientRequestId = null,
string|array|null $smsServerRequestId = null,
?string $smsRequestScheduleId = null,
?bool $returnMessageContent = null,
?string $cursor = null
);

Call the constructor with named arguments. Constants: MIN_LIMIT is 1, MAX_LIMIT is 100, and MAX_SMS_SERVER_REQUEST_IDS is 100. See Listing sent messages for the parameters.

All response models are immutable, JSON-serializable, and provide read-only ArrayAccess to their raw response.

  • State: isSuccess(), isScheduled().
  • Getters: getUsername(), getResultCode(), getResultDescription(), getClientRequestId(), getSmsServerRequestId(), getSmsRequestScheduleId(), getError().
  • State: isSuccess().
  • Getters: getUsername(), getResultCode(), getResultDescription(), getSmsRequestScheduleId(), getError().
  • State: isSuccess(), isActive(), isDisabled(), isExpired().
  • Getters: getUsername(), getResultCode(), getResultDescription(), getSmsRequestScheduleId(), getSmsRequestScheduleState().
  • Constants: STATE_ACTIVE, STATE_DISABLED, STATE_EXPIRED.
  • Getters: getRequestId(), getCredits().

SmsCreditSalesResponse and MessagesResponse

Section titled “SmsCreditSalesResponse and MessagesResponse”
  • Getters: getRequestId(), getTimeZone(), getLimit(), getSort(), getNextCursor().
  • State: hasMore().
  • Items: SmsCreditSalesResponse::getSmsCreditSales() returns SmsCreditSale[]; MessagesResponse::getMessages() returns Message[].
  • Getters: getId(), getAmount(), getVatPercentage(), getVatAmount(), getAmountPaid(), getCurrency(), getNumberOfCredits(), getPaymentMethod(), getSoldAtUtc(), getSoldAtInUserTimeZone(), getCreatedAtUtc(), getCreatedAtInUserTimeZone(), getSourceSmsCreditSaleId().
  • State: isAcknowledged().
  • Constants: PAYMENT_METHOD_CREDIT_OR_DEBIT_CARD, PAYMENT_METHOD_BANK_DEPOSIT, PAYMENT_METHOD_UNKNOWN.
  • State: isDelivered(), isFinalStatus(), isMasked(), hasMessageContent().
  • Getters: getId(), getSmsServerRequestId(), getSmsRequestScheduleId(), getClientRequestId(), getSenderId(), getMobileNumber(), getMessage(), getStatus(), getErrorDescription(), getCredits(), getCreatedAtUtc(), getCreatedAtInUserTimeZone(), getLastStatusUpdatedAtUtc(), getLastStatusUpdatedAtInUserTimeZone().

getMessage() and isMasked() are filled only when the query sets returnMessageContent to true.

  • State: isDelivered(), isFinalStatus().
  • Getters: getSmsServerRequestId(), getClientRequestId(), getInternalSmsOutDeliveryId(), getMobileNumber(), getStatus().
  • Factories: fromArray(), fromJson(), fromQueryString().
  • State: isDelivered(), isFinalStatus().
  • Getters: getSmsServerRequestId(), getClientRequestId(), getInternalSmsOutDeliveryId(), getSenderId(), getMobileNumber(), getStatus(), getErrorDescription(), getRequestTimestamp(), getLastStatusUpdatedTimestamp().

The timestamp parser accepts the documented requestTimestamp and the server variant requestedTimestamp.

In both SmsDeliveryStatusItem and CallbackPayload, getSmsServerRequestId() and getInternalSmsOutDeliveryId() return UUID strings. getInternalSmsOutDeliveryId() is the same value as Message::getId().

Constants: NEW, TEMP_LOCKED, PROCESSING_ERROR, FAILURE, SENT, ERROR, DELIVERED, NOT_DELIVERED, and UNKNOWN_DELIVERY.

Use DeliveryStatus::all() to list every value and DeliveryStatus::isFinal($status) to test terminal status.

Method Purpose
computeSignature(...) Compute the expected HMAC-SHA256 digest
verify(...) Return whether a raw request signature is valid
verifyOrThrow(...) Throw RayoException for an invalid signature
verifyPsr7Request(...) Verify a PSR-7 server request

Extends RuntimeException. In addition to inherited exception methods, it exposes getStatusCode(), getErrorPayload(), getRawResponseBody(), getErrorMessage(), getResultCode(), and getResultDescription().