Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
Jason_Rakers
Participant
Jump to solution

R80.10 API verify-policy Postman response

I am trying to pass the task-id response value from a verify-policy request in Postman as an environment variable.  However, it appears that the output of "task-id" is not a valid json reference?  Based on my testing it appears to be because of the dash "-" in the name "task-id".  Does anyone know of another why to retrieve this value? 

Here is my request:

I perform a verify-policy POST and get the following response:

{
"task-id" : "01234567-89ab-cdef-9966-b355dd0c80f1"
}

That request also has a test script to take the value of "task-id" and put it in my environment as variable "tk".  

var jsonData = JSON.parse(responseBody);

//use task as variable
postman.setEnvironmentVariable("tk", jsonData.task-id);

But executing this results in error, and the output from the Postman console indicates it is not defined, despite it shown in the response body.    

ReferenceError | id is not defined

Also i think the API reference documentation is incorrect as the only response i get from a web-session API call is the task-id, i do not receive the failure messages.  The only output I receive from my verify-policy POST is a task-id (contrary to the API reference with results for failure), whether the verification is good or has errors.  Therefore I am trying to also view the results of the verification task when it completes.  I am using the task-id in a following request to view the output of the verification (i.e. show-task API request).   
 
1 Solution

Accepted Solutions
Joshua_Hatter
Employee
Employee

In Javascript you cannot call a field from json with a hyphen in it the traditional way.

You have to do jsonObj['task-id']

javascript - Unable to access JSON property with "-" dash - Stack Overflow 

View solution in original post

2 Replies
Joshua_Hatter
Employee
Employee

In Javascript you cannot call a field from json with a hyphen in it the traditional way.

You have to do jsonObj['task-id']

javascript - Unable to access JSON property with "-" dash - Stack Overflow 

Jason_Rakers
Participant

Thanks!  That works!

My updated test script:

var jsonData = JSON.parse(responseBody);

//use task as variable
postman.setEnvironmentVariable("tk", jsonData['task-id']);

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events