Forum Discussion

CarolineS's avatar
3 years ago

Basic Postman question w/ Khoros API

Hi ya'll!

I am very much a Postman / API newbie, attempting to do some very basic scripting w/ the Khoros API using Postman.

I have learned how to get the session key:

{{baseURL}}/restapi/vc/authentication/sessions/login?user.login={{khorosUsername}}&user.password={{khorosPassword}}

This returns

<response status="success">
 <value type="string">[SESSION-KEY]</value>
</response>

I can't figure out how to save this response as a variable; currently I copy-and-paste the session key into my session key variable.

How can I avoid this copy-paste? I know this is a postman-specific question but I figured a bunch of you have figured this out!

Thank you!

  • First, get the response in JSON format by adding &restapi.response_format=json to your API call.

    In Postman, click the Tests tab, and paste this code 

    var jsonData = JSON.parse(responseBody);
    postman.setEnvironmentVariable("sessionkey",jsonData.response.value.$);

     

    That will save the API key in the sessionkey variable. You can then use that variable in other API calls.

  • MattV's avatar
    MattV
    Khoros Staff

    First, get the response in JSON format by adding &restapi.response_format=json to your API call.

    In Postman, click the Tests tab, and paste this code 

    var jsonData = JSON.parse(responseBody);
    postman.setEnvironmentVariable("sessionkey",jsonData.response.value.$);

     

    That will save the API key in the sessionkey variable. You can then use that variable in other API calls.