I’m trying to set up a test where I make a POST request but getting a 500 Server Error (Response Body that I’m seeing is Unexpected ‘T’ [JSON]; Tests reporting «There was an error in evaluating the test script: SyntaxError: Unexpected token T in JSON at position 0») and so Tests should show Failed for all 5 of my tests. What can i do?
One of my tests isn’t even run it looks like:
tests[«Status code is 201 Created»] = responseCode.code === 201;
Thanks in advance for your help.
Tien.
- post
- postman
asked Apr 11, 2017 at 23:23
TienTien
1691 gold badge3 silver badges10 bronze badges
2
-
Can you post the actual response received from the server i.e the headers and the raw response?
Apr 12, 2017 at 6:04
-
here you go, @PratikMandrekar: Raw response Body: «Internal Server Error», Headers: APPDYNAMICS_GUID →e87746c4-6e6c-4615-9eb9-5582af5c17d5 Connection →close Content-Length →21 Date →Wed, 12 Apr 2017 23:18:41 GMT Violation →Violation-Internal X-API-Handshake → X-RateLimit-Limit →1000 X-RateLimit-Remaining →1000 X-RateLimit-Reset →0
Apr 12, 2017 at 23:42
2 Answers
You can check that HTTP code is not 500 with following:
tests["Status code is not 500"] = responseCode.code != 500;
Is this what you’re looking for?
answered Apr 12, 2017 at 13:15
grinderX19grinderX19
5645 silver badges13 bronze badges
3
-
thank you @grinderX19 very much for your prompt assistance. Unfortunately, that didn’t work either. I’m seeing the following for Body: Pretty Text: Internal Server Error Pretty JSON: Unexpected ‘I’ When I click on the Tests tab from the Response section, I’m seeing «There was an error in evaluating the test script: SyntaxError: Unexpected token I in JSON at position 0» Btw, development now supported a scenario that failed earlier resulting in Unexpected ‘T’ [JSON] as I mentioned in the question title so I had to induce 500 response again by mucking with the request payload.
Apr 12, 2017 at 23:26
-
This!! How do you know this «responseCode» variable exists? I have been trying to find a list of this postman «default variables» and I cant find them.
May 21, 2020 at 19:39
-
I’ve found it in Postman’s Test examples (also can be seen in the Postman app, Tests tab, Snippets sidebar).
May 25, 2020 at 6:59
Error 500 means either you are sending some invalid JSON in your request body or some issue with your server.
Could tell more by looking at the request and response body.
Do you have your test under any if condition? I don’t any reason why the test didn’t run except if you have any syntax error in test section.
answered Apr 12, 2017 at 7:20
Dinesh KumarDinesh Kumar
1,69415 silver badges22 bronze badges
2
-
thank you @Pandit81 very much … I was sending a serial number for a serialnumber key that development wasn’t supporting yet till today. I would think their API would return a Bad Request instead … Now, I’m tricking the API with another bad request I think by sending i.e. «key1»: «a» instead of an integer and getting another 500. I tried responseCode.code != 500 test but it didn’t run this test either. Body: Pretty Text: Internal Server Error Pretty JSON: Unexpected ‘I’…
Apr 12, 2017 at 23:41
-
(continued) When I click on the Tests tab from the Response section, I’m seeing «There was an error in evaluating the test script: SyntaxError: Unexpected token I in JSON at position 0».
Apr 12, 2017 at 23:41
I’m trying to set up a test where I make a POST request but getting a 500 Server Error (Response Body that I’m seeing is Unexpected ‘T’ [JSON]; Tests reporting «There was an error in evaluating the test script: SyntaxError: Unexpected token T in JSON at position 0») and so Tests should show Failed for all 5 of my tests. What can i do?
One of my tests isn’t even run it looks like:
tests[«Status code is 201 Created»] = responseCode.code === 201;
Thanks in advance for your help.
Tien.
- post
- postman
asked Apr 11, 2017 at 23:23
TienTien
1691 gold badge3 silver badges10 bronze badges
2
-
Can you post the actual response received from the server i.e the headers and the raw response?
Apr 12, 2017 at 6:04
-
here you go, @PratikMandrekar: Raw response Body: «Internal Server Error», Headers: APPDYNAMICS_GUID →e87746c4-6e6c-4615-9eb9-5582af5c17d5 Connection →close Content-Length →21 Date →Wed, 12 Apr 2017 23:18:41 GMT Violation →Violation-Internal X-API-Handshake → X-RateLimit-Limit →1000 X-RateLimit-Remaining →1000 X-RateLimit-Reset →0
Apr 12, 2017 at 23:42
2 Answers
You can check that HTTP code is not 500 with following:
tests["Status code is not 500"] = responseCode.code != 500;
Is this what you’re looking for?
answered Apr 12, 2017 at 13:15
grinderX19grinderX19
5645 silver badges13 bronze badges
3
-
thank you @grinderX19 very much for your prompt assistance. Unfortunately, that didn’t work either. I’m seeing the following for Body: Pretty Text: Internal Server Error Pretty JSON: Unexpected ‘I’ When I click on the Tests tab from the Response section, I’m seeing «There was an error in evaluating the test script: SyntaxError: Unexpected token I in JSON at position 0» Btw, development now supported a scenario that failed earlier resulting in Unexpected ‘T’ [JSON] as I mentioned in the question title so I had to induce 500 response again by mucking with the request payload.
Apr 12, 2017 at 23:26
-
This!! How do you know this «responseCode» variable exists? I have been trying to find a list of this postman «default variables» and I cant find them.
May 21, 2020 at 19:39
-
I’ve found it in Postman’s Test examples (also can be seen in the Postman app, Tests tab, Snippets sidebar).
May 25, 2020 at 6:59
Error 500 means either you are sending some invalid JSON in your request body or some issue with your server.
Could tell more by looking at the request and response body.
Do you have your test under any if condition? I don’t any reason why the test didn’t run except if you have any syntax error in test section.
answered Apr 12, 2017 at 7:20
Dinesh KumarDinesh Kumar
1,69415 silver badges22 bronze badges
2
-
thank you @Pandit81 very much … I was sending a serial number for a serialnumber key that development wasn’t supporting yet till today. I would think their API would return a Bad Request instead … Now, I’m tricking the API with another bad request I think by sending i.e. «key1»: «a» instead of an integer and getting another 500. I tried responseCode.code != 500 test but it didn’t run this test either. Body: Pretty Text: Internal Server Error Pretty JSON: Unexpected ‘I’…
Apr 12, 2017 at 23:41
-
(continued) When I click on the Tests tab from the Response section, I’m seeing «There was an error in evaluating the test script: SyntaxError: Unexpected token I in JSON at position 0».
Apr 12, 2017 at 23:41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Open
Bysmyyr opened this issue
Mar 21, 2020
· 24 comments
Open
Postman api returns 500 and 504
#8213
Bysmyyr opened this issue
Mar 21, 2020
· 24 comments
Assignees
Comments
Postman API PUT to collections endpoint gives 500 and 504 and sometimes returns an empty body. We update the collections to 25 users from the ci run in wercker which runs 10 updates concurrently. Sometimes all they go through fine, sometimes there is one or two fail which is covered by retry logic but increasingly lately it fails so badly than 10 retries are not enough. Collections are quite big, about 600 requests altogether. It also generates double collections(some empty, some not).
500 {"error":{"name":"serverError","message":"Something went wrong with the server."}}
504:
<html>
<head><title>504 Gateway Time-out</title></head>
<body bgcolor="white">
<center><h1>504 Gateway Time-out</h1></center>
<hr><center>nginx</center>
</body>
</html>
@Bysmyyr can you write to us at help@getpostman.com. Would want to take a deeper look at this, I would suggest breaking the collection down into smaller collections of size (preferably lesser than 25 MB) as I see it is timeout error there.
Trying to make a GET request to https://api.covid19api.com/summary
but getting a 504 error. Was working fine on 05/02/2020
<title>504 Gateway Time-out</title>
504 Gateway Time-out
nginx/1.14.0 (Ubuntu)
@abiancu Your error is not even closely related to this. This is about postman internal API, not using poistman for some other API
@Bysmyyr — We have made few performance improvements to these endpoints in the last month. I’d like to know if you are still facing issues around big collection updates.
@mohitranka
I’m still facing the issue.
You can see more details in support ticket #60411
Specifically, for update collection request with body around 1MB, the «Something went wrong with the server.» error is returned after 1 minute.
Also note that collections API only operates on full collections.
You cannot update a single request/folder within a collection.
As a result, there is no workaround for this issue.
@mohitranka Thanks for your reply. Our issues have went worse in last months.
Our team checked on this further after the comment @Bysmyyr — may I know if it helped?
@galbarm We haven’t heard back from you on the ticket. Just checking to see if the recent improvements helped?
Our team checked on this further after the comment @Bysmyyr — may I know if it helped?
@galbarm We haven’t heard back from you on the ticket. Just checking to see if the recent improvements helped?
Hi,
I can’t tell if it helped because my workaround was to delete-create the whole collection for each update instead of using the update API, and this is how my system currently works.
This is not perfect because a failure after delete but before the creation is dangerous, but I had no other option.
Seems like you have some regression that causes this error to now occur for every (large enough) request.
Even the delete-create workaround doesn’t help now.
You may also want to know that the request takes place even though an error is returned.
As a result and to deal with that, this is how our code currently looks like:
case result if result.status == 200 => result.body[JsValue]
//workaround the slow Postman servers. see https://github.com/postmanlabs/postman-app-support/issues/8213
case result if result.status == 500 && result.body.contains("Something went wrong with the server") =>
logger.debug("finishing with success (even though postman 500), because we've observed that the collection gets updated regardless of the error.")
result.body[JsValue]
case result => throw HttpResponseException(result)
Please try not to change anything, unless you actually fix it.
Seeing the same behavior. Our collection is about 3 MB, 300+ requests with a lot of documentation. Put call to Collections returns a 504 after a minute but the collection gets updated a few minutes later. Have not tried the delete-create approach yet.
We had to remove most of the descriptions from our collection to lower the overall size, and now we get 500s only sometimes… It’s still pretty disappointing.
I’m seeing the 500 behavior as well. My collection file is only 350KB and I get a 500 error 100% of the time, but the collection does actually update. Similar use case to the requester: We want to update a collection from within our CI system. Here’s the exact curl request:
curl -v --location -g --request PUT "https://api.getpostman.com/collections/$collection_uid" \
--header "X-Api-Key: $POSTMAN_API_KEY" \
--header 'Content-Type: application/json' \
--data-binary '@postman.json'
I have also been seeing this issue, has there been any solution for this?
Thanks!
I our case (same company as the OP), this is still the workaround that we’re using:
We had to remove most of the descriptions from our collection to lower the overall size, and now we get 500s only sometimes… It’s still pretty disappointing.
We’ll be looking into alternative ways to publish our API documentation. For just making requests from the Postman app we can deal with no descriptions. I haven’t seen 500s in a long time now.
My workaround has been no longer using Postman 🤷♂️
@AndrewGuenther Have you switched to some alternative solution that you could recommend?
I’ve been using Paw and have been pretty happy with it so far.
Hey everyone, thanks for all your comments and patience with this issue.
We have been working on a new way of updating individual collection items (requests, folders, responses).
Please let me know if you’d be interested in testing the new endpoint.
Hey everyone, thanks for all your comments and patience with this issue.
We have been working on a new way of updating individual collection items (requests, folders, responses).
Please let me know if you’d be interested in testing the new endpoint.
I’ll be happy to
@bpedro Can I get access to the new endpoint? Our API is large and is suffering from serious issues when trying to update the whole collection.
Hi @gbarmashiahflir, thanks for your patience.
We are getting in touch with you privately with information about the individual collection items operations.
We have recently started to get 504 errors when retrieving the collection via the post API using Newman.
Newman logs are as follows
2022-10-27T12:02:27.091-07:00 error: collection could not be loaded
2022-10-27T12:02:27.091-07:00 Error fetching the collection from the provided URL. Ensure that the URL is valid.
2022-10-27T12:02:27.091-07:00 Error fetching collection, the provided URL returned status code: 504
On retrying this is fine but it does cause the test via Newman to fail which is annoying.
Any suggestions? I can share the URL privately if that helps
Hi! Related to the PUT operation failing for big collections, we already have exposed an endpoint that allows updating collection individual items (requests, folders, and responses). You can find documentation and examples here: https://www.postman.com/postman/workspace/postman-public-workspace/collection/16473433-f2f0cb8f-609d-443f-913c-9831187c326e?ctx=documentation
In addition, we have been improving the performance of the PUT and POST collections endpoints, but there will always be a limitation… I mean, we won’t process a collection of 100MB in a single PUT. In case of huge collections, the recommendation is to split them into smaller ones or use the collection individual items endpoint if possible.
After successfully setting up the server, I attempted to create a user by providing the necessary information in Postman in the form of Application/JSON. Unfortunately, the server’s response was not as expected.
POST /sign-up 500.
After attempting to utilize utf-8 with no success, I switched to form-urlencoded. However, this resulted in the display of
UnhandledPromiseRejectionWarning: Error: data and salt arguments required
.
const createUser = async (req, res, next) => {
const {
username,
email,
phonenumber,
password
}: {
username: string,
email: string,
phonenumber: string,
password: string
} = req.body;
const salt = bcrypt.genSaltSync(10);
const getRounds = bcrypt.getRounds(salt);
const passHash = bcrypt.hashSync(password, getRounds);
const createAt = new Date(Date.now());
try {
const createNewUser = 'INSERT INTO Creations (username, email, phonenumber, password, salt, created_at) VALUES (?,?,?,?,?,?)';
con.query(createNewUser, [username, email, phonenumber, passHash, salt, createAt], (err, results) => {
if (err) {
console.error(err);
}
console.log(results);
});
res.status(201).send({ success: true, message: 'Created new user', body: {username, email, phonenumber, password} });
} catch (error) {
res.status(500).send({ success: false, message: 'Server error' });
}
await next; }
mainRouter.post('/sign-up', createUser);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({ type: '*/*' }));
localhost:3002/sign-up
{
"username": "yoshi",
"email": "atw@gmailcom" ,
"phonenumber": "somthigna",
"password": "yesyes"
}
I am uncertain about the issue at hand, as I have been attempting to resolve it for the past 48 hours. Any assistance would be greatly appreciated.
The reason behind the error 500 on the server could be incorrect database setup. Those who are facing a similar issue should consider this as a probable cause.
Problem Description:
and this is my code (index.js), (auth.js)
const express = require("express");
const dotenv = require("dotenv");
const mongoose = require("mongoose");
const authRoute = require("./routes/auth");
const app = express();
dotenv.config();
app.use(express.json());
mongoose.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
}).then(console.log("Connected to MongoDB"))
.catch((err) => console.log("err"));
app.use("/api/auth",authRoute );
app.use("/api/auth",authRoute);
app.listen("3000", () => {
console.log("Backend is running.");
});
const router = require("express").Router();
const User = require("../models/User");
//REGISTER
router.post("/register", async (req, res) => {
try {
const newUser = new User({
username: req.body.username,
email: req.body.email,
password: req.body.password,
});
const user = await newUser.save();
res.status(200).json(user);
} catch (err) {
res.status(500).json(err);
}
});
//LOGIN
module.exports = router;
and image of the postman result
when I send the request postman posts empty curly brackets. I want to get the post data on the down of the body at the postman
screenshot of the postman
and this is what terminal logs
result on the terminal
Solution – 1
You should check what receives in user
object at const user = await newUser.save();
data would be in user.data
or use json
instead,
const user = await newUser.save();
res.status(200).jsonp(user);
Solution – 2
.env file must be inside the root folder, not the outside
Solution – 3
I got that error in postman and my problem was that I was adding a str data in an int field in pgAdmin