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 with idealpostcodes.WithManagementKey(...) when you create the client, which sends it in the Authorization header. See setup.
Signature
func (c *Client) CreateConfig(ctx context.Context, key string, body CreateConfigBody) (*ConfigResponse, error)
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
ctx | context.Context | yes | Cancels the request and sets its deadline. |
key | string | yes | API Key |
body | CreateConfigBody | yes | The JSON request body. Fields under Request Body. |
Query Parameters
None.
Request Body
Set these as fields of body, named in Studly case (post_town is PostTown). An optional field is a pointer, set with new(value), or a map; nil sends nothing.
| Name | Type | Required | Description |
|---|---|---|---|
name | string | yes | A unique name to identify the configuration payload |
payload | string | yes | A serialised payload of up to 65536 characters |
Response
*idealpostcodes.ConfigResponse. Fields the API may leave out or send as null are pointers. RawJSON() returns the body as received. See responses.
Errors
An HTTP error returns *idealpostcodes.APIError with the HTTP status, the API error code and the body; match it with errors.AsType. A transport failure returns the net/http error, wrapped. See error handling.
Example
package main
import (
"context"
"fmt"
"log"
idealpostcodes "go.ideal-postcodes.co.uk/sdk"
)
func main() {
client := idealpostcodes.NewClient("ak_test", idealpostcodes.WithManagementKey("uk_test"))
res, err := client.CreateConfig(context.Background(), "ak_test", idealpostcodes.CreateConfigBody{
Name: "woocommerce",
Payload: `{"removeOrganisation":false}`,
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s created %s\n", res.Result.Name, res.Result.CreatedAt)
}