Search Images
Once all images and product data have been uploaded and indexed, an image search can be performed for testing purposes.
Perform a Search
Before you search for an image, you must first authenticate and obtain an access token.
Replace company-xyz
with your customer subdomain, and client_id
and client_secret
values.
Get Token - Sample Request
curl -L -X POST 'https://api-company-xyz.evolvestorefront.com/token' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Accept: application/json'
-d 'client_id=xxxxxxxxxxxxxxxxxxxxxxxxxx' \
-d 'client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxx'
Get Token - Sample Response
{
"access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
"expires_in": 3600,
"token_type": "Bearer"
}
Call the /image-search/search
POST API, replacing company-xyz
with your customer subdomain, and the Bearer token
and imageBase64
values. See Encoding an Image section below.
Search Image - Sample Request
curl -L 'https://api-company-xyz.evolvestorefront.com/image-search/search' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxx' \
-d '{
"imageBase64": "/9j/4Q0PRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMA...",
"size": 4
}'
Search Image - Sample Response
{
"hits": [
{
"score": 0.80532396,
"id": "14246",
"partNumber": "BR-ACCE-0001",
"name": "Makeup Mirror",
"images": [
{ "image_path": "bathroom/accessories/bathacc1_a1_600.jpg" },
{ "image_path": "bathroom/accessories/bathacc1_a2_600.jpg" },
{ "image_path": "bathroom/accessories/bathacc1_a3_600.jpg" }
]
},
{
"score": 0.7009622,
"id": "14001",
"partNumber": "LR-DECO-0001",
"name": "Accent Mirror",
"images": [
{ "image_path": "livingroom/decoration/mirror1_a1_600.jpg" },
{ "image_path": "livingroom/decoration/mirror1_a2_600.jpg" }
]
},
{
"score": 0.6987951,
"id": "14003",
"partNumber": "LR-DECO-0002",
"name": "Framed Mirror",
"images": [
{ "image_path": "livingroom/decoration/mirror2_a1_600.jpg" },
{ "image_path": "livingroom/decoration/mirror2_a2_600.jpg" }
]
},
{
"score": 0.67596465,
"id": "14252",
"partNumber": "BR-FIXT-0001",
"name": "Single Handle Bath Faucet",
"images": [
{ "image_path": "bathroom/fixtures/bathfix1_a1_600.jpg" },
{ "image_path": "bathroom/fixtures/bathfix1_a2_600.jpg" }
]
}
]
}
Encoding an Image
The imageBase64
value in an image search request is a base64-encoded representation of a JPEG or PNG file without a data:content/type;base64
prefix. To generate the base64 encoding of an image, you can do one of the following:
- On Linux-based systems and MacOS, use the built-in
base64
utility:
$ cat my_filename.jpg | base64
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcU
FhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgo
....
1+opJLNqwABqxxHVqE10mQ/ONp1i4SSWxKACLKJzEklUhuWqilgZJQSMB4JJKVUPMzRH5mXM0fYk
v7dfNBuLYHtjmaYpHaDUHvCSSRUzgCkkktI//9k=
- Use an online converter such as https://codebeautify.org/image-to-base64-converter or https://base64.guru/converter/encode/image