Preview and apply
Preview resolves a package or a resource at the head of the branch and shows what would change, without writing. Apply writes exactly the commit you previewed, skips what did not change and can publish new versions.
Deploying from Git is two calls. Preview tells you which commit the installation’s branch is at and what each resource would become. Apply writes that commit, and only that commit. The same operations are behind Sync package and Sync from Git… in the portal.
The examples use two placeholders: $SOMMATIC_API is the API base URL (https://api.sommatic.ai) and
$SOMMATIC_TOKEN is a Bearer token for your organization (see Authentication).
<repository_id> is the id of the Git repository connection, for example pi-git-repo-xxxxxxxxxxxxxxx. Every
response uses the standard envelope { status, success, message, result }.
Choose what to sync
Preview and apply select the same way:
| Parameter | Selects |
|---|---|
path | Every resource of the package in that folder. |
key | One resource, by its logical key. |
resource_id | One resource, by its id in this installation. |
keys | Apply only: together with path, only these keys of the package. |
Read the package
curl -s "$SOMMATIC_API/platform-infrastructure/git-repository/<repository_id>/package?path=support" \
-H "Authorization: Bearer $SOMMATIC_TOKEN"The result lists the manifest, the head commit of the branch and, for each resource, its resource_id in this
installation (null when the key is not mapped in the environment file).
Preview the change
curl -s -X POST "$SOMMATIC_API/platform-infrastructure/git-sync/preview" \
-H "Authorization: Bearer $SOMMATIC_TOKEN" \
-H 'Content-Type: application/json' \
-d '{ "repository_id": "<repository_id>", "path": "support", "include_content": false }'Preview writes nothing. Read these fields of result:
commit,commit_message,commit_date: the head of the branch. This is the commit you will apply.items[], one per resource, withkey,path,resource_idand:exists: whether the resource exists in this installation.unresolved: tokens that could not be resolved. It must be empty.changes.has_changes, and for workflowschanges.nodes(added,removed,changed),changes.edges(added,removed),changes.fieldsandchanges.layout_changed.changes.detailsnames each node and the config settings that changed.unlinked_here: the resource is unlinked from Git in this installation and will be skipped.
include_content: false leaves out the resolved content of each resource. Keep it off unless you need it.
Apply the reviewed commit
curl -s -X POST "$SOMMATIC_API/platform-infrastructure/git-sync/apply" \
-H "Authorization: Bearer $SOMMATIC_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"repository_id": "<repository_id>",
"path": "support",
"expected_commit": "<commit from the preview>",
"publish": true,
"description": "Pull request #12"
}'The result has the commit, whether it published, the counts applied, unchanged, skipped and failed, and
items[] with each result, a reason when it failed or was skipped, and the published version.
Check the outcome
A response with success: true can still contain failed items. Check result.failed and every item’s result
before you report the deployment as done.
Safety rules
expected_commitis mandatory and must be the commit returned by the preview and still the head of the branch the connection reads. If the branch moved after your preview, apply fails: preview again and review the new commit. Apply never deploys an arbitrary commit, such as one of afeature/*branch that skipped the pull request, and it ignoresref.- Nothing half-resolved is written. A resource with unresolved tokens, or that does not exist in the
installation, is reported as
failedand left untouched. - Apply is idempotent. Resources without changes are
unchanged. Withpublish: true, an unchanged resource is published only if its deployed version does not come from this commit yet. Running the same apply twice is safe. - Rollbacks happen in Git. To undo a change, merge a revert pull request and apply the new head. You cannot apply an old commit.
Publish
With publish: true, apply creates a new version of each workflow and a new version snapshot of each knowledge
resource, and stores the commit, the key and your description with it. You can also publish later, one resource at a
time:
curl -s -X POST "$SOMMATIC_API/workflow-orchestration/control-plane/flow-design/flow-definition/<flow_definition_id>/publish" \
-H "Authorization: Bearer $SOMMATIC_TOKEN"
curl -s -X POST "$SOMMATIC_API/cognitive-infrastructure/cognitive-assets/knowledge-resource/<knowledge_resource_id>/publish" \
-H "Authorization: Bearer $SOMMATIC_TOKEN"After a sync, each resource keeps a git_binding with the repository, branch, environment, key and file, the
last_synced_commit and, once published, the deployed_commit and deployed_version.
Preview another branch
Preview accepts ref (a branch, tag or commit) to resolve a commit other than the head of the connection branch, for
example to check a pull request before merging it. Apply ignores ref: only the head of the connection branch can be
deployed.