The Expiry property I set in a pre-request script as follows:
var expiry = Date.now(Date.UTC());
pm.collectionVariables.set("config_expiry", expiry);
console.log("variable config_expiry is: "+pm.collectionVariables.get("config_expiry"));
The output in the log looks perfectly fine: variable config_expiry is: 1596034570100 If I convert that back to a human readable format, it is exactly the time I sent the request.
But on the server I get 0 as value for Expiry and if I look at the raw request I see the following:
Hmm, thatās quite odd. I tried to replicate your issue with Postman Echo, but the Expiry doesnāt display Invalid date. My initial guess would be that it could be server-side. One thing worth trying is for you to run a cURL request and see if the same issue persists?
You can use the code generation feature:
Iād recommend trying to see if you can replicate this behaviour with the cURL request.
Also, it looks like you included a bearer token in your message. Make sure to omit these sorts of credentials when posting anywhere.
Thanks for our reply. Regarding the Bearer Token: This is not a problem here since it is a VM on my local development computer running VMware Fusion. These tokens are re-generated daily when I restart my environment. And none of the VMs are accessible from outside of my machine (not even from my internal network).
Regarding Curl:
Thatās not working at all! (I tried from the shell of my MAC as well as from the shell of a virtual Fedora 32 Workstation) Here is what I copied from Postman:
Interesting: The code which is generated by Postman for curl (and also wget) both contain a value "Invalid Date" for the property Expiry! So this looks like something inside Postman generates thisā¦
And the result:
[1/6]: http://jazz-linuxdev:13666/bscadmin/v1/config.json?BscRequestMeta=CallingRequestId:ef6c2174-354e-46c7-8316-5730bf37ec98 --> <stdout>
--_curl_--http://jazz-linuxdev:13666/bscadmin/v1/config.json?BscRequestMeta=CallingRequestId:ef6c2174-354e-46c7-8316-5730bf37ec98
{"responseStatus":{"errorCode":"SerializationException","message":"Unable to bind to request 'BscUpsertConfigItemRequest'","errors":[{"errorCode":"SerializationException","fieldName":"BscRequestMeta","message":"'CallingRequestId:ef6c2174-354e-46c7-8316-5730bf37ec98' is an Invalid value for 'BscRequestMeta'"}]}}
[2/6]: http://jazz-linuxdev:13666/bscadmin/v1/config.json?BscRequestMeta=Source:%22PostmanApiTestCall%22 --> <stdout>
--_curl_--http://jazz-linuxdev:13666/bscadmin/v1/config.json?BscRequestMeta=Source:%22PostmanApiTestCall%22
{"responseStatus":{"errorCode":"SerializationException","message":"Unable to bind to request 'BscUpsertConfigItemRequest'","errors":[{"errorCode":"SerializationException","fieldName":"BscRequestMeta","message":"'Source:\"PostmanApiTestCall\"' is an Invalid value for 'BscRequestMeta'"}]}}
[3/6]: http://jazz-linuxdev:13666/bscadmin/v1/config.json?BscRequestMeta=CallingUserId:%22postman%22 --> <stdout>
--_curl_--http://jazz-linuxdev:13666/bscadmin/v1/config.json?BscRequestMeta=CallingUserId:%22postman%22
{"responseStatus":{"errorCode":"SerializationException","message":"Unable to bind to request 'BscUpsertConfigItemRequest'","errors":[{"errorCode":"SerializationException","fieldName":"BscRequestMeta","message":"'CallingUserId:\"postman\"' is an Invalid value for 'BscRequestMeta'"}]}}
[4/6]: http://jazz-linuxdev:13666/bscadmin/v1/config.json?BscRequestMeta=CallingUserEmail:%[email protected]%22 --> <stdout>
--_curl_--http://jazz-linuxdev:13666/bscadmin/v1/config.json?BscRequestMeta=CallingUserEmail:%[email protected]%22
{"responseStatus":{"errorCode":"SerializationException","message":"Unable to bind to request 'BscUpsertConfigItemRequest'","errors":[{"errorCode":"SerializationException","fieldName":"BscRequestMeta","message":"'CallingUserEmail:\"[email protected]\"' is an Invalid value for 'BscRequestMeta'"}]}}
[5/6]: http://jazz-linuxdev:13666/bscadmin/v1/config.json?BscRequestMeta=CallingUserIp:16.232.152.202 --> <stdout>
--_curl_--http://jazz-linuxdev:13666/bscadmin/v1/config.json?BscRequestMeta=CallingUserIp:16.232.152.202
{"responseStatus":{"errorCode":"SerializationException","message":"Unable to bind to request 'BscUpsertConfigItemRequest'","errors":[{"errorCode":"SerializationException","fieldName":"BscRequestMeta","message":"'CallingUserIp:16.232.152.202' is an Invalid value for 'BscRequestMeta'"}]}}
[6/6]: http://jazz-linuxdev:13666/bscadmin/v1/config.json?BscRequestMeta=clientType:%22Postman%22 --> <stdout>
--_curl_--http://jazz-linuxdev:13666/bscadmin/v1/config.json?BscRequestMeta=clientType:%22Postman%22
[~]
Donāt know if it has problems with encodingā¦
You write:
Could you please elaborate this a bit? In Postman this shows up under Request Body so I thought it did not yet talk to the server.
I currently run the server in the debugger and as I wrote, the server shows up a value of 0 for the Expiry. The server is written in C# against .NET Core 3.1. I use a library called ServiceStack which does the serialization from JSON to C#. But there I do not get any errors at all. (Just as a remark: I develop my servers under Fedora using JetBrains Rider, so no fancy windows compatibility stuff, all pure Linux. Production stuff runs as Docker containers under RHEL)
So to me it is still unclear who writes this āInvalid Dateā thereā¦ Is it a JavaScript problem or is there a problem with getting a variable from a Pre-request script in the Body of the request??
Hi Kevin, thanks for the hint regarding Find and Replace.
Hmm, not that I know, however I cannot completely exclude, that I tried a several set variants when I wrote my pre-request script. I am pretty sure I used the UI only to define the number of global variables I have, but it is possible, I tried several things when I tried setting a variable from a script.
I am designing and writing software for more than 2 decades but I am a bloody beginner with Postmanā¦ So a lot is possibleā¦
However after deleting the entry from the collection variables it works just fine!
Please allow for one more question: In the previous message I posted a screen shot with the Body for the request in question. Sometimes my JSON objects are a bit more complex and contain nested objects like shown there:
If I do this, the data is added exacly like shown above with tabs, spaces, CR/LF etc. Is this due to the fact, that I serialize into a string on the server side?
Just as little background: The server is written in C# and .NETCore. I develop it on Fedora with JetBrains Rider. The back-end DB is in this case MongoDB and the data contained in the property JsonValue is later converted to a MongoDB C# driver specific data type BsonDocument. I use this if I like to have dynamic, complex data stored under one property.
I just wonder if it is possible to write this in a more readable fashion in Postman than put everything on one single line, quote special characters etc.
I would look at sending it as a regular JSON object and de-serializing it as a string on the server side. If youāre piping this directly into a BsonDocument.Parse call, Iād also exercise caution, as I donāt know if that function sanitizes JSON. I imagine System.Text.Json handles some basic sanitizing of the data. Your request body would end up looking like this: