Was trying to use httpie to post multiple events using the http://open.sen.se/ API. This accepts an array of unnamed objects in the form of:
[
{
"feed_id": 12345,
"value": "foo"
},
{
"feed_id":23456,
"value": 2134
},
...
]
Found that I could not seem to make httpie create JSON like this. Attempting to use the :=
separator for raw JSON without a key name created this output:
[victor@klamm ~]$ http -p B api.sen.se/events/ :='[{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}]'
{
"": [
{
"feed_id": 24571,
"value": 64.0
},
{
"feed_id": 24572,
"value": 60.0
}
]
}
@chuma, this you can do by passing the raw JSON in via STDIN
. For example:
echo '[{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}]' | http api.sen.se/events/
@jakubroztocil good job! you solve my problem
@jakubroztocil, I am using the http 0.9.2 and it seens that it doesn't work that anymore.
I've created a test.php with the code:
<?php
print_r($_REQUEST);
Then i tried the requests below:
echo '[{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}]' | http http://localhost/CRMvTiger_Rodobens/test.php
Return:
Array
(
)
echo '[{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}]' | http --form http://localhost/CRMvTiger_Rodobens/test.php
Return:
Array
(
)
echo '[{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}]' | http --json http://localhost/CRMvTiger_Rodobens/test.php
Return:
Array
(
)
echo '{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}' | http http://localhost/CRMvTiger_Rodobens/test.php
Return:
Array
(
)
echo '{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}' | http --json http://localhost/CRMvTiger_Rodobens/test.php
Return:
Array
(
)
echo '{"feed_id": 24571, "value": 64.0}, {"feed_id":24572, "value":60.0}' | http --form http://localhost/CRMvTiger_Rodobens/test.php
Return:
Array
(
[{"feed_id":_24571,_"value":_64_0},_{"feed_id":24572,_"value":60_0}
] =>
)
The only which return something is the last one, but not was i was expecting, it returned all json as a key with an empty value.
Most helpful comment
@chuma, this you can do by passing the raw JSON in via
STDIN
. For example: