Wix
This recipe puts each frame you approve in Shootika on the matching Wix Stores product. It follows the pattern every recipe shares; this page covers the Wix side.
Wix Stores has two catalog versions, V1 and V3, with different APIs that are not compatible with each other. Wix says every site will move to V3 in time, and a site on V3 does not go back to V1. Step 3 tells you which one your site uses.
Before you begin
Section titled “Before you begin”You need:
- a Shootika API key (see Authentication);
- a Wix API key from your Wix account, with permission to manage your site’s Stores products and its Media Manager;
- your Wix site id.
A Wix API key is sent in the Authorization header, together with a wix-site-id header that names
the site.
export WIX_API_KEY="your Wix API key"export WIX_SITE_ID="your Wix site id"1. Link the product
Section titled “1. Link the product”When you create the product in Shootika, put the Wix product id in external_id:
curl https://api.shootika.com/v1/products \ -H "Authorization: Bearer $SHOOTIKA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "title": "Ribbed crew sweater", "garment_category": "tops", "external_id": "9e8924aa-c3f2-4fe6-bc98-ace47295c52d", "image_urls": ["https://example.com/photos/sweater-flat.jpg"] }'Then shoot, and review the frames in Shootika, as in the pattern.
2. Find the approved frames
Section titled “2. Find the approved frames”Read every page of the approved frames, starting with PAGE=1:
curl "https://api.shootika.com/v1/frames?approved=true&page=$PAGE&page_size=100" \ -H "Authorization: Bearer $SHOOTIKA_API_KEY"Add one to PAGE and ask again until page times page_size reaches total. The list is newest
first, so a frame shot weeks ago and approved today can be on a later page; reading only the first
page misses it. Compare every frame id against your record of published frames. To check one
product, add &product_id= with its Shootika id instead.
For each frame you have not published yet, keep its image.url and read its product’s
external_id:
curl https://api.shootika.com/v1/products/$PRODUCT_ID \ -H "Authorization: Bearer $SHOOTIKA_API_KEY"WIX_PRODUCT_ID="the product's external_id"FRAME_URL="the frame's image.url"3. Check your catalog version
Section titled “3. Check your catalog version”curl https://www.wixapis.com/stores/v3/provision/version \ -H "Authorization: $WIX_API_KEY" \ -H "wix-site-id: $WIX_SITE_ID"catalogVersion is V1_CATALOG, V3_CATALOG or STORES_NOT_INSTALLED. On
STORES_NOT_INSTALLED, stop: Wix Stores is not installed on the site. Wix recommends checking the
version at the start of each flow.
4. Import the frame into your Media Manager
Section titled “4. Import the frame into your Media Manager”Wix accepts an outside image address on a product, but its docs do not say that it keeps its own copy of an image added that way. Importing the frame into your site’s Media Manager first gives your store its own copy.
curl https://www.wixapis.com/site-media/v1/files/import \ -H "Authorization: $WIX_API_KEY" \ -H "wix-site-id: $WIX_SITE_ID" \ -H "Content-Type: application/json" \ -d "{\"url\": \"$FRAME_URL\", \"mediaType\": \"IMAGE\", \"displayName\": \"Ribbed crew sweater, on model\"}"Keep file.id from the answer:
WIX_FILE_ID="the file.id"The file is not ready at once: its operationStatus starts as PENDING. Ask for it until it is
READY, and stop if it is FAILED:
curl "https://www.wixapis.com/site-media/v1/files/get-file-by-id?fileId=$WIX_FILE_ID" \ -H "Authorization: $WIX_API_KEY" \ -H "wix-site-id: $WIX_SITE_ID"A ready file has its address on Wix in file.url. On Catalog V1 you need it:
WIX_FILE_URL="the file.url"5. Add the frame to the product
Section titled “5. Add the frame to the product”On Catalog V3
Section titled “On Catalog V3”Every V3 product update carries the product’s current revision, and the media list you send
replaces the product’s media. So first read the product with its media:
curl "https://www.wixapis.com/stores/v3/products/$WIX_PRODUCT_ID?fields=MEDIA_ITEMS_INFO" \ -H "Authorization: $WIX_API_KEY" \ -H "wix-site-id: $WIX_SITE_ID"Keep product.revision, and the id of each entry in product.media.itemsInfo.items, in order,
with its altText when it has one:
WIX_REVISION="the product.revision"Then send the entries back with the imported file added:
curl -X PATCH "https://www.wixapis.com/stores/v3/products/$WIX_PRODUCT_ID" \ -H "Authorization: $WIX_API_KEY" \ -H "wix-site-id: $WIX_SITE_ID" \ -H "Content-Type: application/json" \ -d "{ \"product\": { \"id\": \"$WIX_PRODUCT_ID\", \"revision\": \"$WIX_REVISION\", \"media\": { \"itemsInfo\": { \"items\": [ {\"id\": \"an existing item id\", \"altText\": \"its alt text\"}, {\"id\": \"$WIX_FILE_ID\", \"altText\": \"Ribbed crew sweater, worn by a model\"} ] } } } }"- Send
altTextonly for an item that has one; Wix does not accept an emptyaltText. - The first item is the product’s main image. To make the frame the main image, put it first.
- An item you leave out is removed from the product.
- If the answer says the revision does not match, the product changed since you read it. Read it again and resend.
On Catalog V1
Section titled “On Catalog V1”V1 adds media to a product without replacing what it has. Add the imported file by its Wix address,
file.url from step 4:
curl https://www.wixapis.com/stores/v1/products/$WIX_PRODUCT_ID/media \ -H "Authorization: $WIX_API_KEY" \ -H "wix-site-id: $WIX_SITE_ID" \ -H "Content-Type: application/json" \ -d "{\"media\": [{\"url\": \"$WIX_FILE_URL\"}]}"When the product is updated, record the frame id as published.
Taking a frame down
Section titled “Taking a frame down”If someone takes the frame’s approval down in Shootika, your Wix product keeps the image. Remove it in Wix.
On V3, send the product’s media without it, as in step 5.
On V1, Add Product Media answers with an empty object, so first read the product to find the
image’s media id. It is the id of the matching entry in product.media.items:
curl https://www.wixapis.com/stores-reader/v1/products/$WIX_PRODUCT_ID \ -H "Authorization: $WIX_API_KEY" \ -H "wix-site-id: $WIX_SITE_ID"Then remove it with Remove Product Media:
curl https://www.wixapis.com/stores/v1/products/$WIX_PRODUCT_ID/media/delete \ -H "Authorization: $WIX_API_KEY" \ -H "wix-site-id: $WIX_SITE_ID" \ -H "Content-Type: application/json" \ -d '{"mediaIds": ["the media id"]}'