Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix: resolve issues around import via URL (#4906)

Nivedin346a1a368816
diff --git a/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/UrlImport.vue b/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/UrlImport.vue
index cc9a5a337..076b08cd3 100644
--- a/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/UrlImport.vue
+++ b/packages/hoppscotch-common/src/components/importExport/ImportExportSteps/UrlImport.vue
@@ -101,7 +101,8 @@ const urlFetchLogic =
const responsePayload = parseBodyAsJSON<unknown>(res.right.body)
if (O.isSome(responsePayload)) {
- return E.right(responsePayload)
+ // stringify the response payload
+ return E.right(JSON.stringify(responsePayload.value))
}
return E.left("REQUEST_FAILED")
diff --git a/packages/hoppscotch-common/src/helpers/import-export/import/import-sources/GistSource.ts b/packages/hoppscotch-common/src/helpers/import-export/import/import-sources/GistSource.ts
index 7a37f5fb7..1939b128a 100644
--- a/packages/hoppscotch-common/src/helpers/import-export/import/import-sources/GistSource.ts
+++ b/packages/hoppscotch-common/src/helpers/import-export/import/import-sources/GistSource.ts
@@ -48,11 +48,13 @@ export function GistSource(metadata: {
loading: metadata.isLoading?.value,
}))
}
-
const fetchGistFromUrl = async (url: string) => {
+ // Extract the gist ID from the URL (eg. https://gist.github.com/username/gistID/...)
+ const gistID = url.split("/")[4]
+
const { response } = interceptorService.execute({
id: Date.now(),
- url: `https://api.github.com/gists/${url.split("/").pop()}`,
+ url: `https://api.github.com/gists/${gistID}`,
method: "GET",
version: "HTTP/1.1",
headers: {
@@ -69,7 +71,7 @@ const fetchGistFromUrl = async (url: string) => {
const responsePayload = parseBodyAsJSON<unknown>(res.right.body)
if (O.isSome(responsePayload)) {
- return E.right(responsePayload)
+ return E.right(responsePayload.value)
}
return E.left("REQUEST_FAILED")