Skip to content

Import through context.data.import.raw() creates new workspace instead of importing on the current workspace #7457

@victoraugustofd

Description

@victoraugustofd

Expected Behavior

Following the documentation, data context import function can receive an argument of type ImportOptions, which has an id corresponding to the workspace that the import should be executed at.

Actual Behavior

Even if I pass a valid workspaceId on the ImportOptions argument, the import occurs, but it creates a new workspace instead of importing the contents on the actual workspace.

Reproduction Steps

  1. Create a plugin with minimal code in index.js eg:
module.exports.workspaceActions = [
    {
        label: 'Pull from GIT',
        icon: 'fa-arrow-down',
        action: async (context, data) => {
            const impFilename = 'example.json';
            if (!fs.existsSync(impFilename)) {
                context.app.alert('Error importing',
                    'Seems example.json is not existing!');
                return false;
            }

            fs.readFile(impFilename, "utf8", function (err, fileContent) {
                context.data.import.raw(fileContent, {
                    workspaceId: data.workspace._id,
                });
            });
        },
    }
];
  1. Use example.json eg. with the following content:
{
  "_type": "export",
  "__export_format": 4,
  "__export_date": "2023-07-09T17:27:43.046Z",
  "__export_source": "insomnia.desktop.app:v2023.4.0",
  "resources": [
    {
      "_id": "req_44dcc4a6c60b42b4b91cf8888a2d9b1b",
      "parentId": "__WORKSPACE_ID__",
      "modified": "1637671845661",
      "created": 1688992190875,
      "url": "https://google.de",
      "name": "New Request",
      "description": "",
      "method": "GET",
      "body": {},
      "parameters": [],
      "headers": [],
      "authentication": {},
      "metaSortKey": -1688992190875,
      "isPrivate": false,
      "settingStoreCookies": true,
      "settingSendCookies": true,
      "settingDisableRenderRequestBody": false,
      "settingEncodeUrl": true,
      "settingRebuildPath": true,
      "settingFollowRedirects": "global",
      "_type": "request"
    },
    {
      "_id": "__WORKSPACE_ID__",
      "parentId": null,
      "modified": "1637671845661",
      "created": 1688992188630,
      "name": "My Collection",
      "description": "",
      "scope": "collection",
      "_type": "workspace"
    },
    {
      "_id": "__BASE_ENVIRONMENT_ID__",
      "parentId": "__WORKSPACE_ID__",
      "modified": "1637671845661",
      "created": 1688992188636,
      "name": "Base Environment",
      "data": {
        "url": "https://google.de"
      },
      "dataPropertyOrder": {
        "&": [
          "url"
        ]
      },
      "color": null,
      "isPrivate": false,
      "metaSortKey": 1688992188636,
      "_type": "environment"
    }
  ]
}
  1. Try to import it. The ImportOptions were removed so it is not possible anymore to send a workspaceId. This basically switches the import of workspaces to import of projects and breaks many plugins: add support for multiple workspaces in one import file #6044

Credits to @sebastiande for the code snippets for reproduction steps.

Is there an existing issue for this?

Additional Information

I don't think this should be the expected behaviour, or the documentation should be updated as it leads developers to assume that this behaviour is what was going to happen.
On my case, I am developing an internal plugin for the company that I work, and this is a blocker that I could not imagine when I was studying what the Insomnia plugins are capable of.
This was already discussed at #6125, however I don't think that the main issue was understood, since "sync" features started being discussed on the thread, even though the discussion was about importing contents of an exported collection/design document on the current workspace.
Also, I searched on the source code of Insomnia and did not find any occurrence of the string "ImportOptions" on the code, which make me think this is a deprecated feature and the documentation is outdated.
Is it correct to assume any of this or is this a known issue that is already under fix from Insomnia team collaborators?

Thanks in advance.

Insomnia Version

2023.5.5

What operating system are you using?

Windows

Operating System Version

Microsoft Windows 11 Pro

Installation method

download from insomnia

Last Known Working Insomnia version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-bugBug: general classificationS-unverifiedStatus: Unverified by maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions