# Sending JSON through URI module

**URL:** <https://forum.ansible.com/t/sending-json-through-uri-module/31807>\
**Category:** Ansible Project\
**Created:** [December 11, 2019, 7:28pm UTC](https://forum.ansible.com/t/sending-json-through-uri-module/31807 "2019-12-11T19:28:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Junaid\_Farooq](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Junaid\_Farooq](https://forum.ansible.com/u/Junaid_Farooq)\
**Post date:** [December 11, 2019, 7:28pm UTC](https://forum.ansible.com/t/sending-json-through-uri-module/31807/1 "2019-12-11T19:28:42Z")

</div>

I am doing this task

`

- name: Register evercam-media local commit hash  
local\_action:  
shell  
chdir={{local\_media\_dir}}  
git log --pretty=‘{“sha”:“%h”, “author\_name”:“%an”, “author\_name”:“%ae”, “unix\_timestamp”:“%at”, “subject”:“%s”, “branch”:“%d”}’ | head -1  
register: local\_commit\_info

- set\_fact:  
commit: “{{ local\_commit\_info.stdout }}”

`

which creates such as

`  
changed: [[media.evercam.io](http://media.evercam.io) → localhost] =\> {  
“changed”: true,  
“cmd”: “git log --pretty=‘{"sha":"%h", "author\_name":"%an", "author\_name":"%ae", "unix\_timestamp":"%at", "subject":"%s", "branch":"%d"}’ | head -1”,  
“delta”: “0:00:00.005962”,  
“end”: “2019-12-11 19:24:54.788804”,  
“invocation”: {  
“module\_args”: {  
“\_raw\_params”: “git log --pretty=‘{"sha":"%h", "author\_name":"%an", "author\_name":"%ae", "unix\_timestamp":"%at", "subject":"%s", "branch":"%d"}’ | head -1”,  
“\_uses\_shell”: true,  
“argv”: null,  
“chdir”: “/home/junaid/evercam/evercam-server”,  
“creates”: null,  
“executable”: null,  
“removes”: null,  
“stdin”: null,  
“stdin\_add\_newline”: true,  
“strip\_empty\_ends”: true,  
“warn”: true  
}  
},  
“rc”: 0,  
“start”: “2019-12-11 19:24:54.782842”,  
“stderr”: “”,  
“stderr\_lines”: ,  
“stdout”: “{"sha":"aca4ef2", "author\_name":"Junaid Farooq", "author\_name":"junaid@evercam.io", "unix\_timestamp":"1576042588", "subject":"Merge pull request #1240 from evercam/delete\_timelapse", "branch":" (HEAD → master, origin/master, origin/HEAD)"}”,  
“stdout\_lines”: [  
“{"sha":"aca4ef2", "author\_name":"Junaid Farooq", "author\_name":"junaid@evercam.io", "unix\_timestamp":"1576042588", "subject":"Merge pull request #1240 from evercam/delete\_timelapse", "branch":" (HEAD → master, origin/master, origin/HEAD)"}”  
]  
}  
Read vars\_file ‘common-vars.yml’  
Read vars\_file ‘media-vars.yml’  
Read vars\_file ‘…/private\_vars\_media.yml’

TASK [media : set\_fact] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/junaid/evercam/evercam-devops/ansible/media/tasks/hotcode.yml:8  
ok: [[media.evercam.io](http://media.evercam.io)] =\> {  
“ansible\_facts”: {  
“commit”: {  
“author\_name”: “[junaid@evercam.io](mailto:junaid@evercam.io)”,  
“branch”: " (HEAD → master, origin/master, origin/HEAD)",  
“sha”: “aca4ef2”,  
“subject”: “Merge pull request #1240 from evercam/delete\_timelapse”,  
“unix\_timestamp”: “1576042588”  
}  
},  
“changed”: false  
}  
`  
All I want to do is to send the commit to a URL as a post request.

I am doing this way

`

- uri:  
url: “[http://www.myapi.com/create](http://www.myapi.com/create)”  
method: POST  
return\_content: yes  
body\_format: json  
HEADER\_Content-Type: “application/json”  
body: “{{ commit }}”  
`

But I am getting error such as

`  
fatal: [[media.evercam.io](http://media.evercam.io)]: FAILED! =\> {  
“changed”: false,  
“invocation”: {  
“module\_args”: {  
“HEADER\_Content-Type”: “application/json”,  
“body”: {  
“author\_name”: “[junaid@evercam.io](mailto:junaid@evercam.io)”,  
“branch”: " (HEAD → master, origin/master, origin/HEAD)",  
“sha”: “aca4ef2”,  
“subject”: “Merge pull request #1240 from evercam/delete\_timelapse”,  
“unix\_timestamp”: “1576042588”  
},  
“body\_format”: “json”,  
“method”: “POST”,  
“return\_content”: true,  
“url”: “[http://www.myapi.com/create](http://www.myapi.com/create)”  
}  
},  
“msg”: “Unsupported parameters for (uri) module: HEADER\_Content-Type Supported parameters include: attributes, backup, body, body\_format, client\_cert, client\_key, content, creates, delimiter, dest, directory\_mode, follow, follow\_redirects, force, force\_basic\_auth, group, headers, http\_agent, method, mode, owner, regexp, remote\_src, removes, return\_content, selevel, serole, setype, seuser, src, status\_code, timeout, unix\_socket, unsafe\_writes, url, url\_password, url\_username, use\_proxy, validate\_certs”  
}

`

Can you point where I am wrong? I also tried Just using curl which didn’t work as well?

---

<div class="post-metadata">

**Author:** ![Junaid\_Farooq](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@Junaid\_Farooq](https://forum.ansible.com/u/Junaid_Farooq)\
**Post date:** [December 11, 2019, 7:52pm UTC](https://forum.ansible.com/t/sending-json-through-uri-module/31807/2 "2019-12-11T19:52:13Z")

</div>

I have removed headers but now I am getting this error

`  
fatal: [[media.evercam.io](http://media.evercam.io)]: FAILED! =\> {  
“changed”: false,  
“content”: “”,  
“elapsed”: 0,  
“invocation”: {  
“module\_args”: {  
“attributes”: null,  
“backup”: null,  
“body”: {  
“commit”: {  
“author\_name”: “[junaid@evercam.io](mailto:junaid@evercam.io)”,  
“branch”: " (HEAD → master, origin/master, origin/HEAD)",  
“sha”: “aca4ef2”,  
“subject”: “Merge pull request #1240 from evercam/delete\_timelapse”,  
“unix\_timestamp”: “1576042588”  
}  
},  
“body\_format”: “json”,  
“client\_cert”: null,  
“client\_key”: null,  
“content”: null,  
“creates”: null,  
“delimiter”: null,  
“dest”: null,  
“directory\_mode”: null,  
“follow”: false,  
“follow\_redirects”: “safe”,  
“force”: false,  
“force\_basic\_auth”: false,  
“group”: null,  
“headers”: {  
“Content-Type”: “application/json”  
},  
“http\_agent”: “ansible-httpget”,  
“method”: “POST”,  
“mode”: null,  
“owner”: null,  
“regexp”: null,  
“remote\_src”: null,  
“removes”: null,  
“return\_content”: true,  
“selevel”: null,  
“serole”: null,  
“setype”: null,  
“seuser”: null,  
“src”: null,  
“status\_code”: [  
200  
],  
“timeout”: 30,  
“unix\_socket”: null,  
“unsafe\_writes”: null,  
“url”: “[http://127.0.0.1:3000/v1/server/deployed](http://127.0.0.1:3000/v1/server/deployed)”,  
“url\_password”: null,  
“url\_username”: null,  
“use\_proxy”: true,  
“validate\_certs”: true  
}  
},  
“msg”: “Status code was -1 and not [200]: Request failed: \<urlopen error [Errno 111] Connection refused\>”,  
“redirected”: false,  
“status”: -1,  
“url”: “[http://127.0.0.1:3000/v1/server/deployed](http://127.0.0.1:3000/v1/server/deployed)”  
}

`

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [December 12, 2019, 1:23am UTC](https://forum.ansible.com/t/sending-json-through-uri-module/31807/3 "2019-12-12T01:23:30Z")

</div>

Hi Junaid,

You can convert stdout to json using `jq` binary and `from_json` filter like -

tasks:

- name: local  
local\_action:  
shell  
chdir=/Volumes/data/src/ansible/  
git log --pretty=‘[“%h”, “%an”, “%ae”, “%ad”, “%s”]’ | head -1 | jq  
register: local\_commit\_info

- set\_fact:  
m: “{{ local\_commit\_info.stdout | from\_json }}”

- debug:  
msg: “{{ m[1] }}”

You can `m` directly in your next call.
