locked
How do I get Postman to call my Web API? RRS feed

  • Question

  • User1642115476 posted

    Hello,

    I'm just wondering how I would get Postman, the plugin for Chrome that allows you to test web requests, to call my web API.

    Current, I'm using this AJAX call written in Javascript:

    alert("Getting security token");

    // Do AJAX call to get security token:
    $.ajax({
    url: [security token url],
    type: "POST",
    headers: {
    Accept: "application/json"
    },
    ContentType: "application/x-www-form-urlencoded",
    data: {
    grant_type: "password",
    username: [username],
    password: [password]
    }
    }).done(function(data)
    {
    var accessToken = data.access_token;

    alert(accessToken);

    alert("Getting json string.");

    // Now that we have access token, send it along with the request for the json string:
    $.ajax({
    // meta data sent as URL parameters:
    url: [url to get json string]
    type: "GET",
    headers: {
    Authorization: "Bearer " + accessToken // access token
    },
    contentType: false,
    processData: false
    }).done(function(data)
    {
    $("#jsonDiv").html(data);
    }).fail(function(jqXhr, textStatus, errorThrown)
    {
    alert("jqXhr = " + JSON.stringify(jqXhr));
    alert("textStatus = " + textStatus + ", errorThrown = " + errorThrown);
    });
    }).fail(function(jqXhr, textStatus, errorThrown)
    {
    alert("jqXhr = " + JSON.stringify(jqXhr));
    alert("textStatus = " + textStatus + ", errorThrown = " + errorThrown);
    });

    Note that it's a two step process: 1) do an ajax call to the API to get a security token, and then 2) do another ajax call to the API, sending the security token, to do whatever you want (in this case, I'm retrieving a json string).

    What would I have to do in Postman to accomplish the equivalent of this?

    Thanks

    Friday, June 9, 2017 1:57 PM

All replies

  • User475983607 posted

    What would I have to do in Postman to accomplish the equivalent of this?

    It would work the same way.  Submit the first request to get the token.  Copy the token and put it in the the subsequent request header. 

    Postman very easy to configure.  I suggest that you visit the Postman support page for help with the Chrome plugin.

    https://www.getpostman.com/support

    Friday, June 9, 2017 2:21 PM
  • User1967761114 posted

    Hi gib9898_00,

    According to the code which you provide, it seems like you are using OAuth2.0(authorization_code), but I couldn’t find OAuth2.0 in postman API, I only find OAuth1.0.

    About how to use OAuth1.0 on postman or other auth, you could refer to the following link.

    https://docs.postman-echo.com/#2f79ab5b-9029-56c2-7b05-52047790d670

    If you have any other questions, please feel free to contact me any time.

    Best Regards

    Even

    Monday, June 12, 2017 5:14 AM