# Connect Onshape

AI agent getting started? Read [Agents: start here](https://docs.openeng.io/agents/start-here.md) first.

Create and manage an Onshape connection from the CLI.

Source: https://docs.openeng.io/guides/connector/

An Onshape connection imports documents into its own connector-managed import project. Open the organisation's **Connections** page in the web app to see its connections.

> Everyone with access to this project sees every document this Onshape account can see.

The connector commands require an organisation selected for CLI commands. Creating a connection needs the owner role, including authority to administer projects and service identities. Other commands state their required capabilities in `openeng help connector <command>`.

## Create the mirror

Have the Onshape company ID and account keys ready. Create a connection by choosing the company to import:

```sh
openeng connector create --system onshape --stack cad --name "Onshape mirror" --company <company-id>
```

The command prints the connection ID, the mirror project ID and whether it drafted types. The mirror project holds the imported copy.

1. If the command drafted types, inspect them with `openeng types draft show --change-set <id> --project <mirror-project-id>`.
2. Accept the reviewed revision with `openeng types draft accept --change-set <id> --revision <revision>` before the first import.
3. If a shared draft of the organisation's proposed schema and view changes is already open, review it. If the types are already approved, no draft is needed.

## Import the first documents

1. Run `openeng connector set-credential <connection>` and enter the Onshape keys at its terminal prompt.
2. Run `openeng connector run <connection>` to start the import.
3. Run `openeng connector runs <connection>` to inspect the run result.
4. Open the returned mirror project and inspect the imported records and product structure.

Confirm the expected documents are present before sharing the mirror project. Imported types are connector-owned: make changes in Onshape and import again, rather than editing those records directly.

## Run later imports

Use `openeng connector run <connection>` again, then inspect the latest run. If an import fails, read its result before retrying. Check credentials and whether required type definitions were published. Revoke the connection when it should no longer be used.

## Commands

See [CLI reference](https://docs.openeng.io/reference/cli.md) for flags and output.

- `openeng connector create` creates the connection, mirror project and service identity.
- `openeng connector set-credential <connection>` stores the Onshape keys entered at a terminal prompt.
- `openeng connector draft-types <connection>` drafts types for review.
- `openeng connector revoke <connection>` revokes the connection.
- `openeng connector run <connection>` starts an import run.
- `openeng connector runs <connection>` lists import runs.

Run `openeng help connector` for exact flags and output shapes. Review and accept drafted types with `openeng types draft`.
