Executing DQL Query via API Results in a Syntax Error

Article: 100053466
Last Published: 2022-08-02
Ratings: 0 0
Product(s): Data Insight

Problem

When running a DQL query via the API, it results in a syntax error 

Error Message

Status: 400 Bad Request

Cause

The DQL Query contains paths with HTML special characters that are not processed by the URL Encoder

Example:  

FROM dfspath GET absname, device.name, msu.name, name, basename, owner.user.login, owner.user.name where absname='\\vtas.local\dfsnamespace\Supportdfs\sub1\Test Folder\Another folder\BHanley_30.txt'

Solution

Convert the special characters in the path with the corresponding URL percent encoding value

In the example above, convert \ to %5C and convert the <SPACE> to %20

Example: 

FROM dfspath GET absname, device.name, msu.name, name, basename, owner.user.login, owner.user.name where absname='%5C%5C%5C%5C%5C%5Cvtas.local%5CTEST%5Cdfsnamespace%5CSupportdfs%5Csub1%5CTest%20Folder%5CAnother%20folder%5CBHanley_30.txt'

API Command:

POST https://192.168.10.220:443/api?function=report&cmd=dql&query='FROM dfspath GET absname, device.name, msu.name, name, basename, owner.user.login, owner.user.name where absname='%5C%5C%5C%5C%5C%5Cvtas.local%5CTEST%5Cdfsnamespace%5CSupportdfs%5Csub1%5CTest%20Folder%5CAnother%20folder%5CBHanley_30.txt''&MATRIX_AUTH=CAE482FC79A635E43DDA88C0789CACFE&format=csv&compress=true"

Result:

NOTE:

When processing a path with a double backslash '\\' via the API you will need to add four additional backslash characters (for a total of six '\\\\\\') to escape out and result in a double backslash as shown in the example query

Example: 

FROM dfspath GET absname, device.name, msu.name, name, basename, owner.user.login, owner.user.name where absname='%5C%5C%5C%5C%5C%5Cvtas.local%5CTEST%5Cdfsnamespace%5CSupportdfs%5Csub1%5CTest%20Folder%5CAnother%20folder%5CBHanley_30.txt'

Reference

URL Encode and Decode - Online (urlencoder.org)

Was this content helpful?