Closed aaryan1 closed 3 years ago
it means you should create a session before performing this request, more there
Hi, While registering new user, I firstly call session api. Which return me token value in response. { session: { id: 19234790, user_id: 0, application_id: 3574, nonce: 787599541, token: "7a02225b540c7df2ece64b9d83142325c1000df6", ts: 1604403380, created_at: "2020-11-03T11:36:21Z", updated_at: "2020-11-03T11:36:21Z" } }
But when I try to pass this token value in headers for registration api. I got below mentione response. { errors: [ "Token is required" ] }
With which key did you put the token to the headed? 'CB-Token' like thete?
Like this - Here $token contains the value which I recieved from session api.
curl_setopt($ch, CURLOPT_HTTPHEADER, array ( 'Content-Type: application/json', "CB-Token: <".$token.">") );
there should be only token string without any special symbols, like
CB-Token: beefecd44c88effee4dc9dabb21ad760650001dc
Still got same response -
curl_setopt($ch, CURLOPT_HTTPHEADER, array ( 'Content-Type: application/json', "CB-Token: ".$token) ); Error Response - { errors: [ "Token is required" ] }
it means you are putting the token not correctly, please provide the complete request
Currently got below mentioned token value from session api -
$token - cf9bf2d746990c55eed6d0af9d9261311c000df6
Pass this value dynamically in registration api.
DEFINE('REG_CB_API_ENDPOINT', "https://api.connectycube.com"); DEFINE('REG_CB_PATH_SESSION', "users");
// Build post body $post_body1 = http_build_query(array( 'application_id' => APPLICATION_ID, 'auth_key' => AUTH_KEY, 'timestamp' => $ts, 'nonce' => $nonce1, 'signature' => $signature, 'user[login]' => USER_LOGIN, 'user[password]' => USER_PASSWORD, 'user[email]' => 'richa@gmail.com' ));
Curl Request - $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, REG_CB_API_ENDPOINT . '/' . REG_CB_PATH_SESSION); curl_setopt($curl, CURLOPT_POST, true); // Use POST curl_setopt($ch, CURLOPT_HTTPHEADER, array ( 'Content-Type: application/json', 'CB-Token: '.$token) ); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body1); // Setup post body curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Receive server response echo $response = curl_exec($curl); curl_close($curl);
are you sure, that field $token
not empty?
Yes, print that token value while executing script. I also tried by passing some random alpha numeric value. But got same response.
DEFINE('REG_CB_PATH_SESSION', "users");
do you use this part for creating a session?
For session creation, you should use session
instead of users
Sorry, but I'm not a PHP developer and I can be mistaken in your code)))
No, previously shared part is only for registartion. Below mentioned code is for session, from where I recieved token value in json.
Session - DEFINE('SESSION_CB_API_ENDPOINT', "https://api.connectycube.com"); DEFINE('SESSION_CB_PATH_SESSION', "session");
$nonce = rand(); $timestamp = time(); $signature_string = "application_id=".APPLICATION_ID."&auth_key=".AUTH_KEY."&nonce=".$nonce."×tamp=".$timestamp; $signature = hash_hmac('sha1', $signature_string , AUTH_SECRET);
// Build post body $post_body = http_build_query(array( 'application_id' => APPLICATION_ID, 'auth_key' => AUTH_KEY, 'timestamp' => $timestamp, 'nonce' => $nonce, 'signature' => $signature ));
$curl = curl_init(); curl_setopt($curl, CURLOPT_URL, SESSION_CB_API_ENDPOINT . '/' . SESSION_CB_PATH_SESSION); curl_setopt($curl, CURLOPT_POST, true); // Use POST curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body); // Setup post body curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Receive server response $responce = curl_exec($curl); curl_close($curl);
$resp = json_decode($responce);
$token = $resp->session->token;
$nonce1 = $resp->session->nonce;
$ts = $resp->session->ts;
Registration - DEFINE('REG_CB_API_ENDPOINT', "https://api.connectycube.com"); DEFINE('REG_CB_PATH_SESSION', "users");
// User credentials
DEFINE('USER_LOGIN', "test");
DEFINE('USER_PASSWORD', "12345");
// Generate signature
$nonce = rand();
$timestamp = time();
$signature_string = "application_id=".APPLICATION_ID."&auth_key=".AUTH_KEY."&nonce=".$nonce1."×tamp=".$ts."&user[login]=".USER_LOGIN."&user[password]=".USER_PASSWORD;
$signature = hash_hmac('sha1', $signature_string , AUTH_SECRET);
// Build post body
$post_body1 = http_build_query(array(
'application_id' => APPLICATION_ID,
'auth_key' => AUTH_KEY,
'timestamp' => $ts,
'nonce' => $nonce1,
'signature' => $signature,
'user[login]' => USER_LOGIN,
'user[password]' => USER_PASSWORD,
'user[email]' => 'richa@gmail.com'
));
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, REG_CB_API_ENDPOINT . '/' . REG_CB_PATH_SESSION);
curl_setopt($curl, CURLOPT_POST, true); // Use POST
curl_setopt($ch, CURLOPT_HTTPHEADER, array
(
'Content-Type: application/json',
'CB-Token: '.$token)
);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body1); // Setup post body
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Receive server response
echo $responce1 = curl_exec($curl);
curl_close($curl);
for the second request will be enough this data only
'user[login]' => USER_LOGIN,
'user[password]' => USER_PASSWORD,
'user[email]' => 'richa@gmail.com'
other parameters are redundant
This thread re how to create a session in PHP might be helpful https://github.com/ConnectyCube/connectycube-reactnative-samples/issues/13
When I got token from below mentioned session api - https://api.connectycube.com/session Token - e38db313879bb3b427a4c45cfea942f944000df6
Then I pass this token in user sign up api via curl- https://api.connectycube.com/users
Then I got below mentioned response - { errors: [ "Token is required" ] }
Also tried to print curl response and got this -
| ( | [url] => https://api.connectycube.com/users | [content_type] => text/html; charset=utf-8 | [http_code] => 400 | [header_size] => 313 | [request_size] => 249 | [filetime] => -1 | [ssl_verify_result] => 0 | [redirect_count] => 0 | [total_time] => 0.858904 | [namelookup_time] => 0.00073 | [connect_time] => 0.211441 | [pretransfer_time] => 0.643958 | [size_upload] => 80 | [size_download] => 0 | [speed_download] => 0 | [speed_upload] => 93 | [download_content_length] => 0 | [upload_content_length] => 80 | [starttransfer_time] => 0.858877 | [redirect_time] => 0 | [redirect_url] => | [primary_ip] => 52.205.218.40 | [certinfo] => Array | ( | ) | | [primary_port] => 443 | [local_ip] => 139.59.67.0 | [local_port] => 52842 | )
No activity for a long time. Closing... If you still have the issue, please create a new one with details.
curl -X POST \ -H "Content-Type: application/json" \ -H "CB-Token:" \
-d '{"user": {"login": "Dacia", "password": "petU4or!", "email": "dacia_k@domain.com", "facebook_id": "91234409", "twitter_id": "83510562734", "full_name": "Dacia Kail ", "phone": "+6110797757"}}' \
https://api.connectycube.com/users
Note -not able to figure out from where I can get the value of "CB-Token:" .
I am getting "invalid token error" while accessing this Api.
getting this response.
{ errors: [ "Token is required" ] }