Get /surveys/{{survey-id}}/logic-graph
This functionality is currently released in ALPHA and under testing. BETA release is expected in May 2026.

Example Request

https://api.questionpro.{{env}}/a/api/v2/surveys/{{survey-id}}/logic-graph

The value of environment {{env}} variable depends upon your datacenter. Refer to the Environment page for more details.


Enumerates every unique logical path through the survey identified by survey-id. The server traverses the survey's branching rules and returns an ordered list of PathStep objects for each possible route a respondent can take. Each step identifies the section visited (sectionId) and the answer that triggered the next branch (answerId; 0 when the transition is unconditional).


Authorization

arrow_rightSecurity - API Key
Name : api-key
required
Location : Request Header
Type : string

Request Parameters

arrow_rightPath Parameters
survey-id integer
required

Example Code

arrow_rightcURL
Snippet copied successfully.
application/json

                curl --location 'https://api.questionpro.{{env}}/a/api/v2/surveys/{{survey-id}}/logic-graph' \
                --header 'Accept: application/json' \
                --header 'api-key: {{api-key}}'
            
arrow_rightPython
Snippet copied successfully.
application/json

                import requests

                url = "https://api.questionpro.{{env}}/a/api/v2/surveys/{{survey-id}}/logic-graph"

                headers = {
                    "Accept": "application/json",
                    "api-key": "{{api-key}}"
                }

                response = requests.get(url, headers=headers)
                data = response.json()

                total_paths = data["response"]["totalPaths"]
                paths = data["response"]["paths"]

                for index, path in enumerate(paths):
                    print("Path " + str(index + 1) + ":")
                    for step in path:
                        print("  sectionId=" + str(step["sectionId"]) + "  answerId=" + str(step["answerId"]))
            
arrow_rightPHP - cURL
Snippet copied successfully.
application/json

                <?php

                $curl = curl_init();

                curl_setopt_array($curl, array(
                    CURLOPT_URL            => 'https://api.questionpro.{{env}}/a/api/v2/surveys/{{survey-id}}/logic-graph',
                    CURLOPT_RETURNTRANSFER => true,
                    CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
                    CURLOPT_CUSTOMREQUEST  => 'GET',
                    CURLOPT_HTTPHEADER     => array(
                        'Accept: application/json',
                        'api-key: {{api-key}}'
                    ),
                ));

                $response = curl_exec($curl);
                curl_close($curl);

                $data       = json_decode($response, true);
                $totalPaths = $data['response']['totalPaths'];
                $paths      = $data['response']['paths'];

                foreach ($paths as $i => $path) {
                    echo "Path " . ($i + 1) . ":\n";
                    foreach ($path as $step) {
                        echo "  sectionId=" . $step['sectionId'] . "  answerId=" . $step['answerId'] . "\n";
                    }
                }
            
arrow_rightJavaScript (fetch)
Snippet copied successfully.
application/json

                const response = await fetch(
                    'https://api.questionpro.{{env}}/a/api/v2/surveys/{{survey-id}}/logic-graph',
                    {
                        method: 'GET',
                        headers: {
                            'Accept': 'application/json',
                            'api-key': '{{api-key}}'
                        }
                    }
                );

                const data = await response.json();
                const totalPaths = data.response.totalPaths;
                const paths = data.response.paths;

                paths.forEach(function(path, index) {
                    console.log('Path ' + (index + 1) + ':');
                    path.forEach(function(step) {
                        console.log('  sectionId=' + step.sectionId + '  answerId=' + step.answerId);
                    });
                });
            

Responses

arrow_right200 OK — Paths enumerated successfully
application/json

                    {
                        "response": {
                            "totalPaths": 3,
                            "paths": [
                                [
                                    { "sectionId": 10001, "answerId": 50001 },
                                    { "sectionId": 10003, "answerId": 0 },
                                    { "sectionId": 10005, "answerId": 0 }
                                ],
                                [
                                    { "sectionId": 10001, "answerId": 50002 },
                                    { "sectionId": 10002, "answerId": 0 },
                                    { "sectionId": 10005, "answerId": 0 }
                                ],
                                [
                                    { "sectionId": 10001, "answerId": 50003 },
                                    { "sectionId": 10004, "answerId": 0 },
                                    { "sectionId": 10005, "answerId": 0 }
                                ]
                            ]
                        },
                        "requestID": "8012fedc-e8ce-48ae-b800-6q5ce287987a"
                    }
                
arrow_rightSchema
application/json
{
  "$schema": "http://json-schema.org/draft-06/schema# ",
  "type": "object",
  "properties": {
    "response": {
      "type": "object",
      "properties": {
        "totalPaths": {
          "type": "string"
        },
        "paths": {
          "type": "array",
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "answerId": {
                  "type": "string"
                },
                "sectionId": {
                  "type": "string"
                }
              },
              "additionalProperties": false,
              "required": [
                "answerId",
                "sectionId"
              ]
            }
          }
        }
      },
      "additionalProperties": false,
      "required": [
        "totalPaths",
        "paths"
      ]
    },
    "requestID": {
      "type": "string"
    }
  },
  "additionalProperties": false,
  "required": [
    "response",
    "requestID"
  ]
}
arrow_right200 OK — Linear survey (single path, no branching)
application/json

                    {
                        "response": {
                            "totalPaths": 1,
                            "paths": [
                                [
                                    { "sectionId": 10001, "answerId": 0 },
                                    { "sectionId": 10002, "answerId": 0 },
                                    { "sectionId": 10003, "answerId": 0 }
                                ]
                            ]
                        },
                        "requestID": "8012fedc-e8ce-48ae-b800-6q5ce287987a"
                    }
                
arrow_right200 OK — Survey with no sections
application/json

                    {
                        "response": {
                            "totalPaths": 0,
                            "paths": []
                        },
                        "requestID": "8012fedc-e8ce-48ae-b800-6q5ce287987a"
                    }
                
arrow_right400 example
application/json

{
    "response": {
     "error": {
         "docs": www.questionpro.com/api/error-codes.html
         "name": "BAD_REQUEST",
         "httpStatusCode": 400,
         "id" : "1000",
         "message": "Invalid URL parameters",
         "resourceUrl":"resource_url"
        }
    }
}
                                
arrow_rightSchema
application/json

{
  "$schema": "http://json-schema.org/draft-06/schema#                                 ",
  "type": "object",
  "properties": {
    "response": {
      "type": "object",
      "properties": {
        "error": {
          "type": "object",
          "properties": {
            "docs": {
              "type": "string"
            },
            "resourceUrl": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "id": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "httpStatusCode": {
              "type": "integer"
            }
          },
          "additionalProperties": false,
          "required": [
            "docs",
            "resourceUrl",
            "name",
            "id",
            "message",
            "httpStatusCode"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "error"
      ]
    }
  },
  "additionalProperties": false,
  "required": [
    "response"
  ]
}
                                
arrow_right401 example
application/json

{
    "response": {
     "error": {
         "docs": www.questionpro.com/api/error-codes.html
         "name": "UNAUTHORIZED",
         "httpStatusCode": 401,
         "id" : "1010",
         "message": "Incorrect API Key",
         "resourceUrl":"resource_url"
        }
    }
}
						
							
arrow_rightSchema
application/json

{
  "$schema": "http://json-schema.org/draft-06/schema#                                 ",
  "type": "object",
  "properties": {
    "response": {
      "type": "object",
      "properties": {
        "error": {
          "type": "object",
          "properties": {
            "docs": {
              "type": "string"
            },
            "resourceUrl": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "id": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "httpStatusCode": {
              "type": "integer"
            }
          },
          "additionalProperties": false,
          "required": [
            "docs",
            "resourceUrl",
            "name",
            "id",
            "message",
            "httpStatusCode"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "error"
      ]
    }
  },
  "additionalProperties": false,
  "required": [
    "response"
  ]
}
                                
arrow_right403 example
application/json

{
    "response": {
     "error": {
         "docs": www.questionpro.com/api/error-codes.html
         "name": "FORBIDDEN",
         "httpStatusCode": 403,
         "id" : "1013",
         "message": "The user does not have permission to access the resource",
         "resourceUrl":"resource_url"
        }
    }
}				
							
arrow_rightSchema
application/json

{
  "$schema": "http://json-schema.org/draft-06/schema#                                 ",
  "type": "object",
  "properties": {
    "response": {
      "type": "object",
      "properties": {
        "error": {
          "type": "object",
          "properties": {
            "docs": {
              "type": "string"
            },
            "resourceUrl": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "id": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "httpStatusCode": {
              "type": "integer"
            }
          },
          "additionalProperties": false,
          "required": [
            "docs",
            "resourceUrl",
            "name",
            "id",
            "message",
            "httpStatusCode"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "error"
      ]
    }
  },
  "additionalProperties": false,
  "required": [
    "response"
  ]
}
                                
arrow_right404 example
application/json

{
    "response": {
     "error": {
         "docs": www.questionpro.com/api/error-codes.html
         "name": "NOT_FOUND",
         "httpStatusCode": 404,
         "id" : "1040",
         "message": "The resource that you're trying to access doesn't exist",
         "resourceUrl":"resource_url"
        }
    }
}
							
							
arrow_rightSchema
application/json

{
  "$schema": "http://json-schema.org/draft-06/schema#                                 ",
  "type": "object",
  "properties": {
    "response": {
      "type": "object",
      "properties": {
        "error": {
          "type": "object",
          "properties": {
            "docs": {
              "type": "string"
            },
            "resourceUrl": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "id": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "httpStatusCode": {
              "type": "integer"
            }
          },
          "additionalProperties": false,
          "required": [
            "docs",
            "resourceUrl",
            "name",
            "id",
            "message",
            "httpStatusCode"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "error"
      ]
    }
  },
  "additionalProperties": false,
  "required": [
    "response"
  ]
}
                                
arrow_right500 example
application/json

{
    "response": {
     "error": {
         "docs": www.questionpro.com/api/error-codes.html
         "name": "INTERNAL_SERVER_ERROR",
         "httpStatusCode": 500,
         "id" : "1026",
         "message": "We are not able to process your request",
         "resourceUrl":"resource_url"
        }
    }
}
							
arrow_rightSchema
application/json

{
  "$schema": "http://json-schema.org/draft-06/schema#                                 ",
  "type": "object",
  "properties": {
    "response": {
      "type": "object",
      "properties": {
        "error": {
          "type": "object",
          "properties": {
            "docs": {
              "type": "string"
            },
            "resourceUrl": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "id": {
              "type": "string"
            },
            "message": {
              "type": "string"
            },
            "httpStatusCode": {
              "type": "integer"
            }
          },
          "additionalProperties": false,
          "required": [
            "docs",
            "resourceUrl",
            "name",
            "id",
            "message",
            "httpStatusCode"
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "error"
      ]
    }
  },
  "additionalProperties": false,
  "required": [
    "response"
  ]
}
                                

PathStep Reference

arrow_rightUnderstanding PathStep fields
Each path is an ordered array of PathStep objects representing one complete route through the survey from the first section to the last.
sectionId — the ID of the survey section (question) visited at this position in the path.
answerId — the ID of the specific answer that caused the survey to branch to the next step. A value of 0 means the transition to the next section is unconditional (i.e. no skip logic or branching rule was triggered).
Every section in the survey appears at least once across all paths. Sections shared by multiple branches will appear in multiple paths.
The last step in each path always has answerId=0 because there is no subsequent branch after the final section.

Usage Notes

arrow_rightIntended use cases
Use this endpoint to pre-compute all possible survey flows before driving a respondent through a headless integration.
Combine with GET /surveys/{survey-id}/take to verify that a specific answer sequence leads to the expected path.
The number of paths grows with each branching question. Surveys with deep or highly conditional logic may return a large paths array.
This endpoint is stateless — it does not create a session or consume a response slot. It can be called freely without affecting survey quotas or response counts.