Bitcoin Forum
May 23, 2024, 10:09:13 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: REST API HELP  (Read 719 times)
BTCIndia (OP)
Hero Member
*****
Offline Offline

Activity: 686
Merit: 500

vini, vedi, no vici.


View Profile
August 05, 2016, 05:09:37 PM
Last edit: August 17, 2016, 03:50:28 PM by BTCIndia
 #1

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... Smiley


He's Nick Sazbo from Washington. I've my answer. Or Hal? :O
achow101
Staff
Legendary
*
Offline Offline

Activity: 3402
Merit: 6647


Just writing some code


View Profile WWW
August 05, 2016, 05:26:37 PM
 #2

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.

BTCIndia (OP)
Hero Member
*****
Offline Offline

Activity: 686
Merit: 500

vini, vedi, no vici.


View Profile
August 08, 2016, 09:04:46 AM
 #3

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.

He's Nick Sazbo from Washington. I've my answer. Or Hal? :O
achow101
Staff
Legendary
*
Offline Offline

Activity: 3402
Merit: 6647


Just writing some code


View Profile WWW
August 08, 2016, 01:12:02 PM
 #4

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);

BTCIndia (OP)
Hero Member
*****
Offline Offline

Activity: 686
Merit: 500

vini, vedi, no vici.


View Profile
August 10, 2016, 11:13:34 AM
 #5

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!

He's Nick Sazbo from Washington. I've my answer. Or Hal? :O
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!