Меню

Postman запрос возвращающий 404 ошибку

Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Patrick Perkins

The route is valid in Postman on a GET request because the json quote is returned. However, when changing to a PUT request and sending json in the body, I get a 404 error but am not receiving the error message «Quote not found» from the code.

Here is my code:

app.put('quotes/:id', async (req,res) => {
  try {
    const quote = await records.getQuote(req.params.id);
    if (quote) {
      quote.quote = req.body.quote;
      quote.author = req.body.author;

      await records.updateQuote(quote);
      res.status(204).end();
    } else {
      res.status(404).json({message: "Quote not found"})
    }
    records.updateQuote(quote)
  } catch (err) {
    res.status(500).json({message: err.message});
  }
})

2 Answers

Zimri Leijen January 10, 2020 7:28pm

app.put('/quotes/:id', async (req,res) => { // you were missing the '/' before quotes
  try {
    const quote = await records.getQuote(req.params.id);
    if (quote) {
      quote.quote = req.body.quote;
      quote.author = req.body.author;

      await records.updateQuote(quote);
      res.status(204).end();
    } else {
      res.status(404).json({message: "Quote not found"})
    }
    records.updateQuote(quote)
  } catch (err) {
    res.status(500).json({message: err.message});
  }
})

Pablo Calvo

Same happened here… lol, thanks, been 3 days stuck looking at it

In the previous section, we had returned the proper response status of CREATED when we created the resource. In this section, we will discuss what should be the response when a user resource does not exist.

Let’s try and execute a simple response.

Step 1: Open Rest client Postman and select the Get method.

Step 2: Click on the History tab and choose the Get request.

Step 3: Type the URI http://localhost:8080/users/{id}. The user id should not exist.

Step 4: Click on the Send Button.

Implementing Exception Handling- 404 Resource Not Found

We get the Status: 200 OK and empty body which is a successful response even though the resource does not exist. But it is not the proper response when a resource does not exist.

Let’s fix that first.

Step 1: Open the UserResource.java file.

Step 2: Create a UserNotFoundException. It is a checked exception.

Step 3: Create UserNotFoundException class.

Step 4: Generate Constructors from Superclass.

Right-click on the file -> Source -> Generate Constructors from Superclass… -> check the RuntimeException(String) -> Generate.

Implementing Exception Handling- 404 Resource Not Found

UserNotFoundException.java

Step 5: Open the Rest Client Postman and generate a Get response as we have done before. It shows the Status: 500 Internal Server Error.

Implementing Exception Handling- 404 Resource Not Found

But the Status: 500 Internal Server Error is not the appropriate response for the resource not found. So, we will add an annotation @ResponseStatus to generate the Status: 404 Not Found.

UserNotFoundException.java

Step 6: Again move to Postman and generate a Get request.

Implementing Exception Handling- 404 Resource Not Found

We get the proper response Status: 404 Not Found when a user resource does not exist. The body of the request provided by default error handling that’s why we are getting this return status back.

Implementing Exception Handling- 404 Resource Not Found

The combination of Spring Boot and Spring Web MVC framework provides error handling. Spring Boot auto-configures some default exception handling. It is important to have a consistent exception message which is obtained for all the services inside our enterprise.

If we have a big organization and each of the services returns the exception messages in a different way, so it is not good. It would be good if we define a standard exception structure which is followed by across all the RESTful Services.


MMoss

Building a reputation

‎05-05-2020

08:30 AM

Postman returning 404 error


I jumped into Postman for the first time since February and all of my GET commands are returning 404 errors. To troubleshoot I ran previously good GET calls from history and even went to back to basics and did the getOrganizations request. I’ve used the base url of https//api.meraki.com/api/v0 and the shard for the dashboard in it’s place. Not sure if this snip is enough to get an idea of the cause or not. I also reset my API thinking it was the error but the new one didn’t help any. 

image.png

1 ACCEPTED SOLUTION

Edgar-VO

Building a reputation

‎05-11-2020

04:25 AM

Hi,

Python is easy to get it…

import meraki

import apikey

api_key = apikey.Get_Api_Key(«»)

dashboard       = meraki.DashboardAPI(api_key)

my_org = dashboard.organizations.getOrganizations()

for org in my_org:

        org_id = org[‘id’]

        print(org)


  • All forum topics


  • Previous Topic

  • Next Topic

17 REPLIES 17

Steinbep

Getting noticed

‎05-05-2020

09:42 AM

What version of the postman package are you using? Are you using the beta for v1?

ammahend

Getting noticed

‎05-05-2020

09:55 AM

for most part I am not seeing any issue, which specific GET call are you making ?

ammahend_0-1588697674281.png

MMoss

Building a reputation

‎05-05-2020

09:59 AM

As a test I was trying to pull the Org ID using the Meraki Dashboard API request they put out. The collection version is .10 released on April 1st, no beta version.

ammahend

Getting noticed

‎05-05-2020

11:15 AM

in your printshot, I don’t see «content-type» header key and value

MMoss

Building a reputation

‎05-05-2020

11:32 AM

I only used what was in the template, I used the variables for what was requested but I don’t recall using anything other than those variables

Edgar-VO

Building a reputation

‎05-05-2020

12:16 PM

Hi there,

Here you have a snippet from my postman…

Simply fill in the API key and Content-Type at the headers and you are set to go.

Edgar-VO_0-1588706151468.png

MMoss

Building a reputation

‎05-07-2020

05:12 AM

@Edgar-VO I added Content-Type and application/json but no luck :disappointed_face: Same 404 error

Edgar-VO

Building a reputation

‎05-07-2020

07:49 AM

Hi,

Try changing your url in https://api.meraki.com/api/v0/organizations/ The API key will redirect you to the proper organsation. Also removing all keys except for API and content type

Then you have the same postman as i have, and it should be working….. I think your problem lies in the URL

Ed

MMoss

Building a reputation

Edgar-VO

Building a reputation

‎05-07-2020

08:41 AM

Hi,

I still see a lot of useless keys…..try removing them. Keep only API and Content type

That is for now the only difference i can see in my request

MMoss

Building a reputation

‎05-07-2020

08:42 AM

Sad thing is I’m using the ones Meraki put out. I’ll try it shortly

MMoss

Building a reputation

‎05-07-2020

11:14 AM

Didn’t work, but I noticed you have yours hidden. The little eye icon at the top will show them. What do you have for Query Params on the first tab if anything?

Edgar-VO

Building a reputation

MMoss

Building a reputation

‎05-08-2020

07:29 AM

Already using it, uninstalled and reinstalled even

MMoss

Building a reputation

‎05-08-2020

09:32 AM

I’m learning Python so I’m really about to kick this to the curve. It’s was quick and easy to pick up, but doesn’t look like it’s going to work like it used to.

Edgar-VO

Building a reputation

‎05-11-2020

04:25 AM

Hi,

Python is easy to get it…

import meraki

import apikey

api_key = apikey.Get_Api_Key(«»)

dashboard       = meraki.DashboardAPI(api_key)

my_org = dashboard.organizations.getOrganizations()

for org in my_org:

        org_id = org[‘id’]

        print(org)

MMoss

Building a reputation

‎05-11-2020

05:24 AM

I’ve been working on learning it for awhile now. Unfortunately I can’t seem to manage not being pulled in 100 different directions on a daily basis so it’s not going as fast as I’d like.

Get notified when there are additional replies to this discussion.

title order updated page_id contextual_links warning

Receiving responses

23

2022-01-27

responses

type name

section

Prerequisites

type name url

link

Sending requests

/docs/sending-requests/requests/

type name

section

Additional Resources

type name

subtitle

Videos

type name url

link

How to Inspect API Responses

type name

section

Next Steps

type name url

link

Grouping requests in collections

/docs/sending-requests/intro-to-collections/

false

The Postman response viewer helps you to visualize and check the correctness of API responses. An API response consists of the response body, headers, and the HTTP status code.

Contents

  • Response body
  • Cookies
  • Headers
  • Test results
  • Network information
    • SSL verification errors
  • Response code
  • Response time
  • Response size
  • Saving responses
  • Viewing security warnings

Response body

The Postman Body tab gives you several tools to help you understand the response quickly. You can view the body in one of four views: Pretty, Raw, Preview, and Visualize.

Finding items in responses — To open the search bar, select the search icon Search icon in the results pane. You can also place your cursor in the response and select ⌘+F or Ctrl+F. This option isn’t available in a response’s Preview or Visualize views.

Note that if the response’s Content-Type header indicates that the response is an image, Postman will detect and render the image automatically.

Pretty

The Pretty view formats JSON or XML responses so they’re easier to view. Links inside Pretty view are highlighted, and selecting them can load a GET request in Postman with the link URL.

For navigating large responses, select the down arrows next to a line to collapse large sections of the response.

Response Pretty view

Forcing JSON formatting. For Postman to automatically format the body, the response must have the appropriate Content-Type header. If you receive a response with a different Content-Type header, you can force formatting through JSON. In the Postman header, select the settings icon Settings icon, then select Settings. In the General tab, select JSON from the Language detection dropdown.

Raw

The Raw view is a large text area with the response body. It can indicate whether your response is minified.

Response Raw view

Preview

The Preview view renders the response in a sandboxed iframe. Some web frameworks by default return HTML errors, and Preview can be especially helpful for debugging in those cases.

Due to iframe sandbox restrictions, JavaScript and images are turned off in the iframe. For binary response types, you can select “Send and download” to save the response locally. You can then view it using the appropriate viewer. This gives you the flexibility to test audio files, PDFs, zip files, or any other file types the API returns.

Response Preview view

Visualize

The Visualize view renders the data in the API response according to visualization code that you add to the requests Tests. For details on how to add, use, and debug visualization code, see Visualizing responses.

Response Visualize view

Cookies

You can inspect cookies sent by the server in the Cookies tab. A cookie’s entry includes its name, value, the associated domain and path, and other information about the cookie.

To learn more about working with cookies in Postman, see Using cookies.

Headers

Headers are displayed as key-value pairs under the Headers tab. Hover over the information icon Information icon next to the header name to get a description of the header according to the HTTP specification.

If you send a HEAD request, Postman will show the Headers tab by default instead of the Body tab.

Test results

If the API request you are viewing had any test scripts, the results are displayed in the Test Results tab.

To learn more about running tests against API requests in Postman, see Writing tests.

Network information

Postman displays network information when your API returns a response. Hover over the network icon Network information icon to get the local and remote IP addresses for the request you sent.

When you make an https request, the network icon includes a padlock. When you hover over the icon, the network information will show more information including certificate verification details.

Hover over the network icon for network information

SSL verification errors

If you have SSL verification enabled in Postman’s global settings and verification fails, the response area will display an error message. Select the link in the error message to turn off verification globally and immediately run the request again.

If SSL is turned off globally but turned on for your request, Postman displays the error and gives you a link to open the console.

Verification error

If you select Disable SSL Verification in the error message, you will need to turn it back on if you want to verify certificates for future requests. To enable it globally, select the settings icon Settings icon in the header and then select Settings. In the General tab, select SSL certificate verification.

To enable SSL verification for only the current request, select the Settings tab in the request, and then select Enable SSL certificate verification.

If you have SSL verification turned off and your request returns a certificate verification error, you can hover over the network information for details about the error.

Certificate error

For requests that return data successfully but with a certificate verification failure, the console displays a warning.

Response code

Postman displays the response code returned by the API. Hover over the response code to get a short description of the code and what it means.

Hover over the response code to get a description

Some API responses also contain custom messages that can help you understand response codes. For example, if you receive a 401 Unauthorized response, the message might tell you to check the token you used in the request. If custom messages are returned, they’re displayed in the Body of the response.

Response time

Postman automatically calculates the time in milliseconds it took for the response to arrive from the server. This information can be useful for some preliminary performance testing. Hover over the response time for a graph with information on how long each event in the process took.

Hover over the response code for a description

Response size

Postman displays the approximate size of the response. Hover over the response size to get a breakdown by body and header sizes.

Saving responses

If a request has been saved in a collection, you can save responses for that request. Once the response has been returned, select Save Response.

  • Select Save as example to save the response as an example that you can access later.
  • Select Save to a file to save the response as a JSON file.

Save an API response as an example or file

Viewing security warnings

Postman applies security rules configured for your API requests when you send requests to any API using either the Postman web app or the Postman desktop app. A security warning indicates that there are potential security risks the API might be vulnerable to, but they don’t mean the API is broken.

To view the specific security warnings that Postman applies to all requests, see Security warnings.

If it finds any potential security risks, Postman adds the number of warnings to the Security tab in the response.

Security tab showing one warning

To view the list of security warnings and to get more information about specific warnings, do the following:

  1. Select Security to view the warnings.
  2. For more details, select a warning to expand it.
  3. Select Possible fix to learn about possible ways to fix the underlying problem.

Select Possible fix in a security warning

Hiding security warnings

To turn a warning off for the current API response, do the following:

  1. Select Hide warning.
  2. Choose a reason for hiding it, then select Hide.

This will turn the warning off for all members of your team, but only for this response.

To turn a warning off globally for your team, you can configure your API Security rules (available for Enterprise teams only).

Select Hide warning in a security warning

When you or another member of your team has hidden a warning, Postman shows a message in the Security tab to indicate how many are hidden.

To turn this warning back on later, do the following:

  1. Select Review.
  2. Review your hidden warnings and select the eye icon Eye icon next to the one you want to turn back on.

Review hidden security warnings

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Postimg cc ошибка 404
  • Postgresql при инициализации базы данных произошла ошибка