Metafield

Metafields are custom variables for various resources. They are available in the template and can be used to alter standard behavior or display extended information.

Example Object

{
    "metafield": {
        "id": 5571481,
        "createdAt": "2019-08-20T16:41:30+00:00",
        "updatedAt": "2019-08-20T16:47:03+00:00",
        "key": "external_email",
        "value": "[email protected]",
        "ownerType": "customer",
        "ownerId": 2145124,
        "ownerResource": {
            "resource": {
                "id": 2145124,
                "url": "customers/2145124",
                "link": "https://api.shoplightspeed.com/us/customers/2145124.json"
            }
        }
    }
}

Properties

id The unique numeric identifier for the metafield. {“id”: {id}}
createdAt The date and time when the metafield was created. (format: ISO-8601){“createdAt”: “2019-08-20T16:41:30+00:00”}
updatedAt The date and time when the metafield was last updated. (format: ISO-8601){“updatedAt”: “2019-08-20T16:47:03+00:00”}
ownerType Owner type {“ownerType”: “shop|api|customer|order|invoice|shipment|category|product|variant|textpage|blog|article|tag”}
ownerId ID of the owner object. {“ownerId”: “{id}”}
key Property key. Will be automatically slugified. {“key”: “key”}
value Property value. (format: string, size: 255){“value”: “value”}
ownerResource Link to owner type resource. {“ownerResource”: {“resource”: { “id”: 2145124,
“url”: “customers/2145124”,
“link”: “https://api.shoplightspeed.com/us/customers/2145124.json”
}
}}

GET Retieve metafields

Returns all the metafield objects in a list.

Definition

GET /metafields.json

Example Request

curl https://api.shoplightspeed.com/en/metafields.json \
  -u {key}:{secret}
<?php $api->metafields->get();

Example Response

{
    "metafields": [
        {
            "id": 5571481,
            "createdAt": "2019-08-20T16:41:30+00:00",
            "updatedAt": "2019-08-20T16:47:03+00:00",
            "key": "external_email2",
            "value": "[email protected]",
            "ownerType": "customer",
            "ownerId": 2145124,
            "ownerResource": {
                "resource": {
                    "id": 2145124,
                    "url": "customers/2145124",
                    "link": "https://api.shoplightspeed.com/us/customers/2145124.json"
                }
            }
        },
        {
            "id": 5496385,
            "createdAt": "2019-08-07T19:13:46+00:00",
            "updatedAt": "2019-08-07T19:13:46+00:00",
            "key": "external_email",
            "value": "[email protected]",
            "ownerType": "variant",
            "ownerId": 34771901,
            "ownerResource": {
                "resource": {
                    "id": 34771901,
                    "url": "variants/34771901",
                    "link": "https://api.shoplightspeed.com/us/variants/34771901.json"
                }
            }
        }
      ]
  }

ARGUMENTS

  No arguments available.

Filters

limit Number of results. {(default: 50) (maximum: 250)}
page Page to show. {(default: 1)}
since_id Restrict results to after the specified ID. {(default: 0)}
created_at_min Show metafields created after date. {(format: YYYY-MM-DD HH:MM:SS)}
created_at_max Show metafields created before date. {(format: YYYY-MM-DD HH:MM:SS)}
updated_at_min Show metafields last updated after date. {(format: YYYY-MM-DD HH:MM:SS)}
updated_at_max Show metafields last updated before date. {(format: YYYY-MM-DD HH:MM:SS)}
fields Comma-separated list of fields to include in the response. {(format: id,createdAt)}

GET Number of metafields

Returns the total number of metafield objects.

Definition

GET /metafields/count.json

Example Request

curl https://api.shoplightspeed.com/en/metafields/count.json \
  -u {key}:{secret}
<?php $api->metafields->count();

Example Response

{
  "count": 10
}

ARGUMENTS

  No arguments available.

Filters

limit Number of results. {(default: 50) (maximum: 250)}
page Page to show. {(default: 1)}
since_id Restrict results to after the specified ID. {(default: 0)}
created_at_min Show metafields created after date. {(format: YYYY-MM-DD HH:MM:SS)}
created_at_max Show metafields created before date. {(format: YYYY-MM-DD HH:MM:SS)}
updated_at_min Show metafields last updated after date. {(format: YYYY-MM-DD HH:MM:SS)}
updated_at_max Show metafields last updated before date. {(format: YYYY-MM-DD HH:MM:SS)}
fields Comma-separated list of fields to include in the response. {(format: id,createdAt)}

GET Retrieve a metafield

Returns a single metafield.

Definition

GET /metafields/{metafield_id}.json

Example Request

curl https://api.shoplightspeed.com/en/metafields/{metafield_id}.json \
  -u {key}:{secret}
<?php $api->metafields->get($metafield_id);

Example Response

{
    "metafield": {
        "id": 5571481,
        "createdAt": "2019-08-20T16:41:30+00:00",
        "updatedAt": "2019-08-20T16:47:03+00:00",
        "key": "external_email2",
        "value": "[email protected]",
        "ownerType": "customer",
        "ownerId": 2145124,
        "ownerResource": {
            "resource": {
                "id": 2145124,
                "url": "customers/2145124",
                "link": "https://api.shoplightspeed.com/us/customers/2145124.json"
            }
        }
    }
}

Arguments

id The unique numeric identifier for the metafield. {“id”: {id}}

POST Create a metafield

Create a new metafield.

Definition

POST /metafields.json

Example Request

curl -X POST https://api.shoplightspeed.com/en/metafields.json \
  -u {key}:{secret} \
  -d metafield[ownerType]="customer" \
  -d metafield[ownerId]=2145124 \
  -d metafield[key]="canonical_url_1" \
  -d metafield[value]="http://mycustomurl"
<?php $api->metafields->create([
  "ownerType"     => "customer",
  "ownerId"       => 2145124,
  "key"           => "canonical_url_1",
  "value"         => "http://mycustomurl"
]);

Example Json payload

{
  "metafield": {
    "ownerType": "customer",
    "ownerId": 2145124,
    "key": "canonical_url_1",
    "value": "http://mycustomurl"
  }
}

Example Response

{
    "metafield": {
        "id": 5701917,
        "createdAt": "2019-09-06T19:24:49+00:00",
        "updatedAt": "2019-09-06T19:24:49+00:00",
        "key": "canonical_url_1",
        "value": "http://mycustomurl",
        "ownerType": "customer",
        "ownerId": 2145124,
        "ownerResource": {
            "resource": {
                "id": 2145124,
                "url": "customers/2145124",
                "link": "https://api.shoplightspeed.com/us/customers/2145124.json"
            }
        }
    }
}

Arguments

ownerType Owner type {“ownerType”: “shop|api|customer|order|invoice|shipment|category|product|variant|textpage|blog|article|tag”}
ownerId ID of the owner object. {“ownerId”: “{id}”}
key Property key. Will be automatically slugified. {“key”: “key”}
value Property value. (format: string, size: 255){“value”: “value”}

PUT Update a metafield

Update an existing metafield.

Definition

PUT /metafields/{metafield_id}.json

Example Request

curl -X POST https://api.shoplightspeed.com/en/metafields.json \
  -u {key}:{secret} \
  -d metafield[ownerType]="customer" \
  -d metafield[ownerId]=2145124 \
  -d metafield[key]="canonical_url_1" \
  -d metafield[value]="http://mycustomurl"
<?php $api->metafields->create([
  "ownerType"     => "customer",
  "ownerId"       => 2145124,
  "key"           => "canonical_url_1",
  "value"         => "http://mycustomurl"
]);

Example Json payload

{
  "metafield": {
    "ownerType": "customer",
    "ownerId": 2145124,
    "key": "canonical_url_1",
    "value": "http://mycustomurl"
  }
}

Example Response

{
    "metafield": {
        "id": 5701917,
        "createdAt": "2019-09-06T19:24:49+00:00",
        "updatedAt": "2019-09-06T19:24:49+00:00",
        "key": "canonical_url_1",
        "value": "http://mycustomurl",
        "ownerType": "customer",
        "ownerId": 2145124,
        "ownerResource": {
            "resource": {
                "id": 2145124,
                "url": "customers/2145124",
                "link": "https://api.shoplightspeed.com/us/customers/2145124.json"
            }
        }
    }
}

Arguments

ownerType Owner type {“ownerType”: “shop|api|customer|order|invoice|shipment|category|product|variant|textpage|blog|article|tag”}
ownerId ID of the owner object. {“ownerId”: “{id}”}
key Property key. Will be automatically slugified. {“key”: “key”}
value Property value. (format: string, size: 255){“value”: “value”}

DELETE Delete a metafield

Delete an existing metafield.

Definition

DELETE /metafields/{metafield_id}.json

Example Request

<<<<<<< HEAD
curl -X DELETE https://api.shoplightspeed.com/en/metafields.json \
  -u {key}:{secret}
=======
curl -X DELETE https://api.shoplightspeed.com/en/metafields/{metafield_id}.json \
  -u key:secret
>>>>>>> 0bb9cc9c386ee0aa941af55a43124185831ec16a
<?php $api->metafields->delete($metafield_id);

Example Response

HTTP/1.1 204 No Content

Arguments

id The unique numeric identifier for the metafield. {“id”: {id}}