# awx 3 api  credeetntials post

**URL:** <https://forum.ansible.com/t/awx-3-api-credeetntials-post/29995>\
**Category:** AWX Project\
**Tags:** awx\
**Created:** [March 27, 2019, 10:02am UTC](https://forum.ansible.com/t/awx-3-api-credeetntials-post/29995 "2019-03-27T10:02:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ignazio\_Cassano](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@Ignazio\_Cassano](https://forum.ansible.com/u/Ignazio_Cassano)\
**Post date:** [March 27, 2019, 10:02am UTC](https://forum.ansible.com/t/awx-3-api-credeetntials-post/29995/1 "2019-03-27T10:02:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rpetrell](https://avatars.discourse-cdn.com/v4/letter/r/b4bc9f/32.png) [@rpetrell](https://forum.ansible.com/u/rpetrell)\
**Post date:** [March 27, 2019, 1:36pm UTC](https://forum.ansible.com/t/awx-3-api-credeetntials-post/29995/2 "2019-03-27T13:36:29Z")

</div>

Ignazio,

Does the response status give any clues?

---

<div class="post-metadata">

**Author:** ![Ignazio\_Cassano](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@Ignazio\_Cassano](https://forum.ansible.com/u/Ignazio_Cassano)\
**Post date:** [March 27, 2019, 2:10pm UTC](https://forum.ansible.com/t/awx-3-api-credeetntials-post/29995/3 "2019-03-27T14:10:59Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Ignazio\_Cassano](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@Ignazio\_Cassano](https://forum.ansible.com/u/Ignazio_Cassano)\
**Post date:** [March 27, 2019, 2:12pm UTC](https://forum.ansible.com/t/awx-3-api-credeetntials-post/29995/4 "2019-03-27T14:12:56Z")

</div>

PS  
The response is 200

---

<div class="post-metadata">

**Author:** ![Ignazio\_Cassano](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@Ignazio\_Cassano](https://forum.ansible.com/u/Ignazio_Cassano)\
**Post date:** [March 27, 2019, 2:50pm UTC](https://forum.ansible.com/t/awx-3-api-credeetntials-post/29995/5 "2019-03-27T14:50:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rpetrell](https://avatars.discourse-cdn.com/v4/letter/r/b4bc9f/32.png) [@rpetrell](https://forum.ansible.com/u/rpetrell)\
**Post date:** [March 27, 2019, 2:58pm UTC](https://forum.ansible.com/t/awx-3-api-credeetntials-post/29995/6 "2019-03-27T14:58:18Z")

</div>

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](https://docs.ansible.com/ansible-tower/latest/html/userguide/credentials.html#understanding-how-credentials-work)

---

<div class="post-metadata">

**Author:** ![Ignazio\_Cassano](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@Ignazio\_Cassano](https://forum.ansible.com/u/Ignazio_Cassano)\
**Post date:** [March 27, 2019, 3:03pm UTC](https://forum.ansible.com/t/awx-3-api-credeetntials-post/29995/7 "2019-03-27T15:03:17Z")

</div>

Many thanks
