Well i found a solution with the users query :
const axiosInstanceForNativeAPI = axios.create({ baseURL: ENDPOINT_URL, headers: { Authorization: ADMIN_TOKEN_FOR_NATIVE_API }, }); export const getUserByEmail = email => axiosInstanceForNativeAPI.get(`/users?searchBy=email&query=${email}`); export const getUserByUsername = username => axiosInstanceForNativeAPI.get(`/users?searchBy=username&query=${username}`);Unsolved Cannot authenticate API with PHP cURL
-
I'm trying to make use of the NodeBB API on a PHP page, but cannot seem to get authentication using a bearer token working.
This is my code so far
$url = '<forums>/api/user/email/<email>'; $headers = ['Authorization: Bearer <token>']; $post = ['_uid' => '0']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post)); $response = curl_exec($ch); $data = json_decode($response, true); curl_close($ch); print_r($data);
-
Have you tried curl from the command line?
-
@pitaj Yes I have, doesn't appear to work either.
-
@zxh share the curl command you used please.
-
/usr/bin/curl -H 'Authorization: Bearer <token>' --data _uid=0 <forums>/api/user/email/<email>
-
@zxh and what response do you get?
-
{"path":"/user/email/<email>","title":"[[global:404.title]]","bodyClass":"page-user page-user-email page-user-<email> page-status-404 user-guest"}
-
@julian mind taking a look?
-
@Pitaj sure
@zxh the
/api/user/email/:email
API call is aGET
route, not aPOST
route.e.g. https://community.nodebb.org/api/user/email/[email protected]ebb.org