question

Dylan Hunt avatar image
Dylan Hunt asked

Err 400 for redeemcoupon with JS SDK

https://api.playfab.com/Documentation/Client/method/RedeemCoupon

Hmm, why is this a bad request? I should have received an err 1016 coupon not found, but instead got an actual POST err.

Any guesses?

var req =
{
    "CouponCode": "123-1234-123",
    "CatalogVersion": "Game"
};

PlayFabClientSDK.RedeemCoupon(req, onPfRedeemCoupon);

function onPfRedeemCoupon(response)
{
    alert( 'yay - at least a caught err if this far );
}

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

·
brendan avatar image
brendan answered

Is that call being made with the Unity SDK or the C# SDK? Can you try using the RedeemCouponRequest object for the call? Also, can you add an errorCallback function and capture the errorDetails, so that we can see what it says?

3 comments
10 |1200

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

Dylan Hunt avatar image Dylan Hunt commented ·

I don't think I can do that for JS with web -- I'm doing my website before i put PF in my game, since we're unreleased.

I actually had it working with Ajax, but not with the SDK. I've been converting all my code to SDK since it's 100x easier and easier to read.

0 Likes 0 ·
brendan avatar image brendan Dylan Hunt commented ·

Ah, JavaScript, I see. Sorry, wasn't looking at the title of the thread. You should still be getting the errorDetails back. Can you have a look, to see what the more descriptive text states about the error?

1 Like 1 ·
Dylan Hunt avatar image Dylan Hunt brendan commented ·

Ahh the errors are literally header errors (or whatever they're called - before a response), not a caught err. I got it now:

*{ "readyState": 4, "responseText": "{\"code\":400,\"status\":\"BadRequest\",\"error\":\"CouponCodeNotFound\",\"errorCode\":1016,\"errorMessage\":\"Coupon code not found\"}", "responseJSON": { "code": 400, "status": "BadRequest", "error": "CouponCodeNotFound", "errorCode": 1016, "errorMessage": "Coupon code not found" }, "status": 400, "statusText": "Bad Request" }

This is the correct response I was looking for -- just in the wrong place ;)

0 Likes 0 ·

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.