Issue with Badges API?

Hello all,
Is there an issue with assigning badges API, all of a sudden one of my client’s sites cannot award badges to members when previously they could?

It’s able to call the API and run the backend code but returns with (according to Site Monitoring)

Error: Unable to handle the request, contact site administrator
[Status Code: 400, Message: {"message":"Bad Request","details":{}}"]

The coding on the website is as follows:

////////// Page Code \\\\\\\

import wixData from 'wix-data';
import wixUsers from 'wix-users';
import wixWindow from 'wix-window';

import { assignMembers } from 'backend/badgesaward'

$w.onReady(function () {
 
});

export function button110_click(event) {
 let count = $w('#input1').value
    console.log(count)
 if(count === '15'){
 let user = wixUsers.currentUser
 let userid = user.id

 let badgeId = '5ee20740-cdde-4145-a6e6-4f90b56499b6'
 let memberIds = userid

    assignMembers(badgeId, memberIds)

let toInsert = {
 "title" : 'Become A Ghostbuster',
 "badge":   badgeId,
 "user":    memberIds
};

wixData.insert("userbadges", toInsert)
.then( (results) => {
    $w('#dataset1').setFieldValue('completionPercentage', 100)
    $w('#dataset1').save()
    }) 
    }
}

////////// Backend Code \\\\\\\

import {badges} from 'wix-users-backend';

export function assignMembers(badgeId, memberIds) {
 return badges.assignMembers(badgeId, memberIds);
}

As mentioned before this was working previously with no issue, but suddenly since I got the Corvid Interface change it suddenly has stopped working.

If I need to raise a ticket with support please do let me know.

Thanks
Chris

#corvidbug #BadgesAPI

Please post the URL of your site?

https:/www.flyhighstories.co.uk

Also just tried it on a fresh new site on standard editor and same issue again

Are you still having this issue?

Hi Yisrael,
Sorry for the delay in getting back to you. No it’s still casing issues.

I’m having a similar issue

Unhandled rejection Error: server responded with - {"message":"","details":{}} (500)    

And now, the same issue

Unhandled rejection Error: Status code: 400, message: {"message":"Bad Request","details":{}}

Hi Yisrael, I’m having this same issue at moment.

Please, post the URL of your site as well

Hi Vika,

Hi @viktoriian , should I create a support ticket?

Hey everybody…

Any clue about that?

Chris, you should note that a call to a web modules (backend function) returns a Promise and it should be handled in the front end code:

Something like this:

assignMembers(badgeId, memberIds).then( function(memberIds) {
    console.log(memberIds);
});

Renato, are you calling your web module the same way or are you handling the Promise? Please share your code and post your site URL so we can investigate.

Hi Yisrael, just tried that again the same error message came up. I have also tried as a test to set default ID’s from the backend end as below, and it is still producing the same message.

/// Backend Code \\

import {badges} from 'wix-users-backend';

export function assignMembers() {
 let badgeId = 'ad4e8fb9-b1ad-43ed-8b83-6fab96ed3a55'
 let memberIds = 'f51b05c6-c080-494b-97ac-804992d59edb'
 return badges.assignMembers(badgeId, memberIds);
}

I have got support who have just advanced it as they could recreate the issue: Ticket ID: 1966440638. I think the issue is originating from the Wix Side as I can’t assign a badge on this site or any other site that I create at the moment.

I have followed both my existing code for site that had it working before and also the WIX Corvid Badge Api as per the reference documentation and both cases are not working either.

Thanks for all the help so far Yisrael!

Thanks
Chris

@chrisg-silvester I agree, it sounds like it is on the Wix side.

However, keep in mind that when calling web modules you need to handle the returned Promise.

Hi Yisrael,

I’m calling from the backend, http functions actually.

My dao.jsw
-----------------
import {badges} from 'wix-users-backend';

export function atualizarSelo(plano, userId) {
 
 let badgeId = "9e118ba3xxxxxxxxx-71203295bb2a";
 switch (plano.toLowerCase()) {
 case "pro":
        {
            badgeId = "6b8714axxxxxxxxxxxx1723b9517d";
 break;
        }
 case "plus":
        {
            badgeId = "f35b66xxxxxxxxxxxf7bbb0ca96";
 break;
        }
    }
    console.log(badgeId);
    console.log(userId);
 return badges.assignMembers(badgeId, userId );

@renatoamueller I understand. But in order to call atualizarSelo() from the frontend, you need to make sure that you handle the Promise, something like this:

atualizarSelo(plano, userId).then( function(memberIds) {
    console.log(memberIds);
});

And, actually not http functions. The wix-http-functions API is for exposing a site API, and you currently not using that API.

@renatoamueller A web module function always returns a Promise, even if you call it from the backend. That means that calling it from a function in your http functions file, you will need to handle the Promise.

You really shouldn’t be calling a web module function from the backend. Web module functions are meant to be called from the front end only.

@yisrael-wix

Ok, I decide to join all code on http-function.

function atualizarSelo(plano, userId) {
 
 let badgeId = "9e118ba3-671203295bb2a";
 switch (plano.toLowerCase()) {
 case "pro":
        {
            badgeId = "6b8714a0d1723b9517d";
 break;
        }
 case "plus":
        {
            badgeId = "f35b66bdf7bbb0ca96";
 break;
        }
    }
    console.log(badgeId);
    console.log(userId);
 return badges.assignMembers(badgeId, userId )
            .then( function(memberIds) {
                        console.log(memberIds);
            }).catch((error)=>{
                console.log(error);    
            });
 
 }
 
 

                atualizarSelo(plano, userId)
                .then( function(memberIds) {
                        console.log(memberIds);
                    });

and i still get da same error