Author

Topic: REST API HELP (Read 746 times)

hero member
Activity: 686
Merit: 500
vini, vedi, no vici.
August 10, 2016, 06: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!
staff
Activity: 3458
Merit: 6793
Just writing some code
August 08, 2016, 08:12:02 AM
#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);
hero member
Activity: 686
Merit: 500
vini, vedi, no vici.
August 08, 2016, 04: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.
staff
Activity: 3458
Merit: 6793
Just writing some code
August 05, 2016, 12: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.
hero member
Activity: 686
Merit: 500
vini, vedi, no vici.
August 05, 2016, 12:09:37 PM
#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:
	$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

Jump to: