# Editing & Publishing (/docs/products/ussd-flows/editing-and-publishing)

You write a flow as JSON in the editor. It checks your work as you type and saves a draft for you. Callers only see the flow after you publish.

## Opening the Editor

On the flow's page, click **Open Editor**. The editor opens over the page. Click **✕** to close it.

The top bar has:

- A **Draft** / **Published** switch. Draft is where you edit. Published shows the live version, read-only.
- The **Publish** button and the flow's **Code**.
- On the right, the save status, the **Save** button (disk icon) and **✕**.

Below it, a toolbar has **Undo**, **Redo**, **Copy all** (copies the whole flow) and **Simulator**, which shows or hides the Simulator.

## Writing a Flow

The editor checks your JSON against the flow rules as you type: required fields, allowed values and field names. Even a typo such as `lable` for `label` is underlined in red. Hover over a red line to see what's wrong. The full rules are in the [Flow Definition](/docs/products/ussd-flows/developers/flow-definition).

Variables such as `$(page.ask_name.value)` are shown in bold. Type `$(` inside a string and the editor suggests `page`, `session` and `data`. After `page.` it lists the page ids in your flow. See [Variables](/docs/products/ussd-flows/developers/variables).

![Editor showing variable highlighting and autocomplete dropdown](/assets/images/dashboard-guide/ussd-flows/editor-variable-autocomplete.png)

*Caption: Variable highlighting (teal) and autocomplete suggestions in the editor*

## Saving

The editor saves your draft 5 seconds after you stop typing. It doesn't save while the JSON has errors. To save now, click the disk icon or press Ctrl+S (Cmd+S on Mac).

The status next to the Save button tells you where you are:

| Status                | Meaning                                           |
| --------------------- | ------------------------------------------------- |
| Invalid JSON (red)    | Fix the red lines. Nothing is saved until you do. |
| Unsaved (grey)        | Your latest edits aren't saved yet.               |
| Saving... (blue)      | Saving now.                                       |
| Changes saved (green) | Your draft is saved.                              |

If you close the editor within 5 seconds of an edit, that edit may be lost. Save before you close.

## Testing in the Simulator

The Simulator opens beside the editor and runs your saved draft like a real USSD session. Press **Start**, type your answers, and press **Run Again** to start over. You can pick Orange or Africell as the network.

Save your changes before you start, because the Simulator runs the saved draft, not what's on screen.

## Publishing

Click **Publish** in the editor, then confirm. On the flow's page you can also click **Publish Draft**, which shows whenever there is a saved draft.

When you publish:

- Your saved draft replaces the live version. New sessions get it straight away.
- The draft is cleared. The next time you open the editor, it starts from the live version.
- If the flow was disabled, it is live again.

Publish sends the last saved draft, so wait for "Changes saved" first.

![Editor header with publish button enabled](/assets/images/dashboard-guide/ussd-flows/editor-publish.png)

*Caption: The publish button (rocket icon) enabled and ready to publish*

If **Publish** is greyed out, hover over it to see why:

| Message                                                                                    | What to do                                                                                                     |
| ------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------- |
| No draft to publish                                                                        | Nothing has changed since you last published. Edit the flow and wait for "Changes saved".                      |
| Saving changes...                                                                          | Wait a moment.                                                                                                 |
| This flow uses dynamic exchange and requires an RSA public key before it can be published. | The flow calls your server. Add a public key, as shown in [Flow Security](/docs/products/ussd-flows/security). |

## Going Back to an Earlier Version

There is no undo for a publish. Before a big change, switch to **Published** and click **Copy all** to keep a copy of the live flow. To go back, paste it into the draft and publish.
