Avatar

Get data from app kintone via API

Rika S Andriast

Dear All

i am new user of kintone, no i have app ABCD with field (field_A, サービス内容, 一般料金(ルピア)【一覧】)

now i want to display record of that filed on php file.

would you like to helpme, below is my code

--------

<?php

 

$query =$_POST['query'];
$subdomain = "abcd"; // subdomain
$token = "BNcxdSfZFa97779u29hW6qC8888";
$appId = "18"; // App ID of product app


$url="https://abcd.cybozu.com/k/v1/record.json?app=18&id=1";

$subdomain = "abcd"; // subdomain
// Set HTTP header to send to server
$options = array (
'http' => array (
'method' => 'GET',
'header' => "X-Cybozu-API-Token:". $token. "\r \n"
)
);
$buildQuery = http_build_query (array ("app" => $appId, "query" => $query), "", "&");
// create context
$context = stream_context_create ($options);
// Connect to server and get data
//$contents = file_get_contents ('https: //'.$subdomain.'.cybozu.com/k/v1/records.json?'.$buildQuery, FALSE, $context);
$contents = file_get_contents( 'https://'.$subdomain.'.cybozu.com/k/v1/records.json?'.htmlspecialchars_decode($buildQuery), FALSE, $context );

$data = json_decode ($contents, true);
echo json_encode ($data ["records"]);
echo $data;
?>

-------------

RS - Indonesian

 

Follow 2 followers
0

1 comment

Avatar
Sean Tachibana 0 votes
Hello Rika,

I am not too familiar with PHP but once I proceeded as is, the 1st parameter of file_get_contents URLs query part became null.
My guess is that the URL is not set up correctly and also, I was not sure what type of errors were coming up.
By executing the process below, you can obtain the value of the record.

-----
define("API_TOKEN", "*****");
define("SUB_DOMAIN", "****");
define("APP_NO", "100");
define("QUERY", "limit 1");

//set up an HTTP header transmitting a server
$options = array(
'http'=>array(
'method'=>'GET',
'header'=> "X-Cybozu-API-Token:". API_TOKEN ."\r\n"
)
);
//generate the context
$context = stream_context_create( $options );
//connected to the server receive data
$contents = file_get_contents( 'https://'. SUB_DOMAIN .'.cybozu.com/k/v1/records.json?app='. APP_NO .'&query='. urlencode(QUERY), FALSE, $context );

echo $contents;
-----

You can also process the PHP from the page below:


Please tell us know what type of errors you are getting and where it is happening so we can assist you further.
0
Comment actions Permalink