PUT API call fails with error "BAD_Request"
search cancel

PUT API call fails with error "BAD_Request"

book

Article ID: 450546

calendar_today

Updated On:

Products

VMware NSX

Issue/Introduction

  • PUT API call using curl from NSX manager fails with error 'BAD_REQUEST'.

    https://[######]nsxtmgr1.iaas.opssq/policy/api/v1/infra/capacity/threshold
    {
      "httpStatus" : "BAD_REQUEST",
      "error_code" : 220,
      "module_name" : "common-services",
      "error_message" : "Unexpected character ('/' (code 47)): maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)"
    root@[######]nsxtmgrla:/#
    


  • Postman cannot be used due to usage limitation for third party application.

Environment

NSX 4.x

Cause

Improper formatting of the JSON payload or incorrect usage of inline JSON passed as body can lead to API errors.

Resolution

Using curl to run API calls, we need to pass below arguments:

  • A header type, normally application/json and defined with argument -H, not required if a GET method is used.

  • A method type, use -X to define what type of method is being used 'PUT/POST/PATCH/DELETE'.

  • The username and password used to run the API call, -u is used to define this, the password can be password or left empty to prompt the user to enter the password, if entered in the curl command, surround the username and password with single quotes.

  • When using curl for the like of PUT/POST/PATCH API call data needs to be passed, either via the command line or as a file with json content. The -d or --data flag can be used as shown below :

    • curl -k -u 'admin:Password' -H "Content-Type:application/json" -X PUT -d @Bodyy.json 'https://NSXFQDN/policy/api/v1/infra/capacity/threshold'

  • To fetch the input body for PUT call, please use GET API and copy the output to be used as body for  PUT/POST/PATCH API call

    • curl -k -u 'admin:Password' -X GET 'https://NSXFQDN/policy/api/v1/infra/capacity/threshold' 

Additional Information

Configure Postman for NSX REST API Requests