Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SimonAngatia's avatar

How do you handle an API that sends data to a callback URL using various methods

I have an API that sends data to the callback URL using various methods. For example: getPlayerBalance method comes with data like this: {"Login":"username","OperatorId":"1","Session":"465663"} while getPlayerBalances method comes with data like this: {"d":{"Data":[{"Balance":100.0000,"Login":" username1"},{"Balance":200,"Login":" username2"}],"ErrorCode":0,"HasErrors":false,"Message":""}} Now the question is how do I know the method sending data so that I can handle the data differently?

0 likes
16 replies
laracoft's avatar

getPlayerBalance and getPlayerBalances are part of your callback URLs correct?

The data structure is usually found in the API docs.

You can route them to different methods of your handler class.

Route::post("/getPlayerBalance", [your_handler_class::class, "getPlayerBalance"]);
Route::post("/getPlayerBalances", [your_handler_class::class, "getPlayerBalances"]);
laracoft's avatar

Do this Route::post("/api/response/{slug?}", [your_handler_class::class, "handler"]);

Create a class your_handler_class with a method called handler($slug = "").

I'm sure getPlayerBalance and getPlayerBalances are returned as part of the response. Perhaps it is /api/response/getPlayerBalance and /api/response/getPlayerBalances?

What does the API documents say?

laracoft's avatar

We need the part that explains how to call these "web services", I do not see anything about callback URLs. Both are very different.

  1. webservices = your PHP code uses file_get_contents to call them
  2. callback URL = their server file_get_contents your URLs to pass you information
SimonAngatia's avatar

The documentation doesn't talk about callback URL anywhere

laracoft's avatar

Then where did the idea of callback URL in your opening post come from?

SimonAngatia's avatar

It comes because they told me to send them a callback URL

laracoft's avatar

Callback is a very specific and unique term meaning they load your URL. I think we might be confusing 2 different issues.

Since your objective appears to be calling web services and not handling callbacks, I suggest you refer to earlier answers regarding using file_get_contents() and also figure out which URL you have to call (which is probably somewhere in the docs).

SimonAngatia's avatar

In this case, they are the ones sending data to us. For example when a player wins or losses, they send the debit or credit data that we ought to process and return data to them to update the player's account information

laracoft's avatar

Do they have any documentation on callbacks? The docs you have right now pertain to webservices.

It could also be that, they callback your URL as a general notification and then you call their web services to retrieve the data.

SimonAngatia's avatar
  1. Player place a bet/s on any XPG live game
  2. XPG sends Debit API call
  3. Operator processes Debit API call and will reply to XPG within 3sec.
  4. Operator waits for Credit API call to see if player did Win or Lost [“Lost” Credit API calls will contain “Amount=0”]

This is part of instruction on how it works, please...

laracoft's avatar
laracoft
Best Answer
Level 27

They want you to implement an API service according to the way it is specified in the docs.

You have to write code like this as well as the class your_handler_class and methods getPlayerBalance/getPlayerBalances etc

Route::post("/getPlayerBalance", [your_handler_class::class, "getPlayerBalance"]);
Route::post("/getPlayerBalances", [your_handler_class::class, "getPlayerBalances"]);

Your getPlayerBalance() must also respond according to the doc with data like {"Login":"username","OperatorId":"1","Session":"465663"}

Please or to participate in this conversation.