I'm trying to do a GET request to the XBMC api in PHP, but i cant get it to work. I already have a valid url, thats working when i simulate a GET request with a REST client.
http://localhost:8085/jsonrpc?request={"jsonrpc": "2.0", "id": 1, "method": "Input.ExecuteAction", "params": {"action":"left"}}
I get a parse error from xbmc when i simulate a POST:
{
"error": {
"code": -32700,
"message": "Parse error."
},
"id": null,
"jsonrpc": "2.0"
}
This is the code i currently have:
<?php
$jsonString = "{\"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"Input.ExecuteAction\", \"params\": {\"action\":\"left\"}}";
$url = "http://localhost:8085/jsonrpc?request=".$jsonString;
get($url);
function get($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 7);
$result = curl_exec($ch);
print $result;
curl_close($ch);
}
But this wont do the job, just like when i simulate a POST request a parse error is returned.
So my thoughts are that i'm doing a POST request, am i?
If no, what would be the problem then?
I just ran into the same problem.
You need to encode the url you are using for XBMC (Kodi nowadays). So in your case:
$jsonString
should be replaced by
urlencode($jsonString)
Related
So I am trying to display info from a website onto my website via an API using curl.
And I am not to clued up on curl at all :(
So this is what I have to from the source website :
curl -H "IHOSTMN-API-KEY:YourIhostmnApiKeyHere" -X GET "https://ihostmn.com/api/v1/sharing/user/list_all_deposits"
And it should give this response:
{
"result": {
"deposits": [
{
"deposit_id": 36,
"share_id": 2,
"current_amount": 53.077553,
"total_deposited": 24.91567,
"total_earned": 28.146885,
"withdraw_address": "GcUgnY5fFwTv9ef8rsggdxbdQzLEUxpp4c",
"deposit_address": "GfUgnY5sFwTf9ez8rovtdxdEQzLcbxpb4c"
},
{
"deposit_id": 37,
"share_id": 5,
"current_amount": 885.9591,
"total_deposited": 521.92,
"total_earned": 472.30566,
"withdraw_address": "gHWHPs21H8UsSNcbfWxvn5XssAxFkcuZYe",
"deposit_address": "g4sbWWtD3tf16Dsd8wiaJkar3zhJ82qNKP"
},
{
"deposit_id": 38,
"share_id": 6,
"current_amount": 754.5115,
"total_deposited": 548.52997,
"total_earned": 416.25214,
"withdraw_address": "LLqWFFJkNSog6VwsbPWEWE4KcXJrzB6t1K",
"deposit_address": "LW5Vbt1gEkvVQzfVcpLmidLPpcED1Yp3yu"
}
]
},
"error": ""
}
I have created my php webpage but can't make it work, this is what wrote:
curl -H "IHOSTMN-API-KEY:xxxxxxxxxxxxxxxxxxxxxxxxx" -X GET "https://ihostmn.com/api/v1/sharing/user/list_all_deposits"
$obj = json_decode($result);
echo $obj[0]->deposits;
Hopefully one of you will be able to point me in the correct direction, and thank you for taking the time to help if you can.
Mark
Try something like this
<?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://ihostmn.com/api/v1/sharing/user/list_all_deposits');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$headers = array();
$headers[] = 'Ihostmn-Api-Key: YourIhostmnApiKeyHere';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
$obj = json_decode($result);
print_r($obj->result->deposits);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
you use [] for arrays and arrows for objects.
I cannot test the API but this should give you a headstart.
Helpful links: cURL
I have this URL as a GET
https://api-gametroove.eeposit.com/auth/gameland_subscription_status/
Need to send it like this
https://api-gametroove.eeposit.com/auth/gameland_subscription_status/270830000000
with 270830000000 being the mobile number.
The response is supposed to be
{
"success": true,
"message": "Subscription status checked successfully.",
"params": {
"subscriptStatus": true
}
}
I am using the following code, but don't get any response back.
function subscriber($msisdn){
$URL = "https://api-gametroove.eeposit.com/auth/gameland_subscription_status/".$msisdn;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output=curl_exec($ch);
curl_close($ch);
echo $output;
}
subscriber('2773000000');
If I do above nothing is returned. How can I check if any errors or should I use another
method to do the GET for thsi URL?
I'm sending a JSON request in PHP and i get a response from the server, that looks like this:
{"success":true,"result":
{"items":
[{"woj":"łódzkie","powiat":"kutnowski","gmina":"Bedlno","kod":"99-
311","miasto":"Adamów","id":"99-311Adamów167271172700"}]},
"error":null,
"unAuthorizedRequest":false}
I want to pick a content from "woj" and "powiat" but it doesn't work.
My code looks like this:
$code = 'https://hetman.e4b.com.pl/api/services/app/kodPoczt/KodPocztInfo?
kod='.$kod;
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $code);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//execute post
$result1 = curl_exec($ch);
//close connection
curl_close($ch);
echo $result1;
$wynik = json_decode($result1, true);
echo $wynik['result'][0]['woj'];
show your full code... curl isnt inited in your example and return_transfer isnt set. whats the output of $result1?
anyway its
$wynik['result']['items'][0]['woj'];
$temp = '{
"success": true,
"result": {
"items": [{
"woj": "łódzkie",
"powiat": "kutnowski",
"gmina": "Bedlno",
"kod": "99-311",
"miasto": "Adamów",
"id": "99-311Adamów167271172700"
}]
},
"error": null,
"unAuthorizedRequest": false
}';
$result = json_decode($temp,true);
echo $result['result']['items'][0]['woj'];
I'm trying to get a range query to work with PHP cURL and Cloudant.
I've setup the following search index in my Cloudant:
{
"_id": "_design/date",
"_rev": "20-822ebda694f4fb57dc0a48bf60f6570f",
"views": {},
"language": "javascript",
"indexes": {
"by_date": {
"analyzer": "classic",
"index": "function (doc) {\n index(\"default\", doc.datequery);\n}"
}
}
}
And then in my PHP document I do the following:
$urlstuff = "[20180110 TO 20180119]";
$url = "https://user:pass.#user.cloudant.com/db/_design/date/_search/by_date?q=".$urlstuff."&include_docs=true&limit=200";
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
And I get Bad Request.
If I replace:
$urlstuff = "[20180110 TO 20180119]";
for
$urlstuff = "20180117";
Then I get good results.
Is it the square brackets messing with my cURL?
What am I missing?
Yes, you are on the right track. If you escape your variable (e.g. using http://php.net/manual/en/function.curl-escape.php?) your query should work:
curl -g -X GET 'https://user:password#user-bluemix.cloudant.com/db/_design/date/_search/by_date?q=[20180110 TO 20180119]&include_docs=true&limit=20'
{"error":"bad_request","reason":"Bad request"}
vs
curl -X GET 'https://user:password#user-bluemix.cloudant.com/db/_design/date/_search/by_date?q=%5B20180110%20TO%2020180119%5D&include_docs=true&limit=20'
{"total_rows":1, ...
I have configured Authorize.net, accept hosted payment method for my client requirement, where everything is happening fine, except Transaction reponse. As per Authorize.net, response comes only either of these ways, webhooks or CommunicatorUrl. CommunicatorUrl not working for my code. so, opted for webhooks. Below is my code. please, suggest me something.
My doubts are:
My Code displaying this error when calling list of available webhooks
{
"status": 405,
"reason": "Method Not Allowed",
"message": "The requested resource does not support http method 'POST' for given parameters.",
"correlationId": "ff90ee25-0ba7-4006-bb1e-225ea64897e3"
}
Should i configure webhook anywhere in my Merchant Panel
How would i get my transaction response using webhook
<?php
$login_transKey = 'xxx:xxx'; //Login and Transaction Key of Authorize.net
$jsonObj = '{
"name": "Get WebHooks",
"request": {
"url": "http://localhost:81/hosted_payment_form/webhookstwo.php",
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"description": ""
},
{
"key": "Authorization",
"value": "'.$login_transKey.'",
"description": ""
}
],
"body": {
"mode": "formdata",
"formdata": []
},
"description": ""
},
"response": []
}';
$jsonObj = json_encode($jsonObj);
$url = "https://apitest.authorize.net/rest/v1/eventtypes";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonObj);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
$content = curl_exec($ch);
echo '<pre>'; print_r($content); die();
curl_close($ch);
?>
Please, Let me know for more information.
You need to specify the webhook URL in authorize.net account.
Also you need to select the events in the settings page.
Please make sure that the Web-hook URL always return HTTP 200 response.
Otherwise it will be automatically changed to Inactive status.