Skip to main content

$client->createConfig()

Create

Creates a named configuration on a key and returns it.

Endpoint​

POST /keys/{key}/configs

See the API reference for this endpoint.

This operation needs a Management Key. Pass it as the second argument to IdealPostcodes::client(), which sends it in the Authorization header. See setup.

Signature​

public function createConfig(string $key, array $body): ConfigResponse

Arguments​

NameTypeRequiredDescription
$keystringyesAPI Key
$bodyarrayyesThe JSON request body. Keys under Request Body.

Query Parameters​

None.

Request Body​

Pass these as keys of $body.

NameTypeRequiredDescription
namestringyesA unique name to identify the configuration payload
payloadstringyesA serialised payload of up to 65536 characters

Response​

IdealPostcodes\Responses\ConfigResponse. Read fields as properties, such as $response->result, or as an array with the API's field names. toArray() returns the decoded body.

Errors​

An HTTP error throws ApiException with the HTTP status, the API error code from getCode() and the decoded body. A transport failure throws TransporterException. See error handling.

Example​

create-config.phpphp
<?php

declare(strict_types=1);

use IdealPostcodes\IdealPostcodes;

require 'vendor/autoload.php';

$client = IdealPostcodes::client('ak_test', 'uk_test');

$response = $client->createConfig('ak_test', [
'name' => 'woocommerce',
'payload' => json_encode(['removeOrganisation' => false], JSON_THROW_ON_ERROR),
]);

echo $response->result->name, ' created ', $response->result->createdAt, PHP_EOL;