hoppscotch icon indicating copy to clipboard operation
hoppscotch copied to clipboard

[bug]: "Error while importing: format not recognized" when importing a single environment

Open crossbone-magister opened this issue 2 years ago • 34 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current behavior

When exporting a single environment and then reimporting, the following error shows up: image

When exporting all the environments, no errors show up. This works whether all is one or multiple environments.

If you use both export methods in an hoppscotch installation that only has one registered environment, the only difference in the two export files is that the first one contains a JSON object, while the second one contains an array of JSON objects.

Steps to reproduce

  1. Go to the Environments sidebar
  2. Select an environment to export
  3. Click on the kebab menu icon on the right of the environment and select 'Export as JSON'
  4. Click on the Environment Import/Export button
  5. Select 'Import from Hoppscotch'
  6. Select the downloaded file of the environment just exported
  7. Error appears

Environment

Release

Version

Local

crossbone-magister avatar Nov 15 '23 18:11 crossbone-magister

@JoelJacobStephen can you take a look into this?

liyasthomas avatar Nov 16 '23 04:11 liyasthomas

Hi @crossbone-magister Ensure the JSON file has square brackets at the beginning and end. When exporting, a JSON file is downloaded without square brackets at the beginning and end, so when you try to import the same file, an error occurs.

DanielAttali avatar Dec 03 '23 10:12 DanielAttali

Hi @DanielAttali, thanks for your reply. I also pointed out the missing square brackets in my original description, though not explicitly:

the only difference in the two export files is that the first one contains a JSON object, while the second one contains an array of JSON objects.

What you are suggesting is what I eventually did to move forward with the import, but it feels like a workaround to me. I believe it would be best for the import and export files to have a consistent format instead of having the user to play around with them to make the import work. What do you think about it?

In any case this is just my personal opinion, it's ultimately up to the hoppscotch team to decide if they consider it an issue and what is the best approach to solve it.

crossbone-magister avatar Dec 03 '23 13:12 crossbone-magister

Feels like this is still an issue. I can re-import exported env.json (with 1 environment collection) but if I have another file with the simplest content as below - constantly getting "File format not recognized.". Adding this new environment into the previously exported env.json with existed environment produce same error

[
  {
    "name": "app",
    "variables": [
      {
        "key": "host",
        "value": "http://localhost:8000"
      }
    ]
  }
]

Hoppscotch Desktop App v2023.12.1-1

nnmer avatar Dec 27 '23 16:12 nnmer

@jamesgeorge007 @amk-dev can you look into this?

liyasthomas avatar Dec 27 '23 17:12 liyasthomas

Hi @nnmer, I couldn't reproduce the issue with the above environment JSON file.

Adding this new environment into the previously exported env.json with existed environment produce same error.

Can you provide a sample environment JSON file that will help reproduce the issue? Also, can you check if it's reproducible on hoppscotch.io?

jamesgeorge007 avatar Dec 28 '23 03:12 jamesgeorge007

@jamesgeorge007 , I've played a bit more, maybe restart of OS and App helped, it does work now. But, I've found that the values in json should not contain numbers as a number, but strings instead. If all values to be converted to strings and updated format to native Hoppscotch - I've managed to import my Postman env. collection.

nnmer avatar Dec 29 '23 14:12 nnmer

Thanks for your patience and valuable feedback. This feature has been implemented in the latest release.

Closing this ticket as this feature is now available in the recent version. Feel free to reach out if you encounter any further concerns.

liyasthomas avatar Jan 02 '24 13:01 liyasthomas

Still getting the same error. from client version and from website.

aakrem avatar Jan 18 '24 08:01 aakrem

@aakrem, can you share the steps to reproduce? Possibly a sample environment JSON file.

jamesgeorge007 avatar Jan 18 '24 08:01 jamesgeorge007

@jamesgeorge007 sure, it's a JSON format and I am trying to import it from this URL: https://cloud.agenta.ai/api/openapi.json

aakrem avatar Jan 18 '24 08:01 aakrem

@jamesgeorge007 any idea if we can solve this soon?

aakrem avatar Jan 18 '24 17:01 aakrem

Hi, we'll investigate this and get back.

jamesgeorge007 avatar Jan 18 '24 18:01 jamesgeorge007

@aakrem, a CORS error occurs while attempting to fetch from the above URL. We're tracking this internally. In the meantime, you can use an extension that adds the Access-Control-Allow-Origin: * rule to the response header. For instance, Allow CORS: Access-Control-Allow-Origin.

jamesgeorge007 avatar Jan 22 '24 09:01 jamesgeorge007

Is there any update on this? This is not just related to CORS. I tried to import a OpenAPI 3.01 JSON file which was saved to disc. Even then this error came. The JSON file was generated automatically by Spring Boot and works with OpenAPI viewer.

pritammobisoft avatar Apr 01 '24 11:04 pritammobisoft

Hi @pritammobisoft, can you help with the steps you took and a sample file to reproduce? Please follow the steps here while importing an OpenAPI collection.

jamesgeorge007 avatar Apr 02 '24 06:04 jamesgeorge007

Hi @jamesgeorge007 Importing https://cloud.agenta.ai/api/openapi.json from URL is not working in Desktop App (windows v2024.3.0).

image

lin-mt avatar Apr 22 '24 07:04 lin-mt

Same for me, exports from Postman fail to import The [] trick failed also

(Note managed to get a environment in, but never a collection)

matthiscock avatar May 20 '24 11:05 matthiscock

Same issue for me while try to import file http://localhost:8000/openapi.json directly exported from FastAPI swagger.

ChenE2000 avatar May 30 '24 06:05 ChenE2000

Same for me, when I try to import from Spring Boot OpenApi Spec !

jalotra avatar May 30 '24 14:05 jalotra

Same for me, when I try to import from Flask OpenApi Spec.

whhomi avatar Jun 12 '24 09:06 whhomi

@jamesgeorge007 @liyasthomas can we reopen this issue ? it looks like it's not solved

aakrem avatar Jun 12 '24 10:06 aakrem

We are trying to switch from Insomnia. But For this issue, we got stuck. We identified an interesting thing. The exported json file from insomnia gets imported instantly in the personal workspace.

It doesn't work with the newly created workspace.

I saw the same problem is faced by others. But the issue seems to be closed without any solution. Here is the link to the issue: https://github.com/hoppscotch/hoppscotch/issues/3975

ahsanaasim avatar Jul 04 '24 05:07 ahsanaasim

I have checked the network response of the API that is being called. Seems like there is one internal crash. Hope the response below helps to solve the issue

{
    "errors": [
        {
            "message": "PrismaClientKnownRequestError: \nInvalid `tx.teamCollection.create()` invocation in\n/usr/src/app/src/team-collection/team-collection.service.ts:296:55\n\n  293 while (collectionProcessQueue.length > 0) {\n  294   const [parentCollID, coll] = collectionProcessQueue.shift()!;\n  295 \n→ 296   const createdColl = await tx.teamCollection.create(\nTransaction API error: Transaction already closed: Could not perform operation.",
            "locations": [
                {
                    "line": 2,
                    "column": 3
                }
            ],
            "path": [
                "importCollectionsFromJSON"
            ],
            "extensions": {
                "code": "INTERNAL_SERVER_ERROR",
                "stacktrace": [
                    "Error: PrismaClientKnownRequestError: ",
                    "Invalid `tx.teamCollection.create()` invocation in",
                    "/usr/src/app/src/team-collection/team-collection.service.ts:296:55",
                    "",
                    "  293 while (collectionProcessQueue.length > 0) {",
                    "  294   const [parentCollID, coll] = collectionProcessQueue.shift()!;",
                    "  295 ",
                    "→ 296   const createdColl = await tx.teamCollection.create(",
                    "Transaction API error: Transaction already closed: Could not perform operation.",
                    "    at throwErr (/usr/src/app/src/utils.ts:22:9)",
                    "    at TeamCollectionResolver.importCollectionsFromJSON (/usr/src/app/src/team-collection/team-collection.resolver.ts:291:32)",
                    "    at target (/usr/src/app/node_modules/@nestjs/core/helpers/external-context-creator.js:74:28)",
                    "    at Object.importCollectionsFromJSON (/usr/src/app/node_modules/@nestjs/core/helpers/external-proxy.js:9:24)"
                ]
            }
        }
    ],
    "data": null
}

I saw the same problem is faced by others. But the issue seems to be closed without any solution. Here is the link to the issue: https://github.com/hoppscotch/hoppscotch/issues/3975

ahsanaasim avatar Jul 04 '24 05:07 ahsanaasim

Hey @ahsanaasim if its not a problem could you share the file you were using so we can try reproducing the issue out end.

balub avatar Jul 04 '24 07:07 balub

Encountering the same issue cannot share the file since it has company data.

rampa2510 avatar Jul 14 '24 14:07 rampa2510

anyone solved this issue???

sxhil7 avatar Jul 19 '24 06:07 sxhil7

Dummy fix, but I import with Postman, then dump and re-import into Hoppscotch as the import function for Postman works.

CostcoFanboy avatar Sep 27 '24 12:09 CostcoFanboy

Any status update on this issue? We use .NET Swagger generated specs. same error as everyone else.

LucasVos avatar Oct 02 '24 14:10 LucasVos

Same here. First time trying Hoppscotch and shocked that I can't import an OpenAPI spec.

Jrb1x avatar Nov 01 '24 13:11 Jrb1x