Download the PHP package pdeans/miva-api without Composer

On this page you can find all versions of the php package pdeans/miva-api. 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 miva-api

Miva JSON API PHP Library

Latest Stable Version Build Status Total Downloads

PHP library for interacting with the Miva JSON API.

Table Of Contents

Installation

Requirements:

Install via Composer.

Configuring the API Client

Utilizing the library to interact with the API is accomplished via the Client class. The Client class accepts an array containing API and HTTP client (Guzzle) configuration options in key/value format.

Client Configuration Options

Key Required Type Description
url Yes string The API endpoint URL.
store_code Yes string The Miva store code.
access_token Yes string The API access token.
private_key Yes string The API signature key. Hint: If omitting signature validation, pass in an '' empty string literal value.
hmac No string HMAC signature type. Defaults to sha256. Valid types are sha256, sha1, or '' (blank string literal to disable HMAC; header becomes MIVA <token>).
timestamp No boolean Enable/disable API request timestamp validation. Defaults to true (Enabled).
timeout No int Override default 60s Miva request timeout. Sends X-Miva-API-Timeout header.
binary_encoding No string json (default) or base64. Sends X-Miva-API-Binary-Encoding header when not json.
range No string Range header value for multi-call retries (e.g., Operations=4-5).
ssh_auth No array SSH authentication (takes precedence over token authentication when present): ['username' => string, 'private_key' => string, 'algorithm' => 'sha256'\|'sha512']. private_key may be a file path (preferred) or raw PEM contents. Supported private key formats: PKCS#1 PEM or PKCS#8 PEM (convert OpenSSH keys before use).
http_headers No array HTTP request headers to merge. The library automatically sets the following default headers for every request: Content-Type, Accept, User-Agent, and the appropriate auth header. These headers should not be included in this list.
http_client No array Associative array of Guzzle request options, or an instance of GuzzleHttp\ClientInterface.

Example:

Authentication

The Miva API authorization header is generated based on the configuration:

JSON Request Format

The required Miva_Request_Timestamp and Store_Code properties are automatically generated based on the configuration settings passed into the Client object and added to the JSON body for every API request. The Function property is also automatically added to the JSON body for every request. The JSON data generated for the Function property will vary based on the provided request function list.

Function Builder

The func method is used to generate API request functions. The method accepts the request function name as its only argument.

The add method is used to "publish" the function and append it to the request function list.

Note: All function builder methods are chainable.

Function Request Parameters

This section showcases how to construct and add function parameters.

Common Filter List Parameters

Each common filter list parameter for the xxxList_Load_Query functions has a corresponding helper method to seamlessly set the parameter value. The example below shows each of the methods in action.

Function Request Filters

Most of the function search/display filters have an associated helper method that acts as a shorthand, or factory for creating the respective filter. The filter method must be used for any filter that does not have a linked helper method, as shown in the example above. This method can also be used to create each filter covered below. The method accepts two arguments, with the first argument always being the filter name. The second argument takes the filter value, which will vary per filter type.

The available search/display helper methods are covered below.

Search

The search method may be used to attach a search filter to a function's filter list. The most basic call to search requires three arguments. The first argument is the search field column. The second argument is the search operator, which can be any of the supported API search operators. Finally, the third argument is the value to evaluate against the search column.

Below is an example to issue a search filter for a specific product code:

For convenience, if you want to verify that a column is equal ('EQ') to a given value, you may pass the value directly as the second argument to the search method. The following will achieve the same result as the first example above:

Of course, you may use a variety of other supported operators when writing a search filter:

The search method can be issued multiple times to perform an AND search:

Performing OR searches and parenthetical comparisons can be achieved by passing in an array to the search method as the first and only argument. The array should be modeled to match the desired search value output, with value nesting as needed:

On Demand Columns

Using the ondemandcolumns method, you can specify the explicit columns to return. The method takes one argument, the list of on demand columns to select:

For convenience, the odc method can be utilized as an alias to the ondemandcolumns method:

Show

The "show" filters can be created using the show method. This method takes one argument, the show filter value, which will vary per xxxList_Load_Query function. Note that this filter is currently available for the following functions only:

Example:

Function Request Input Parameters

Passphrase

The passphrase method is used to set the Passphrase parameter. The method takes a single argument, the decryption passphrase.

Additional Input Parameters

The params method is used to set all other input parameters. Some example use cases for this method are the request body parameters for the Xx_Create / Xx_Insert / Xx_Update / Xx_Delete functions, Module level functions, and essentially all other functions that require specific input parameters to perform actions. The function accepts a key/value array which maps to the input parameter key/values as its only argument.

Examples:

API Requests

This section covers configuring and issuing API requests.

HTTP Headers

You may specify which HTTP headers are attached to all API requests with the addHeader and addHeaders methods. By default the library sets:

Sending Requests

The send method will issue an API request, and return the results in the library's Response object. If you wish to bypass this object and return the raw JSON response from the API, pass a true value as the first argument for the send method.

Example requests:

You may preview the current request body at any time before sending the request by using the getRequestBody method. This is helpful for debugging requests.

API Responses

By default, API responses will return a pdeans\Miva\Api\Response class instance. The Response object includes a number of helper methods for interacting with the API responses.

Checking For Request Errors

Use hasErrors() to check for any errors across functions/iterations/operations. The errors() method returns an ErrorBag with helpers such as all(), messages(), and forField('Field_Name'). successful() indicates if any result succeeded; failed() is the inverse. Mixed success/failure responses (e.g., operations with some errors) will still report successful() true but hasErrors() true.

Response Body

The raw JSON response body can be retrieved anytime using the getBody method:

To receive an iterable form of the API response, issue the getResponse method. This will return an array of objects, with the array keys mapping to the function names supplied to the API request function list. The items are sorted in identical order to the API request function list. Each item or "function", contains its own array of the results of the function request. These array items correlate to each of the function's iterations that were sent in the request. The items are sorted in the same order that they were issued in the request. Use the getFunctions method to retrieve the list of available functions.

The getFunction method may be used to explicitly return the response results for a specific function name. This can also be accomplished with the getResponse method by passing the function name as the first argument.

The getData method returns the response data property for a specific function name. By default, the data property is returned for the first iteration index for the function name provided. However, an optional second argument can be provided to return the data property for a specific iteration index on the given function name.

Examples:

Helpers

This section covers library helper methods.

Troubleshooting API Requests And Responses

To aid in troubleshooting API requests and responses, PSR-7 Request and PSR-7 Response objects can be obtained using the getPreviousRequest and getPreviousResponse methods respectively after an API request has been issued:

Furthermore, the getUrl, getHeaders, and getFunctionList methods may be used to inspect and troubleshoot requests before they are sent off to the API:

Further Reading

Having a general understanding of the Miva JSON API configuration and schema is highly recommended before using the library.

Testing

Install dev dependencies:

Copy the example environment file and provide valid credentials for a test store:

Populate the following variables in .env (values are not committed):

Optional for SSH auth testing:

Run the test suite:

Static analysis and style checks:


All versions of miva-api with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-json Version *
guzzlehttp/guzzle Version ^7.10
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 pdeans/miva-api contains the following files

Loading the files please wait ...