awx 3 api credeetntials post

Hello, I am trying to post new ssh credentials with python but it returns the list ov credentials and not creates the new credential:

def add_ssh_credentials(self, uri, token, name, description, organization, team, tipo, user, key):
“”"add ssh credential
Parameters:

  • uri: awx api uri of the credentials
  • token: awx token

Returns:

True/False and hosts dict or message error

Raise: :class:Myerror
“”"
heady= {‘Authorization’: 'Bearer '+token}
payload = {
“organization”: organization,
“credential_type”: tipo,
“team”: team,
“description”: description,
“name”: name,
“inputs”: {
“became_method”: “sudo”,
“username”: user,
“ssh_key_data”: key,
“api_token”: “secret”
},
}

res = requests.post(uri, data=json.dumps(payload), headers={‘content-type’: ‘application/json’}, auth=(self.user, self.password))
output=res.json()

Anyone can help me ?
Regards
Ignazio

Ignazio,

Does the response status give any clues?

it returns all credentials like using get instead post,
No error are returned.
The post returns a dictionary with all credentials I created using web interface.

I am using the following uri:

http://awxaddress/api/v2/credentials

I am not a python expert, but I would like to know where I can get logs.

I tried the same with web interface and with tower-cli and both work fine

Thanks
Ignazio

PS
The response is 200

I discovered the uri must finish with / and organization field is required.
Now it works.
I have only a problem: the ssh_key_data field must be a serialized private key o the file name containing the private key ?
Regards
Ignazio

ssh_key_data is raw SSH private key data. AWX encrypts this data before it’s stored in the database: https://docs.ansible.com/ansible-tower/latest/html/userguide/credentials.html#understanding-how-credentials-work

Many thanks