Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Capitão Jack Posted March 12 Posted March 12 Hello Team, I'm trying to send a POST request through the endpoint using axios, so that I can update the member's group. Flow for the code below: I call the function updateMemberGroup, which uses the function searchMember to get the member's id, and then I try to update the member's group on the endpoint api/core/members/${id}, as shown in the documentation: https://invisioncommunity.com/developers/rest-api?endpoint=core/members/POSTitem Please find below my code for that: async function searchMember(email) { const url = communityUrl + 'api/core/members'; let id = axios.get(url + `?email=${email}`, { headers: { 'Content-Type': 'application/json', 'User-Agent': 'MyUserAgent/1.0', 'Authorization': `Basic ${Buffer.from(apiKey + ':').toString('base64')}`, }, }) .then(response => { let id = response.data.results[0].id return id }) .catch(error => { console.error(error); return null }); return id } async function updateMemberGroup(email) { let id = await searchMember(email); if (!id) { console.log("Member not found"); return; } console.log(`Updating status for member with email ${email}`); console.log(`User ID: ${id}`); const url = communityUrl + `api/core/members/${id}`; let data = { "group": 9 // "Not paying" member }; let resp = await axios.post(url, data, { headers: { 'Content-Type': 'application/json', 'User-Agent': 'MyUserAgent/1.0', 'Authorization': `Basic ${Buffer.from(apiKey + ':').toString('base64')}`, }, }) .then(response => { console.log(`Updated Successfully ${email}`); return response.data; }) .catch(error => { console.error(error); return "error"; }); return resp; } I don't run into any errors and tried several approaches, I get the 200 OK response in the API Logs, but the member is returning with the primaryGroup not changed (still as a member, and not the group I'm trying to assign): { "id": 284, "name": "Kaue Nogueira", "title": null, "timeZone": "America\/Sao_Paulo", "formattedName": "Kaue Nogueira", "primaryGroup": { "id": 3, "name": "Members", "formattedName": "Members" }, ... Further info: - Access for the POST request is given in the API Key. - I tried changing other parameters as test, without success as well, so I don't know if it's something with the POST request only on api/core/members/${id}(as I easily can add members through POST on api/core/members ) Can you please help me on understanding this?
Recommended Posts