question

Frank DiCola avatar image
Frank DiCola asked

Unexpected end of JSON input error

Does anyone know why this code to ban a single user is returning this error?

Error: invalid json response body at https://feaac.playfabapi.com/Group/BanUsers reason: Unexpected end of JSON input

Code:

 const body = {
                 Bans: [
                     {
                         PlayFabId: chariteerToUpdate.id,
                         Reason: "Bad behavior",
                     },
                 ],
             };
             console.log(JSON.stringify(body));


        
         const headers = {
             'Content-Type': 'application/json',
             'X-SecretKey': process.env.PLAYFAB_API_SECRET_KEY,
         };
    
         try {
             const response = await fetch(
                 `${process.env.PLAYFAB_API_HOST}/Group/BanUsers`,
                 {
                     method: 'POST',
                     headers,
                     body: JSON.stringify(body),
                 }
             );
             console.log("Request sent!");
             const data = await response.json();
             console.log(response.data);
             console.log(data);
        
             // Error handling
             if ( data.code == 400 )
             {
                 console.log("Problem detected");
             }
             else if ( data.code == 200 ) {
                 console.log("Player banned!");
             }
        
             } catch (error) {
             console.log("Errorz! " + error.message);
             console.log(error);
         }
Player Data
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Frank DiCola avatar image
Frank DiCola answered

Sorry, I accidentally got my URL wrong. I put Group, but I meant Admin. Solved!

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.