Skip to content

Instantly share code, notes, and snippets.

@clavery
Created December 1, 2023 14:02
Show Gist options
  • Select an option

  • Save clavery/2a7370293db35309b3e186f47c3bd76f to your computer and use it in GitHub Desktop.

Select an option

Save clavery/2a7370293db35309b3e186f47c3bd76f to your computer and use it in GitHub Desktop.
SFCC Dynamic data replication via job
#!/usr/bin/env bash
# execute a data replication job with dynamic replication configuration
# See job config below
set -e
API_CLIENT_ID="client_id"
API_CLIENT_SECRET=""
OCAPI_BASE="https://staging-internal-ccdemo.demandware.net/s/-/dw/data/v23_2"
RESPONSE=$(curl "https://account.demandware.com/dwsso/oauth2/access_token" \
-su "$API_CLIENT_ID:$API_CLIENT_SECRET" \
-d "grant_type=client_credentials")
echo $RESPONSE | jq
TOKEN=$(echo $RESPONSE | jq -r '.access_token')
# replicate the nto-electronics catalog without clearing cache
# replication configuration is JSON so it's stringified into the parameter value here
RESPONSE=$(curl -s "$OCAPI_BASE/jobs/DoDataReplication/executions" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"parameters": [{
"name":"ReplicationConfig",
"value": "{\"data_replication_configuration\":{\"target\":\"production\",\"type\":\"transfer_and_publish\",\"description\":\"Replicate NTO Electronics catalog to production\",\"cache_invalidation\":\"keep_all\",\"tasks\":{\"global\":{\"catalogs\":{\"nto-electronics\":true}}}}}"
}]
}'
)
execution_id=$(echo $RESPONSE | jq -r .id)
echo "Running replication with execution id: $execution_id"
while true; do
response=$(curl -sX GET "$OCAPI_BASE/jobs/DoDataReplication/executions/$execution_id" -H "Authorization: Bearer ${TOKEN}")
status=$(echo $response | jq -r '.status')
if [ "$status" != "RUNNING" ]; then
break
fi
echo -n "."
sleep 1
done
echo ""
exit
### JOB CONFIG
# <job job-id="DoDataReplication" priority="0">
# <description/>
# <parameters>
# <parameter name="ReplicationConfig">{}</parameter>
# </parameters>
# <flow>
# <context site-id="Sites"/>
# <step step-id="data-replicate" type="ExecuteDataReplication" enforce-restart="false">
# <description/>
# <parameters>
# <parameter name="ReplicationConfiguration" job-parameter-ref="ReplicationConfig"/>
# </parameters>
# </step>
# </flow>
# <rules>
# <on-running runtime-threshold="60m" enabled="false">
# <mark-job-as-hanging/>
# </on-running>
# </rules>
# <triggers>
# <run-once enabled="false">
# <date>2023-08-10Z</date>
# <time>18:38:00.000Z</time>
# </run-once>
# </triggers>
# </job>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment