You are not logged in.
Boa noite pessoal,
Preciso de uma ajuda para selecionar/capturar o ID do usuário através de uma API.
O mais próximo que eu cheguei vou descrever logo abaixo como estou fazendo.
ENDPOINT USADO - http.../apirest.php/User/?range=3-4 **Para retornar só 2 usuários e não toda a lista.
RETORNO:
[
{
"id": 5,
"name": "normal",
"password_last_update": null,
"phone": null,
"phone2": null,
"mobile": null,
"realname": null,
"firstname": null,
"locations_id": 0,
"language": null,
"use_mode": 0,
"list_limit": null,
"is_active": 0,
"comment": null,
"auths_id": 0,
"authtype": 1,
"last_login": "2020-09-28 21:45:50",
"date_mod": "2020-10-18 15:15:52",
"date_sync": null,
"is_deleted": 0,
"profiles_id": 0,
"entities_id": 0,
"usertitles_id": 0,
"usercategories_id": 0,
"date_format": null,
"number_format": null,
"names_format": null,
"csv_delimiter": null,
"is_ids_visible": null,
"use_flat_dropdowntree": null,
"show_jobs_at_login": null,
"priority_1": null,
"priority_2": null,
"priority_3": null,
"priority_4": null,
"priority_5": null,
"priority_6": null,
"followup_private": null,
"task_private": null,
"default_requesttypes_id": null,
"password_forget_token": null,
"password_forget_token_date": null,
"user_dn": null,
"registration_number": null,
"show_count_on_tabs": null,
"refresh_views": null,
"set_default_tech": null,
"personal_token_date": null,
"api_token_date": null,
"cookie_token_date": null,
"display_count_on_home": null,
"notification_to_myself": null,
"duedateok_color": null,
"duedatewarning_color": null,
"duedatecritical_color": null,
"duedatewarning_less": null,
"duedatecritical_less": null,
"duedatewarning_unit": null,
"duedatecritical_unit": null,
"display_options": null,
"is_deleted_ldap": 0,
"pdffont": null,
"picture": null,
"begin_date": null,
"end_date": null,
"keep_devices_when_purging_item": null,
"privatebookmarkorder": null,
"backcreated": null,
"task_state": null,
"layout": null,
"palette": null,
"set_default_requester": null,
"lock_autolock_mode": null,
"lock_directunlock_notification": null,
"date_creation": null,
"highcontrast_css": null,
"plannings": null,
"sync_field": null,
"groups_id": 0,
"users_id_supervisor": 0,
"timezone": null,
"default_dashboard_central": null,
"default_dashboard_assets": null,
"default_dashboard_helpdesk": null,
"default_dashboard_mini_ticket": null,
"links": [
{
"rel": "Entity",
"href": "http..../apirest.php/Entity/0"
},
{
"rel": "Document_Item",
"href": "http..../apirest.php/User/5/Document_Item/"
}
]
},
{
"id": 6,
"name": "marcio.santos",
"password_last_update": null,
"phone": "",
"phone2": "xxxxxxxx",
"mobile": "xxxxxxxxx",
"realname": "xxxxxxxxx",
"firstname": "xxxxxxxxx",
"locations_id": 178,
"language": null,
"use_mode": 0,
"list_limit": 50,
"is_active": 0,
"comment": " | 512",
"auths_id": 0,
"authtype": 3,
"last_login": "2022-04-08 12:48:00",
"date_mod": "2022-10-07 16:16:34",
"date_sync": "2022-04-08 12:48:00",
"is_deleted": 0,
"profiles_id": 4,
"entities_id": 4,
"usertitles_id": 1,
"usercategories_id": 0,
"date_format": null,
"number_format": null,
"names_format": null,
"csv_delimiter": null,
"is_ids_visible": null,
"use_flat_dropdowntree": null,
"show_jobs_at_login": null,
"priority_1": null,
"priority_2": null,
"priority_3": null,
"priority_4": null,
"priority_5": null,
"priority_6": null,
"followup_private": 1,
"task_private": null,
"default_requesttypes_id": null,
"password_forget_token": null,
"password_forget_token_date": null,
"user_dn": "CN=Marcio Santos,OU=Usuarios O365,OU=Usuários,OU=Colaborador Exceções,OU=Tecnologia da Informação,OU=6 - DIRETORIA ADMINISTRATIVA E FINANCEIRA,OU=XXXXXXXX,OU=PB,OU=BR,OU=IBQ,DC=IBQ,DC=local",
"registration_number": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"show_count_on_tabs": null,
"refresh_views": null,
"set_default_tech": 0,
"personal_token_date": "2020-06-05 02:36:48",
"api_token_date": null,
"cookie_token_date": "2020-09-14 18:28:38",
"display_count_on_home": null,
"notification_to_myself": null,
"duedateok_color": null,
"duedatewarning_color": null,
"duedatecritical_color": null,
"duedatewarning_less": null,
"duedatecritical_less": null,
"duedatewarning_unit": null,
"duedatecritical_unit": null,
"display_options": null,
"is_deleted_ldap": 0,
"pdffont": null,
"picture": null,
"begin_date": null,
"end_date": null,
"keep_devices_when_purging_item": null,
"privatebookmarkorder": "[77,13,26,146]",
"backcreated": null,
"task_state": null,
"layout": null,
"palette": "dark",
"set_default_requester": null,
"lock_autolock_mode": null,
"lock_directunlock_notification": null,
"date_creation": "2020-05-25 21:06:04",
"highcontrast_css": null,
"plannings": "{\"filters\":{\"ChangeTask\":{\"color\":\"#E94A31\",\"display\":false,\"type\":\"event_filter\"},\"ProblemTask\":{\"color\":\"#5174F2\",\"display\":false,\"type\":\"event_filter\"},\"Reminder\":{\"color\":\"#51C9F2\",\"display\":false,\"type\":\"event_filter\"},\"TicketTask\":{\"color\":\"#FFCC29\",\"display\":false,\"type\":\"event_filter\"},\"ProjectTask\":{\"color\":\"#20C646\",\"display\":false,\"type\":\"event_filter\"}},\"plannings\":{\"user_6\":{\"color\":\"#FFEEC4\",\"display\":false,\"type\":\"user\"}}}",
"sync_field": "marcio.atanasio",
"groups_id": 0,
"users_id_supervisor": 380,
"timezone": null,
"default_dashboard_central": null,
"default_dashboard_assets": null,
"default_dashboard_helpdesk": null,
"default_dashboard_mini_ticket": null,
"links": [
{
"rel": "Location",
"href": "http..../apirest.php/Location/178"
},
{
"rel": "Profile",
"href": "http..../apirest.php/Profile/4"
},
{
"rel": "Entity",
"href": "http..../apirest.php/Entity/4"
},
{
"rel": "UserTitle",
"href": "http..../apirest.php/UserTitle/1"
},
{
"rel": "User",
"href": "http..../apirest.php/User/380"
},
{
"rel": "Document_Item",
"href": "http..../apirest.php/User/6/Document_Item/"
}
]
}
]
Abaixo estou tentando capturar/selecionar só o ID, porem esta retornando erro(Error: Expected ',' or '}' after property value in JSON at position 4405), devido o campo "plannings" que consta lista, já tentei remover o campo "plannings" do array mas não consegui ainda.
const json = '[ { "id": 5, "name": "normal", "password_last_update": null, "phone": null, "phone2": null, "mobile": null, "realname": null, "firstname": null, "locations_id": 0, "language": null, "use_mode": 0, "list_limit": null, "is_active": 0, "comment": null, "auths_id": 0, "authtype": 1, "last_login": "2020-09-28 21:45:50", "date_mod": "2020-10-18 15:15:52", "date_sync": null, "is_deleted": 0, "profiles_id": 0, "entities_id": 0, "usertitles_id": 0, "usercategories_id": 0, "date_format": null, "number_format": null, "names_format": null, "csv_delimiter": null, "is_ids_visible": null, "use_flat_dropdowntree": null, "show_jobs_at_login": null, "priority_1": null, "priority_2": null, "priority_3": null, "priority_4": null, "priority_5": null, "priority_6": null, "followup_private": null, "task_private": null, "default_requesttypes_id": null, "password_forget_token": null, "password_forget_token_date": null, "user_dn": null, "registration_number": null, "show_count_on_tabs": null, "refresh_views": null, "set_default_tech": null, "personal_token_date": null, "api_token_date": null, "cookie_token_date": null, "display_count_on_home": null, "notification_to_myself": null, "duedateok_color": null, "duedatewarning_color": null, "duedatecritical_color": null, "duedatewarning_less": null, "duedatecritical_less": null, "duedatewarning_unit": null, "duedatecritical_unit": null, "display_options": null, "is_deleted_ldap": 0, "pdffont": null, "picture": null, "begin_date": null, "end_date": null, "keep_devices_when_purging_item": null, "privatebookmarkorder": null, "backcreated": null, "task_state": null, "layout": null, "palette": null, "set_default_requester": null, "lock_autolock_mode": null, "lock_directunlock_notification": null, "date_creation": null, "highcontrast_css": null, "plannings": null, "sync_field": null, "groups_id": 0, "users_id_supervisor": 0, "timezone": null, "default_dashboard_central": null, "default_dashboard_assets": null, "default_dashboard_helpdesk": null, "default_dashboard_mini_ticket": null, "links": [ { "rel": "Entity", "href": "http..../apirest.php/Entity/0" }, { "rel": "Document_Item", "href": "http..../apirest.php/User/5/Document_Item/" } ] }, { "id": 6, "name": "marcio.santos", "password_last_update": null, "phone": "", "phone2": "xxxxxxxx", "mobile": "xxxxxxxxx", "realname": "xxxxxxxxx", "firstname": "xxxxxxxxx", "locations_id": 178, "language": null, "use_mode": 0, "list_limit": 50, "is_active": 0, "comment": " | 512", "auths_id": 0, "authtype": 3, "last_login": "2022-04-08 12:48:00", "date_mod": "2022-10-07 16:16:34", "date_sync": "2022-04-08 12:48:00", "is_deleted": 0, "profiles_id": 4, "entities_id": 4, "usertitles_id": 1, "usercategories_id": 0, "date_format": null, "number_format": null, "names_format": null, "csv_delimiter": null, "is_ids_visible": null, "use_flat_dropdowntree": null, "show_jobs_at_login": null, "priority_1": null, "priority_2": null, "priority_3": null, "priority_4": null, "priority_5": null, "priority_6": null, "followup_private": 1, "task_private": null, "default_requesttypes_id": null, "password_forget_token": null, "password_forget_token_date": null, "user_dn": "CN=Marcio Santos,OU=Usuarios O365,OU=Usuários,OU=Colaborador Exceções,OU=Tecnologia da Informação,OU=6 - DIRETORIA ADMINISTRATIVA E FINANCEIRA,OU=XXXXXXXX,OU=PB,OU=BR,OU=IBQ,DC=IBQ,DC=local", "registration_number": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "show_count_on_tabs": null, "refresh_views": null, "set_default_tech": 0, "personal_token_date": "2020-06-05 02:36:48", "api_token_date": null, "cookie_token_date": "2020-09-14 18:28:38", "display_count_on_home": null, "notification_to_myself": null, "duedateok_color": null, "duedatewarning_color": null, "duedatecritical_color": null, "duedatewarning_less": null, "duedatecritical_less": null, "duedatewarning_unit": null, "duedatecritical_unit": null, "display_options": null, "is_deleted_ldap": 0, "pdffont": null, "picture": null, "begin_date": null, "end_date": null, "keep_devices_when_purging_item": null, "privatebookmarkorder": "[77,13,26,146]", "backcreated": null, "task_state": null, "layout": null, "palette": "dark", "set_default_requester": null, "lock_autolock_mode": null, "lock_directunlock_notification": null, "date_creation": "2020-05-25 21:06:04", "highcontrast_css": null, "plannings": "{\"filters\":{\"ChangeTask\":{\"color\":\"#E94A31\",\"display\":false,\"type\":\"event_filter\"},\"ProblemTask\":{\"color\":\"#5174F2\",\"display\":false,\"type\":\"event_filter\"},\"Reminder\":{\"color\":\"#51C9F2\",\"display\":false,\"type\":\"event_filter\"},\"TicketTask\":{\"color\":\"#FFCC29\",\"display\":false,\"type\":\"event_filter\"},\"ProjectTask\":{\"color\":\"#20C646\",\"display\":false,\"type\":\"event_filter\"}},\"plannings\":{\"user_6\":{\"color\":\"#FFEEC4\",\"display\":false,\"type\":\"user\"}}}", "sync_field": "marcio.atanasio", "groups_id": 0, "users_id_supervisor": 380, "timezone": null, "default_dashboard_central": null, "default_dashboard_assets": null, "default_dashboard_helpdesk": null, "default_dashboard_mini_ticket": null, "links": [ { "rel": "Location", "href": "http..../apirest.php/Location/178" }, { "rel": "Profile", "href": "http..../apirest.php/Profile/4" }, { "rel": "Entity", "href": "http..../apirest.php/Entity/4" }, { "rel": "UserTitle", "href": "http..../apirest.php/UserTitle/1" }, { "rel": "User", "href": "http..../apirest.php/User/380" }, { "rel": "Document_Item", "href": "http..../apirest.php/User/6/Document_Item/" } ] } ]';
const obj = JSON.parse(json);
console.log(obj.id);
Alguém consegue me ajudar ou sabe me informar uma outra maneira para capturar/selecionar o ID do usuário através do login(usuario)?
Offline