Solved Web API

baylf2000

Member
Plugin Developer
Messages
52
Points
8
I'm very interested in developing, if possible, some plugins that would utilise some external web apis. For example, I'd like to work on a plugin that calls a web api uri each time any player logs on or logs off a server, with the uri including some kind of player identification.

Is this something the Ark Server API would allow, and if so, might there be any kind of example code I could have a look at?

Thanks so much.
 
Advertisement

Official Game Server Partner

Michidu

Administrator
Staff member
Messages
640
Points
93
That's how you can make a request:
C++:
void RequestCallback(TSharedRef<IHttpRequest> request, bool success)
{
    //
}

void main()
{
    FString url = "url";
    FString verb = "GET";

    const bool result = ArkApi::Requests::Get().CreateRequest(url, verb, &RequestCallback);
}
 

baylf2000

Member
Plugin Developer
Messages
52
Points
8
Ok, that seems simple enough. And what would be the simplest way of triggering such code, for example, when any player logs on or off? Are there any of your plugins that do something like this that you might suggest I have a look at?

Many thanks again.
 

baylf2000

Member
Plugin Developer
Messages
52
Points
8
I've been able to use the ArkApi::Requests::Get().CreateRequest to set the url, verb, and content. Is there any way to modify the header?

Edit: Forgive me for my newb knowledge of c++ and your api, but from looking at the source of your api, it looks like you have fixed the "Content-Type" header to "text/html"? Am I correct? Or more likely totally wrong.

In order to use the POST method on most REST API's you need to set the "Content-Type" header to "application/json" and then include the data in JSON format in the body of the request.

I'm sure you already know all this and I'm just doing something completely wrong.

Thanks again for your help.
 
Last edited:

Michidu

Administrator
Staff member
Messages
640
Points
93
You are right, there is no way to edit Content-Type as of now. I will fix it.
For the player login/logout, hook "AShooterGameMode_HandleNewPlayer" and "AShooterGameMode_Logout".
 

baylf2000

Member
Plugin Developer
Messages
52
Points
8
OK thank you. In the mean time I can just modify your code slightly and recompile, but obviously I don't want to do that long term.

And thank you for the login/logout hook. That's extremely helpful.

Many thanks.
 
Top