POST API endpoint only working if request made from POSTMAN
I am developing an app which needs to send information to an endpoint another client has put online to receive POST requests. This is just a simple POST request I send with a body, then the client saves its body to wherever he wants to. This endpoint has no Authorization header as it has been removed recently due to thinking it might be the cause for it not to work. So, now, it only works if you do the request from Postman.
I created a simple Expressjs server and deployed on Vercel to mock that client endpoint for testing purposes (just returns the req.body to the client)
I deployed my main project on Vercel and made POST requests to my mock Express app. Works.
I deployed my main project on AWS Amplify and made POST requests to my mock Express app. Works.
But when I try to attack the original endpoint URL the client has put online, it just does not work. It returns a 404 status everytime. But not from Postman (200 status). I just don't get it... maybe I am malforming the requests? I just want to be really sure the issues is not on my end.
My code is part of a
create-t3-app
stack that uses tRPC
first to fetch information from my PlanetScale DB and then makes a POST request to that endpoint:23 Replies
@stoykotlv
taking a look
After all the debugging and trial/error I did I just think the client has the issue on how he has configured that endpoint, but maybe I am missing something on my end that I just can't see. But logically if code works on any endpoint I try but not on the one the client has set up...
fyi. logs from aws amplify
Okay, so you have a TRPC query that you run, which first gets data from the DB, then you make a POST request to a 3rd party API with the response from the DB.
Can you log the URL to which you are posting the request?
Might be something with the URL itself?
Yes, that is correct. The url itself it is not the issue, I tried hardcoding it to the code and it has the same problems.
Cuz if it works from everywhere else, but your trpc procedure, it won't be something from the client API
I mean, my tRPC procedure works for any url I try except the client API url
And does the client API work if you do a curl reqeust or via postman directly?
Yes, it does
Then the issue shouldn't be in the client API. Can you try removing the headers and see if that will work?
I am fetching the log, one moment
Same error without headers:
It doesnt make sense, I just can't understand what is happening
Where are you deploying this app?
vercel / aws
Well, it isn't much, but can you try switching to a
try/catch
block, as it might be resolving differently, thus causing these requests in .then()
not workingI switched from try/catch to .then() thinking the same the other way around.
The thing is the entire code works because when I post request to my other server it succeeds
just not on the client url
I am repeating myself here, but are you sure you are hitting the correct URL?
but then again it works on postman
yes.. same url works on postman, fails on the code
as I can see it is not something trivial I am missing on my code (it was what I was afraid of)
Have you tried doing a simple cURL request to the same URL? Just to see if it will give you the same error. It might be some header that Postman is adding, which you are missing here
Only other thing I can think of is setting up a repo where I can reproduce this, to see if I can debug it further.
I appreciate it but there is no need... this exact code is working when doing get/post requests to facebook API
no worries. Good luck troubleshooting further.
I've done it and the server responds well. I will go back on everything we've discussed step by step and make sure the app itself os not modifying the url on the fly (which I made sure it didn't)
In any case thank you for your effort and time!
Good luck!