question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to import project via API - Request to check this out

See original GitHub issue

Hi team 👋

I’ve been trying to import a project to my CastleMock instance (version 1.55). Based on the Swagger specification, I built this curl:

curl --location --request POST 'http://localhost:8080/castlemock/api/rest/core/project/rest/import?type=rest' \ --header 'Authorization: Basic eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJjYXN0bGVtb2NrIiwiZXhwIjoxNjIyNDg2MjM3LCJ1c2VySWQiOiJtQ3NGWUEifQ.SvFL4dYXkUzNQpNNAPijheCj81ueffIw6EmRHSe9_eA8Zm8bTJMuEoxZGknhpy4_56B80H8qmxoCA9kO7Y5Ia0IKc2KUUM3h9RnjuOgiIWacxTMqcCetLlfPFP5XLrbFC2MsZbps1MGoC4qucjxigE9emcgoFhq6TVAizT15HjJ5j4Bsy-MyV8xYHWsrO6D04ikOm7HoWDAavYr_d0A1V_Uze6QWWaLKYlkS-CxQfc84E7oR6SJZk7hv7pxEngJKW31pgwl7FNh2i9f9JOhHA2hGXo2U-EF9QdQ8sgzv9T2MTEOfgPPAmCefmFTRxPRcs2RCT5_Khbjzx4KUdqn_Ow' \ --form '=@"/home/nico/Desktop/Project-2021-03-08.xml"'

and always got unauthorized {"timestamp":"2021-05-24T19:21:21.330+00:00","status":401,"error":"Unauthorized","message":"","path":"/castlemock/api/rest/core/project/rest/import"}

I generated the token from Swagger (http://localhost:8080/castlemock/swagger-ui) and then used it in Postman.

Wonder if I missing something or there is actually an issue. Any help/observation is welcome.

Thank you in advance! 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
karldahlgrencommented, May 27, 2021

Hi @nicohv. My apologies for the late response here. Regarding query param filtering: Yes, Castle Mock supports matching mocked responses based on incoming query parameters. More information can be found here: https://github.com/castlemock/castlemock/wiki/Use-Case:-REST#query-match

I hope you found this answer helpful.

Best regards, Karl

1reaction
karldahlgrencommented, May 24, 2021

Hi @nicohv. My guess is that the Authorization header is invalid. The correct value is Authorization: Basic {Base 64 encoded username:password}.

Example: Authorization: Basic admin:admin Example (Encoded) Authorization: Basic YWRtaW46YWRtaW4=

You can easily encode your username and password on this page: https://www.base64encode.org/

I was certain that I had created an article about this on our Wiki, but it seems that I have missed that. I will definitely do that as soon as I have some time over. For now, you can find more information regarding basic authentication on this Wikipedia article: https://en.wikipedia.org/wiki/Basic_access_authentication#Client_side

I hope this helps. If not, please don’t hesitate to write again. Good luck! Best regards, Karl Dahlgren

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to create a project via the API with path and import_url ...
After the API call failed, I tried creating this project from the GitLab UI to see if "testRepo-Put-clone" truly was a reserved name....
Read more >
Project import errors – Support Portal | Snyk
While importing a project into the Snyk console, you may sometimes encounter an error; for example: Some common errors and suggested...
Read more >
Some projects cannot be imported because they already exist ...
Uncheck the "copy projects into workspace" checkbox, and then click "refresh" button, you will be able to import the project.
Read more >
Git Import request api throwing 400 bad request error
I am trying to use below api for importing git repository from one visualstudio instance to another azure devops instance.
Read more >
Importing and exporting data | Postman Learning Center
How to Import and Export Data in Postman ... Using the API Builder. Postman Newsletter Subscribe for product updates, API best practices.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found