Skip to main content

I am trying to make an API call to create a credential but is failing with error “Request body is empty, or format is invalid.”
I did not modify anything except the endpoint and Token. I am not sure what mistake I am doing here. 
documentation referred # https://api.commvault.com/docs/SP32/api/cv/OpenAPI3/create-credential/

 

 

import requests
import json

url = "https://commvault.newblr.com/commandcenter/api/V4/Credential"

payload = json.dumps({
  "accountType": "CLOUD_ACCOUNT",
  "vendorType": "HITACHI_VANTARA_HCP_S3",
  "name": "HCPBucketuser01",
  "userAccount": "Y3ZidWNrZXQ",
  "password": "dc06698f0e2e75751545455899adccc3",
  "description": "API test",
  "security": {
    "owner": {
      "user": {
        "id": 0,
        "name": ""
      },
      "userGroup": {
        "id": 0,
        "name": ""
      }
    },
    "associations":
      {
        "user": {
          "id": 0,
          "name": ""
        },
        "userGroup": {
          "id": 0,
          "name": ""
        },
        "permissions": {
          "permissionId": 0,
          "permissionName": "",
          "categoryId": 0,
          "categoryName": "",
          "type": "ALL_CATEGORIES",
          "exclude": True
        },
        "isCreatorAssociation": True
      }
    ]
  }
})
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'Authtoken': 'QSDK ******'
}

response = requests.request("POST", url, headers=headers, data=payload,  verify=False)

print(response.text)

hello @Gaurav Shrivastava 
i hope you are doing well ! 
 

This error means the CV server is not receiving the payload correctly.

Could you please check if the JSON payload matches the structure in the documentation?
 

I also recommend using a testing tool like postmaan to determine the issue in your code or with the API endpoint itself.

Best Regards,
Mohamed Ramadan
Data Protection Specialist


Below are the fields required to create a cloud account credential. you can try with below.

import requests
import json

url = "https://commvault.newblr.com/commandcenter/api/V4/Credential"

payload = json.dumps({

  "accountType": "CLOUD_ACCOUNT",
  "vendorType": "HITACHI_VANTARA_HCP_CLOUD_SCALE_S3",
  "name": "XXXX",
  "accessKeyId": "XXXX",
  "secretAccessKey": "XXXX", //must be in base64 encoded format 
  "description": "XXXX"

})
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'Authtoken': 'QSDK XXXX'
}

response = requests.request("POST", url, headers=headers, data=payload,verify=False)

print(response.text)

 

 

 


Reply