rmddx / shipstation-note-parser

unmerges notes
0 stars 1 forks source link

ShipStation Note Parser

When orders are synced from Shopify to Shipstation,
order notes and order attributes are merged into a single field.

This unmerges them.

Uses Shipstation webhook to process orders as they are imported.
Parses order note and saves to "Note from Buyer".
Copies orignal note to "Custom Field 1".

Before:

Note From Buyer: Special Note 4 U<br\> internal-track-data: 123abc

After:

Note From Buyer: Special Note 4 U
Custom Field 1: Special Note 4 U<br\> internal-track-data: 123abc

Tech

Prereqs

Setup

  1. Clone repo
  2. Generate ShipStation API key
  3. Create new Google Secret to store ShipStation API key (secret format: key:secret)
    
    gcloud secrets create shipstation-key \
    --replication-policy="automatic"

echo -n "KEY:SECRET" | \ gcloud secrets versions add secret-id --data-file=-

4. Rename `config.template.ini` -> `config.ini`
5. Update `config.ini` with project_id, secret_name, version
6. Update `config.ini` with ShipStation base URL
7. Deploy cloud function (replace PROJECT, REGION)
```shell
gcloud functions deploy shipstation-note-parser \
--gen2 \
--project PROJECT \
--region REGION \
--runtime php82 \
--trigger-http \
--entry-point run 
  1. Get Cloud Function URL (either cloudfunctions.net or run.app)
  2. Create ShipStation webhook (On New Orders) with Cloud Function URL.

Tests

composer test

Dev

Run Functions Framework
https://cloud.google.com/functions/docs/running/function-frameworks

composer start

Call function
(Use a service like https://webhook.site to capture webhook POST data to test with)

curl -X POST \
-H "Content-Type: application/json" \
-d '{"resource_url":"URL","resource_type":"ORDER_NOTIFY"}' \
http://localhost:8080