Receiving a Malformed JSON Error When Using API Doc
search cancel

Receiving a Malformed JSON Error When Using API Doc

book

Article ID: 144115

calendar_today

Updated On:

Products

CA Privileged Access Manager (PAM) CA Privileged Access Manager - Cloakware Password Authority (PA)

Issue/Introduction

When adding access methods through the API doc, the API body will be pre-populated with the following.

[  
     {  
         "customName":null,  
         "port":null,  
         "taskProperty":null,  
         "type":null  
     }
]

However, when the information is entered and "Try it out" is clicked, the response is a malformed JSON error.

Curl

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '[ \ 
     { \ 
         "customName":null, \ 
         "port":22, \ 
         "taskProperty":null, \ 
         "type":SSH \ 
     } \ 
 ]' 'https://1.1.1.1/api.php/v1/devices.json/1111/accessMethods'

Response Body
{ "error": { "code": 400, "message": "Bad Request: Error parsing JSON, malformed JSON" } }

Cause

The malformed JSON error means that the format of the API call is incorrect.

Resolution

In this case, the values for "port" and "type" do not have quotation marks around them. If the value is not null, quotation marks are required for the values.

Curl

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '[ \ 
     { \ 
         "customName":null, \ 
         "port":"22", \ 
         "taskProperty":null, \ 
         "type":"SSH" \ 
     } \ 
 ]' 'https://1.1.1.1/api.php/v1/devices.json/1111/accessMethods'