Pre-request Scripts in Postman | The Exploratory

Поделиться
HTML-код
  • Опубликовано: 2 июн 2022
  • You can use pre-request scripts in Postman to execute JavaScript before a request runs. By including code in the Pre-request Script tab for a request, collection, or folder, you can carry out pre-processing such as setting variable values, parameters, headers, and body data.
    Docs: learning.postman.com/docs/wri...
    Public Workspace: www.postman.com/twitter/works...
    For an example of a collection making use of pre-request scripts, check out Twitter’s public workspace in the link above. They use pre-request scripts at the collection level to handle authentication.
    Blog: / how-to-automate-oauth2...
    For an advanced and practical use case using pre-request scripts, check out this blog post by Allen Helton on refreshing OAuth 2.0 tokens.
    Presenter: Sean Keegan, Developer Advocate
  • НаукаНаука

Комментарии • 8

  • @siddharthau489
    @siddharthau489 Год назад

    Thanks for the detailed explanation. Can we write a pre request script to upload an image file as binary in the Body of the request?
    I have an api in which I upload the image binary in the body before sending the request. I'm trying to validate this through script. Could you please guide me how to write the script for this. Thank You.

  • @SRW27
    @SRW27 Год назад

    Hi, thanks for the explanation on this! I do have one question regarding Pre Request scripts, is there a way to change the Environment with a Pre Request Script? For example if I'm running a folder which is running against Environment "ABC" but one request within that folder I want to run against Environment "DEF" is there code i can put into Post Request Script of that particular request to do that?

    • @postman
      @postman  Год назад

      Hey there! You can't switch environment from the pre-request script, we're tracking it as a feature request here: github.com/postmanlabs/postman-app-support/issues/11055

  • @johnquarto
    @johnquarto Год назад

    If I heard you right, the pre-request for the collection will fire before any of the requests in the collection. Thinking of OAuth2, very useful but the API we are required to use is highly rate-limited for the getting of tokens; each is good for 15 minutes. Is there a way to save the token variable so that if I run, say 3 different requests one after the other, it only needs to get one token and can re-use it for the second and third requests, rather than requesting a new token every time?

    • @postman
      @postman  Год назад

      Yes, you can save the expiry date of the token in a variable and only get a new token when it has expired. We have an example of doing that in this collection, fork it and adapt it to your needs! www.postman.com/postman/workspace/postman-answers/documentation/9215231-2dd82ce4-b940-4797-8fff-662721c77c50?entity=&branch=&version=
      If you have any more questions I'd recommend posting them on the community forum: community.postman.com

  • @sergiu_s
    @sergiu_s 2 года назад

    Hi, i’m not sure is this the official postman channel, if so, it’s possible to improve the accessibility of postman for blind users that use the screen reader? Thanks

    • @postman
      @postman  2 года назад +1

      We recommend upvoting this feature request, or chiming in with your specific scenarios (if not already covered): github.com/postmanlabs/postman-app-support/issues/3121

    • @sergiu_s
      @sergiu_s 2 года назад

      @@postman thank you for replying. I noticed that a lot of accessible issues I found in Postman was been mentioned years ago. Do you have more realistic news about these problems? Are they working to fix them? Thanks