postmanlabs / postman-app-support

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.
https://www.postman.com
5.86k stars 840 forks source link

PreRequest script pm.environment.set('variable', null) will send STRING `null` with JSON body #12859

Open 6562680 opened 6 months ago

6562680 commented 6 months ago

Is there an existing issue for this?

Describe the Issue

Am testing verify sms/call service api with postman, So on method "start" i should clear previous data BEFORE request, and set new data AFTER request.

As i see in Environments - my environment contains correct values - filled that was filled, and empty that was cleared and didnt filled (because i returned NULL in that fields)

But, i send new json with fields (that is possible not exists) this way:

{
    "user_activity_uuid": "{{user_activity_uuid}}",
    "user_uuid": "{{user_uuid_real}}",
    "verify_channel": "PHONE_SMS",
    "verify_hash": "{{user_activity_verify_hash}}",
    "verify_code": "{{user_activity_verify_code}}",
    "verify_call": "{{user_activity_verify_call}}"
}

Guess, because postman see double quotes - it tries to convert NULL to null string. What solution could be? Or is it a bug, that is null value is auto-converted?

If i omit quotes - it could be invalid JSON i guess.

Steps To Reproduce

Read above

Screenshots or Videos

No response

Operating System

Windows

Postman Version

10.12.0

Postman Platform

Postman App

User Account Type

Signed In User

Additional Context?

No response

6562680 commented 6 months ago

up feature to add: "autoquotes of variable" / "autotrim quotes of variable" syntaxes