Reputation: 2652
I have this PHP webhook page that I am using for my sample smooch.io app, see below.
<?php
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if (!$update) {
// receive wrong update, must not happen
exit;
}
logf(json_encode($content));
/*curl https://api.smooch.io/v1/appusers/5790bff5237cbc5d00b10a17/conversation/messages \
-X POST \
-d '{"text":"Just put some vinegar on it", "role": "appMaker"}' \
-H 'content-type: application/json' \
-H 'authorization: Bearer your-jwt'
*/
$parameters["text"] = "Reply from the webhook!";
$parameters["role"] = "appMaker";
$handle = curl_init("https://api.smooch.io/v1/appusers/5790bff5237cbc5d00b10a17/conversation/messages");
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($handle, CURLOPT_TIMEOUT, 60);
curl_setopt($handle, CURLOPT_POSTFIELDS, json_encode($parameters));
curl_setopt($handle, CURLOPT_HTTPHEADER,
array("Content-Type: application/json; charset=utf-8","Authorization: Bearer ".MY_JWT)
);
$response = curl_exec($handle);
logf("response: ".$response);
$response = json_decode($response, true);
function logf($str){
$logf = "smooch.txt";
$dtnow = date("dmy H:i:s");
$logfh = fopen($logf, 'a');
$str = $dtnow." - ".$str."\n";
fputs($logfh, $str);
fclose($logfh);
}
I am getting the following error in my logged response
response: {"error":{"code":"user_not_found","description":"User not found"}}
I have verified my signature here https://jwt.io/ using the credentials given from smooch.io
I suspect it's this {smoochId|userId} value? I just copied these random characters (5790bff5237cbc5d00b10a17) from my browser's URL, I am assuming this is my userID. Please advise how can I get my smoochID or userID. Thanks!
Upvotes: 0
Views: 459
Reputation: 8141
5790bff5237cbc5d00b10a17 is your app id, not your user's id. To get a user id you have to initialize one first:
http://docs.smooch.io/rest/#init
Upvotes: 2