Contents
On this page
Import Map File - Plugixa Image Map
POST /plugixa-image-map/v1/import
Make a new map from a file made by Export Map, on this site or another.
Any signed-in user with both plugixa_image_map_import and plugixa_image_map_create. See Roles and permissions.
Note. The new map is always a draft, whatever status the file carries. The picture is not downloaded: the site looks in its own Media Library for an image with the same file name (and the same size when the file gives one). Upload the picture first, then import.
Request
POST https://your-site.example/wp-json/plugixa-image-map/v1/import
Request body
Content type: application/json
| Field | Type | Required | Description |
|---|---|---|---|
file |
object |
Yes | The export file’s contents: the data of Export Map. format must be plugixa-image-map and format_version a whole number from 1 to 1. |
The whole request may be 3 MB at most. The title comes from the file (Imported map when it has none) and the document is cleaned as in Create Map. Any attachment id in the file is ignored.
{
"file": {
"format": "plugixa-image-map",
"format_version": 1,
"map": {
"title": "Ground floor",
"status": "published",
"doc": {
"image": {
"attachment_id": 0
},
"objects": [
{
"id": "o_3f9a1c2e",
"type": "spot",
"name": "Reception",
"geometry": {
"x": 42.5,
"y": 61.25
}
}
]
}
},
"image": {
"filename": "ground-floor.png",
"width": 1600,
"height": 1000,
"alt": "Ground floor plan"
}
}
}
Responses
201 Created. data describes the new map.
{
"success": true,
"data": {
"id": 21,
"title": "Ground floor",
"image": "found",
"warnings": []
},
"meta": {
"warnings": []
}
}
| Field | Type | Meaning |
|---|---|---|
data.id |
integer |
The new map’s id |
data.title |
string |
Its title |
data.image |
string |
found (the picture was matched in the Media Library), missing (the file names one, but no match was found: the map has no picture yet) or none (the file has no picture) |
data.warnings |
array |
What the cleaning changed, also in meta.warnings |
Errors
| Status | Code | When |
|---|---|---|
413 |
plugixa_image_map_import_too_large |
The request is over 3 MB. |
422 |
plugixa_image_map_import_format |
file is not a Plugixa Image Map export, or has no map in it. |
422 |
plugixa_image_map_import_newer |
The file was made by a newer version of the plugin. |
413 |
plugixa_image_map_too_large |
doc is over 2 MB as JSON. |
422 |
plugixa_image_map_too_deep |
doc nests more than 12 levels. |
422 |
plugixa_image_map_newer_document |
doc.schema is newer than this version of the plugin reads. |
422 |
plugixa_image_map_too_many_objects |
More than 2,000 hotspots. |
422 |
plugixa_image_map_too_many_points |
A polygon with more than 1,000 points. |
422 |
plugixa_image_map_too_many_groups |
More than 500 groups. |
422 |
plugixa_image_map_too_long |
A value is longer than its column holds (the title: 255 characters). data.field and data.max say which and how long. |
Plus the errors every endpoint can return.
Examples
curl -s -X POST "https://your-site.example/wp-json/plugixa-image-map/v1/import" \
-u "admin:$WP_APP_PASSWORD" \
-H "Content-Type: application/json" \
-d '{"file":{"format":"plugixa-image-map","format_version":1,"map":{"title":"Ground floor","status":"published","doc":{"image":{"attachment_id":0},"objects":[{"id":"o_3f9a1c2e","type":"spot","name":"Reception","geometry":{"x":42.5,"y":61.25}}]}},"image":{"filename":"ground-floor.png","width":1600,"height":1000,"alt":"Ground floor plan"}}}'
<?php
$ch = curl_init('https://your-site.example/wp-json/plugixa-image-map/v1/import');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERPWD => 'admin:' . getenv('WP_APP_PASSWORD'),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
'file' => [
'format' => 'plugixa-image-map',
'format_version' => 1,
'map' => [
'title' => 'Ground floor',
'status' => 'published',
'doc' => [
'image' => [
'attachment_id' => 0,
],
'objects' => [
[
'id' => 'o_3f9a1c2e',
'type' => 'spot',
'name' => 'Reception',
'geometry' => [
'x' => 42.5,
'y' => 61.25,
],
],
],
],
],
'image' => [
'filename' => 'ground-floor.png',
'width' => 1600,
'height' => 1000,
'alt' => 'Ground floor plan',
],
],
]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
const response = await fetch('https://your-site.example/wp-json/plugixa-image-map/v1/import', {
method: 'POST',
headers: {
'Authorization': 'Basic ' + btoa(`admin:${process.env.WP_APP_PASSWORD}`),
'Content-Type': 'application/json',
},
body: JSON.stringify({
file: {
format: 'plugixa-image-map',
format_version: 1,
map: {
title: 'Ground floor',
status: 'published',
doc: {
image: {
attachment_id: 0,
},
objects: [
{
id: 'o_3f9a1c2e',
type: 'spot',
name: 'Reception',
geometry: {
x: 42.5,
y: 61.25,
},
},
],
},
},
image: {
filename: 'ground-floor.png',
width: 1600,
height: 1000,
alt: 'Ground floor plan',
},
},
}),
});
const { data } = await response.json();
Quick Links
Share