# Re-syncing a previous payload

## Introduction

If a process flow fails to complete successfully, you'll see the run displayed in your logs with a `failure` status - if appropriate, you can [use the retry option to run it again](https://doc.wearepatchworks.com/product-documentation/process-flows/error-reporting-and-exception-handling/run-logs-and-queue/working-with-run-logs/handling-failed-process-flow-runs/retrying-a-failed-process-flow-run).&#x20;

However, there may be occasions when some time has passed since a flow failed, therefore a `retry` would not necessarily pick up the same data as the original run. Or, you want to re-sync a specific item in a payload.

This guide walks through the steps required to retrieve the original payload from a failed run and pass this into the process flow to run again.

{% hint style="info" %}
Most endpoints have a variable or parameter used to target a specific entity (for example, `order_id`, `customer_id`, `product_id`, etc.). When building a process flow, we recommend building an alternative 'flavour' that allows users to specify a unique identifier to target at runtime - this is the most efficient way to sync/re-sync specific items. For more information please see our [Targeted syncs - best practice page](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/best-practice-for-building-process-flows/targeted-syncs-best-practice).

However, if you don't have a process flow in place for targeted syncs, the steps detailed here can be followed.&#x20;
{% endhint %}

## The steps

This task is documented in four stages:

1. [Find the payload to be synced](#stage-1-find-the-payload)\
   We need to find the payload from the failed process flow that needs to be passed in again, manually.
2. [Skip shapes](#stage-2-skip-shapes)\
   Since we're passing in the required data manually, we must prevent (temporarily) all shapes up to and including the point the payload was taken from running again.&#x20;
3. [Initialise the flow manually with the payload](#stage-3-initialise-the-flow-manually-with-payload)\
   Run the flow manually, passing in the payload found in stage 1.
4. [Reinstate skipped shapes](#stage-4-reinstate-skipped-shapes)\
   Remove the 'skip' option from shapes so the process flow runs normally next time.

{% hint style="danger" %}
This task requires us to (temporarily) prevent some shapes in your process flow from running. As such, please ensure that you complete this task at a time when the process flow is not scheduled to run automatically.
{% endhint %}

### Stage 1: Find the payload

First, we locate and copy the initial payload so it can be passed in again, manually.

{% hint style="info" %}
The 'initial' payload is the payload you want to pass into the flow to be synced. In the simplest case, this is a payload generated from a first connector step that receives data, but there may be times when you need to take a payload from further down the flow - for example, you might want to process a single-item payload generated from a [flow control](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/flow-control-shape) shape.
{% endhint %}

Any payloads associated with a process flow run can be accessed retrospectively, via your [run logs](https://doc.wearepatchworks.com/product-documentation/process-flows/error-reporting-and-exception-handling/run-logs-and-queue). To do this, follow the steps below.

**Step 1**\
Select `run logs` from the left-hand navigation menu:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FeivSQmPPxBRIBOzfWzVL%2Fmanual%20sync%201.png?alt=media&#x26;token=ea5fef39-4029-4b49-8ca8-ea9234199b41" alt="" width="237"><figcaption></figcaption></figure></div>

**Step 2**\
At the top of the run logs table, click the `filter` icon associated with the `status` column:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FMmDrI3htpI4xQj268c4k%2Fmanual%20sync%202.png?alt=media&#x26;token=54868965-bb51-4f43-9d72-9d9269a0207c" alt="" width="375"><figcaption></figcaption></figure></div>

...and select the failure option (so only failed runs are displayed):

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FOoPJcd12wyQXhK87cH5y%2Fmanual%20sync%203.png?alt=media&#x26;token=7089055a-c59e-473e-ba04-2798745f972b" alt="" width="375"><figcaption></figcaption></figure></div>

{% hint style="warning" %}
Here we assume that you are re-syncing data because a run has failed. If this isn't the case, you can filter by any status to find the required run - however, beware of duplicating data if you re-use data from a run set to anything other than a `failure` status.
{% endhint %}

**Step 3**\
Click the ellipses associated with the run that you want to access, then select the `view logs` option:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FOM3lVXJAlN5mGxpBtoMF%2Fmanual%20sync%204.png?alt=media&#x26;token=fd37792b-cdaa-42a8-b617-c7a64aad38bd" alt=""><figcaption></figcaption></figure></div>

**Step 4**\
Logs are displayed with each step in the flow listed in the lower panel - for example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F1d3zVwZ3kG61ylf3zRBw%2Fmanual%20sync%205.png?alt=media&#x26;token=15b3ba25-47ca-4b5a-8e22-d71059c2c65b" alt=""><figcaption></figcaption></figure></div>

Our example shows that our flow failed at the `assert` step, with only a connector step before. So in this case, we need to obtain the entire payload from the previous connector step.

{% hint style="info" %}
You can retrieve the payload from whichever step in your process flow is most appropriate. In our example, we want to re-sync ALL original data from the connector shape but if - for example - you are looking for a specific record and your process flow includes [flow control](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/flow-control-shape), this is most likely to be the place to find it.&#x20;
{% endhint %}

**Step 5**\
Click the 'eye' icon associated with the shape that you want to view.&#x20;

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FuOVSWnFGh4nhFzf7eCAv%2Fmanual%20sync%206.png?alt=media&#x26;token=d2b4ecae-1d4b-4cdf-8246-a84a453764fe" alt=""><figcaption></figcaption></figure></div>

...and look for payloads in the lower panel:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FCWRFEv1n2tXsui3jI1EM%2Fmanual%20sync%207.png?alt=media&#x26;token=14a69378-6a00-4314-a7d5-7a003bbef322" alt=""><figcaption></figcaption></figure>

These are payloads that were available at the end of the step - you might have a single payload or (for example, if your data is paginated or has been through flow control) you might have multiple payloads as per this example.

**Step 6**\
Click the 'eye' icon associated with the first payload:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FpIZVwCa9yyzJw6XWGbNz%2Fmanual%20sync%208.png?alt=media&#x26;token=f43fd563-058a-4206-9a89-5c832c7c30d5" alt=""><figcaption></figcaption></figure>

...and the payload is displayed:

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FA0lGt86xIF25zZ5ePlYm%2Fmanual%20sync%209.png?alt=media&#x26;token=52e26ab9-58ea-4b5f-a932-f5ba0931ac04" alt=""><figcaption></figcaption></figure>

**Step 7**\
Check the payload to ensure that it contains the right data, then scroll to the end and look to see if the displayed data is truncated - if it ends with a `[trimmed]` marker, the full payload can't be displayed: &#x20;

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FCdbyt5Mburgh1NnKBQKm%2Fmanual%20sync%2010a.png?alt=media&#x26;token=f5b3b3fa-b0a6-44d3-9a35-780028883820" alt=""><figcaption></figcaption></figure>

**Step 8**\
What you do next depends on whether the displayed payload ends with a `[trimmed]` marker:

<details>

<summary><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FPq80F8deQ3i4P3iazHRj%2Ficon%20decision.svg?alt=media&#x26;token=61be5bf3-7235-45fe-af5f-726229df8dd6" alt="" data-size="line"> Payload is NOT trimmed</summary>

Click anywhere in the payload panel, then press CTRL+A followed by CTRL+C to copy the data to your clipboard:

<img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FfjYtFm7nvgNBiW80zcxj%2Fmanual%20sync%2010b1.png?alt=media&#x26;token=9755242a-d538-4d4a-a503-ad9732396aff" alt="" data-size="original">

</details>

<details>

<summary><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FPq80F8deQ3i4P3iazHRj%2Ficon%20decision.svg?alt=media&#x26;token=61be5bf3-7235-45fe-af5f-726229df8dd6" alt="" data-size="line"> Payload is trimmed</summary>

Click the download button to download the full payload in a text file - then open this file and press CTRL+A followed by CTRL+C to copy the data to your clipboard:

<img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Foi2bSFpwgaBI97qMvCkk%2Fmanual%20sync%2010c.png?alt=media&#x26;token=3cbf0054-2c0b-4bf9-959a-89df715c6a40" alt="" data-size="original">

</details>

### Stage 2: Skip shapes

Having obtained the required data, we must ensure that all shapes up to including the step associated with your payload are NOT processed the next time the process flow runs.&#x20;

To do this, access `settings` for each shape and toggle the `skip` option `on`:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FW1vtU2DgLWmCCzyChvXg%2Fskip%20shape%20option%200.png?alt=media&#x26;token=78037878-7d80-4f8d-901a-09fd3cc92c97" alt="" width="375"><figcaption></figcaption></figure></div>

{% hint style="warning" %}
With the exception of the [trigger shape](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/trigger-shape) (which can't and doesn't need to be skipped), you must skip ALL shapes up to and including the shape where you copied the required payload.
{% endhint %}

{% hint style="info" %}
For more information about the `skip shape` option please see our [Skipping shapes](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/skipping-shapes) page.
{% endhint %}

### Stage 3: Initialise the flow manually with payload

Now we're ready to run the process flow manually, passing in the payload copied in [stage 1](#stage-1-find-the-payload).&#x20;

**Step 1**\
Select `initialise flow with data` from the actions bar:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FmgpmTY6o1oNUFsP1nnH0%2Fmanual%20sync%20stage%202%201.png?alt=media&#x26;token=e197ae69-2298-4f70-aadb-46fa1142b260" alt="" width="297"><figcaption></figcaption></figure></div>

...a payload window is displayed: &#x20;

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F9qtn9ITB1xAivnI8KICs%2Fmanual%20sync%20stage%202%202.png?alt=media&#x26;token=e43e2e8c-a5be-4dae-952f-151693b11bbb" alt=""><figcaption></figcaption></figure></div>

**Step 2**\
Paste in the payload that you copied in [stage 1](#stage-1-find-the-payload), then click the `initialise flow` button:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FWm5eRHQZyX3mT4LyIrTk%2Fmanual%20sync%20stage%202%203.png?alt=media&#x26;token=95f7330a-8017-472a-be29-aaeb3f76f1c4" alt=""><figcaption></figcaption></figure></div>

**Step 3**\
Ensure that the process flow runs without errors, and check that data has synced as expected.

### Stage 4: Reinstate skipped shapes

Having ensured that data has synced successfully, we can reset skipped shapes so the process flow runs normally next time.&#x20;

To do this, access `settings` for each shape that you skipped in [stage 2](#stage-2-skip-shapes) and toggle the `skip` option back to `off`:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F9FlElO4xWdER33PUZwMb%2Fskip%20shape%20option%202.png?alt=media&#x26;token=725e3420-92bd-4368-a91d-d9fee6dbc3e1" alt="" width="375"><figcaption></figcaption></figure></div>
