Bitcoin Forum

Economy => Service Discussion => Topic started by: BTCIndia on August 05, 2016, 05:09:37 PM



Title: REST API HELP
Post by: BTCIndia on August 05, 2016, 05:09:37 PM
Dear All,
Im Trying to hit a Get Request from my https server
but it always Return NULL Please help,

https://tierion.com/docs/dataapi#api-create-datastore

Code:
<?php
$service_url 'https://api.tierion.com/v1/datastores';
   $curl curl_init($service_url);
   $curl_post_data = array(
        "X-Username" => 'EMAIL ADDRESS',
        "X-Api-Key" => 'API KEY',
        );
   curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
   curl_setopt($curlCURLOPT_POSTtrue);
   curl_setopt($curlCURLOPT_POSTFIELDS$curl_post_data);
   $curl_response curl_exec($curl);
   curl_close($curl);
   
   $decoded json_decode($curl_response);
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
    die('error occured: ' $decoded->response->errormessage);
}
echo 'response ok!';
var_export($decoded->response);

?>

Here is my potato in advance... :)
http://3.bp.blogspot.com/-k6mmw9BbX4E/VXtPzM22rgI/AAAAAAAAAp0/axlLjiF-QKI/s1600/potato.gif


Title: Re: Tierion REST API HELP
Post by: achow101 on August 05, 2016, 05:26:37 PM
Since it is a GET request, you don't need this line which is for post:
Code:
	   curl_setopt($curl, CURLOPT_POST, true);

Furthermore, you are authenticating incorrectly. The authentication stuff should be in the headers, not in the body of the request.
Instead of
Code:
	   $curl_post_data = array(
        "X-Username" => 'EMAIL ADDRESS',
        "X-Api-Key" => 'API KEY',
        );
   curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
you should have something like:
Code:
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        "X-Username" => 'EMAIL ADDRESS',
        "X-Api-Key" => 'API KEY',
        ));

Note, I don't have experience with Tierion's data api. I just read the documentation you linked to, I highly suggest that you give that a read and fully understand how the API works, and how HTTP Requests work.


Title: Re: Tierion REST API HELP
Post by: BTCIndia on August 08, 2016, 09:04:46 AM
Since it is a GET request, you don't need this line which is for post:
Code:
	   curl_setopt($curl, CURLOPT_POST, true);

Furthermore, you are authenticating incorrectly. The authentication stuff should be in the headers, not in the body of the request.
Instead of
Code:
	   $curl_post_data = array(
        "X-Username" => 'EMAIL ADDRESS',
        "X-Api-Key" => 'API KEY',
        );
   curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
you should have something like:
Code:
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        "X-Username" => 'EMAIL ADDRESS',
        "X-Api-Key" => 'API KEY',
        ));

Note, I don't have experience with Tierion's data api. I just read the documentation you linked to, I highly suggest that you give that a read and fully understand how the API works, and how HTTP Requests work.


This is first time, I'm working on API and its really painful. I'd really appreciate if you can write code to authenticate. I'm sure, I can write GET, POST command thereafter.


Title: Re: Tierion REST API HELP
Post by: achow101 on August 08, 2016, 01:12:02 PM
This is first time, I'm working on API and its really painful. I'd really appreciate if you can write code to authenticate. I'm sure, I can write GET, POST command thereafter.

The code is right there. Just look at my earlier post. The first two code blocks are the code that you should remove from your script. The last block is what you should add right after
Code:
$curl = curl_init($service_url);


Title: Re: Tierion REST API HELP
Post by: BTCIndia on August 10, 2016, 11:13:34 AM
This is first time, I'm working on API and its really painful. I'd really appreciate if you can write code to authenticate. I'm sure, I can write GET, POST command thereafter.

The code is right there. Just look at my earlier post. The first two code blocks are the code that you should remove from your script. The last block is what you should add right after
Code:
$curl = curl_init($service_url);

Thank you Knight!