WooCommerce
This recipe puts each frame you approve in Shootika on the matching WooCommerce product. It follows the pattern every recipe shares; this page covers the WooCommerce side.
Before you begin
Section titled “Before you begin”You need:
- a Shootika API key (see Authentication);
- a WooCommerce REST API key with Read/Write access. Create it in WordPress under WooCommerce, Settings, Advanced, REST API;
- your store served over HTTPS, since the key is sent with HTTP Basic Auth.
The commands below read your WooCommerce keys and address from variables:
export WC_STORE="https://yourstore.example"export WC_KEY="ck_..."export WC_SECRET="cs_..."1. Link the product
Section titled “1. Link the product”When you create the product in Shootika, put the WooCommerce product id in external_id. For
WooCommerce product 1042:
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": "1042", "image_urls": ["https://yourstore.example/wp-content/uploads/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"WC_PRODUCT_ID="the product's external_id"FRAME_URL="the frame's image.url"3. Read the product’s current images
Section titled “3. Read the product’s current images”The image list you send in the next step replaces the product’s images, so first read the ones it has:
curl "$WC_STORE/wp-json/wc/v3/products/$WC_PRODUCT_ID" \ -u "$WC_KEY:$WC_SECRET"Keep the id of each entry in images, in order.
4. Add the frame to the product
Section titled “4. Add the frame to the product”Send the existing images by id, then the frame by src:
curl -X PUT "$WC_STORE/wp-json/wc/v3/products/$WC_PRODUCT_ID" \ -u "$WC_KEY:$WC_SECRET" \ -H "Content-Type: application/json" \ -d "{ \"images\": [ {\"id\": 501}, {\"id\": 502}, {\"src\": \"$FRAME_URL\", \"alt\": \"Ribbed crew sweater, worn by a model\"} ] }"Replace 501 and 502 with the ids you kept in step 3.
- WooCommerce downloads the image at
srcinto your WordPress Media Library and adds it to the product, so your store keeps its own copy. - The first image in the list is the product’s main image; the rest are its gallery. To make the frame the main image, put it first.
- An image you leave out of the list is removed from the product. It stays in the Media Library.
- If WooCommerce cannot download the image, the answer is
400with the codewoocommerce_product_image_upload_error.
When the answer is 200, 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 WooCommerce product keeps the image.
Remove it with the same PUT, sending the product’s images without it.