Skip to main content
Question

Create Credential API call fails

  • October 21, 2024
  • 3 replies
  • 49 views

Forum|alt.badge.img+1

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)

Mohamed Ramadan
Forum|alt.badge.img+11

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


Forum|alt.badge.img+2

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)

 

 

 


Forum|alt.badge.img+1

Hi All

Thanks for your suggestions. I made API call by commenting few non-mandatory fields. 

   
    payload = json.dumps({
        "accountType": "CLOUD_ACCOUNT",
        "vendorType": "HITACHI_VANTARA_HCP_S3",
        "name": credentialName,
        "userAccount": namespaceUser,
        "password": namespacePassword_base64,
        "description": "API Integration",
        "security": {
            "owner": {
               # "user": {
               #     "id": 0,
               #     "name": ""
               # }
            }
        }
    })


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings