I'm trying to do a super simple fetch to grab some user data for my WP site. This URL works 100% in Postman and I get everything I need. However, in the browser and script, the response is ALWAYS an empty array.
Here's my script:
fetch(url, {
method: "GET",
headers: {
"authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjIsIm5hbWUiOiJsemFrb29yIiwiaWF0IjoxNjYzMTA5MzU2LCJleHAiOjE4MjA3ODkzNTZ9.2l957IqslJBsvY9MrV5dT0ykod7kloFCc5qSxGeGlT0",
"cache-control": "no-cache",
'Content-Type': 'application/json;charset=UTF-8'
}
})
// Handle success
.then(response => response.json()) // convert to json
.then(json => console.log(json)) //print data to console
.catch(err => console.log('Request Failed', err)); // Catch errors
I'm not sure what I'm doing wrong. I've tried almost everything I can think of. Postman gives me the proper JSON response every time.
The URL is this: /wp-json/wp/v2/users/ Raw:
{"id":668,"name":"008LT","url":"","description":"","link":"author\/008lt\/","slug":"008lt","avatar_urls":{"24":"wp-content\/plugins\/buddyboss-platform\/bp-core\/images\/profile-avatar-buddyboss-50.png","48":"wp-content\/plugins\/buddyboss-platform\/bp-core\/images\/profile-avatar-buddyboss-50.png","96":"wp-content\/plugins\/buddyboss-platform\/bp-core\/images\/profile-avatar-buddyboss-50.png"},"meta":{"project_code":[null],"hours_approved":[],"hours_used":[]},"acf":{"password_was_reset":"yes","acad_coordinator":"Mariah G.","project_poc":"Someone else","student_admin":"Test 1","admin_contact":"Someone","project_id":"11104.0028.001","hd_project_id_status":"","primary_language":"lithuanian (lit)","secondary_language":"russian (rus)","approved_hours":30,"used_hours":15,"todays_appointments":"","scheduled_instructor":"","training_focus":"","jlu":"","let_status":"","cl150_status":"","iltp":"","pmo_account-type":"","hd_account_status":"","tutor_orientation":"","class_activity":"","next_test":"","test_date":"","class_recording":"","last_updated":null,"student_category":"dlt","student-iltp":""},"_links":{"self":[{"href":"wp-json\/wp\/v2\/users\/668"}],"collection":[{"href":"wp-json\/wp\/v2\/users"}],"courses":[{"embeddable":true,"href":"wp-json\/ldlms\/v2\/users\/668\/courses"}],"groups":[{"embeddable":true,"href":"wp-json\/ldlms\/v2\/users\/668\/groups"}],"course-progress":[{"embeddable":true,"href":"wp-json\/ldlms\/v2\/users\/668\/course-progress"}],"quiz_progress":[{"embeddable":true,"href":"wp-json\/ldlms\/v2\/users\/668\/quiz-progress"},{"embeddable":true,"href":"wp-json\/ldlms\/v2\/groups\/668\/quiz-progress"},{"embeddable":true,"href":"wp-json\/ldlms\/v2\/groups\/668\/quiz-progress"}]}}
console.log
output, I'm interested in the raw network response that chrome/firefox receives before it's handed to JS. If you're using JS to output the value then that value is tainted. Looking at the request itself in the network panel bypasses any mistakes or missing steps and shows you the raw unprocessed network request. Also keep in mind that you've still not expanded your code snippet to include what came before it. This could be a trivial mistake creatingurl
.