Mechanic is a development and ecommerce automation platform for Shopify. :)
This task integrates Report Toaster and ShipStation. On order fulfillment, Mechanic calls the ShipStation API to retrieve the shipping cost, and this cost is sent to Report Toaster.
Runs Occurs whenever an order is fulfilled, Occurs when a Mechanic action is performed, and Occurs when a user manually triggers the task with text. Configuration includes api username and api password.
This task integrates Report Toaster and ShipStation. On order fulfillment, Mechanic calls the ShipStation API to retrieve the shipping cost, and this cost is sent to Report Toaster.
Note - the task currently makes a few assumptions:
See your ShipStation settings to retrieve the API Key and Password to use in the task options.
This task can be run manually as a test by entering an order name.
See the Mechanic documentation for Report Toaster for more information on updating costs.
Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Shopifolks, everybody.
That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.
(By the way, have you seen our documentation? Have you joined the Slack community?)
shopify/orders/fulfilled mechanic/actions/perform mechanic/user/text
{% comment %} Preferred option order: {{ options.api_username__required }} {{ options.api_password__required }} {% endcomment %} {% if event.topic == "shopify/orders/fulfilled" or event.topic == "mechanic/user/text" or event.preview %} {% assign authorization_header = options.api_username__required | append: ":" | append: options.api_password__required | base64 | prepend: "Basic " %} {% if event.preview %} {% assign order_number = 12345 %} {% elsif event.topic == "shopify/orders/fulfilled" %} {% assign order_number = order.name %} {% elsif event.topic == "mechanic/user/text" %} {% assign order_number = event.data %} {% endif %} {% if order_number != blank %} {% assign order_number = order_number | remove: "#" %} {% action "http" %} { "method": "get", "url": {{ "https://ssapi.shipstation.com/shipments?orderNumber=" | append: order_number | json }}, "headers": { "Authorization": {{ authorization_header | json }} }, "meta": { "order_number": {{ order_number | json }} } } {% endaction %} {% endif %} {% endif %} {% if event.preview or event.topic == "mechanic/actions/perform" and action.type == "http" %} {% if event.preview %} {% capture shipments_json %} [ { "shipmentId": 28195403, "orderId": 65695876, "orderKey": "4244227981505", "userId": "a3cf6157-11e9-46a1-b0fc-2222322", "customerEmail": "email@yahoo.com", "orderNumber": "5969", "createDate": "2022-01-13T04:26:37.1670000", "shipDate": "2022-01-13", "shipmentCost": 21.02, "insuranceCost": 0, "trackingNumber": "123455", "isReturnLabel": false, "batchNumber": "100527", "carrierCode": "dhl_express_uk", "serviceCode": "dhl_uk_express_worldwide", "packageCode": null, "confirmation": null, "warehouseId": 26351, "voided": false, "voidDate": null, "marketplaceNotified": true, "notifyErrorMessage": null, "shipTo": { "name": "Somebody", "company": null, "street1": "", "street2": "", "street3": null, "city": "VANCOUVER", "state": "WA", "postalCode": "90210", "country": "US", "phone": "", "residential": null, "addressVerified": null }, "weight": { "value": 340, "units": "grams", "WeightUnits": 2 }, "dimensions": { "units": "inches", "length": 20, "width": 10, "height": 5 }, "insuranceOptions": { "provider": null, "insureShipment": false, "insuredValue": 0 }, "advancedOptions": { "billToParty": null, "billToAccount": null, "billToPostalCode": null, "billToCountryCode": null, "storeId": 45678 }, "shipmentItems": null, "labelData": null, "formData": null } ] {% endcapture %} {% assign shipments = shipments_json | parse_json %} {% else %} {% assign shipments = action.run.result.body.shipments %} {% endif %} {% if shipments != blank %} {% for shipment in shipments %} {% assign order_id = shipment.orderKey %} {% assign shipping_cost = shipping_cost | plus: shipment.shipmentCost | plus: shipment.insuranceCost %} {% endfor %} {% action "report_toaster" %} { "operation": "update", "Order": [ { "id": {{ order_id | json }}, "shipping_cost": {{ shipping_cost | json }} } ] } {% endaction %} {% endif %} {% endif %}