Hi everyone. I decided today to create a bug reporter that posts cards to Trello, since Trello is well known in the community. This could be a good way for you to record the bugs of the game if your game is in early stages and you playtest a lot.
So this is a tutorial to describe how to create such a bug reporter using HTTP requests in C++.
Note: This was created in UE 4.7.6
Trello
If you don’t know trello yet, check it out. It is basically a project management tool. You will need an account, create a board and create a list in that board before you start with this tutorial.
The trello api uses a lot of ID’s and keys, so first I will describe how to get all of them.
Request
Every api request for trello starts with: https://api.trello.com/1/
We will be filling in this request:
https://api.trello.com/1/cards?key=<yourkey>&token=<yourtoken>&name=My+new+card+name&desc=My+new+card+description&idList=<thelist>
Key
First you need to generate a key with your trello account by going to this page:
https://trello.com/app-key
Board
Get the id from the correct board by going here: https://trello.com/1/members/me/boards?fields=name
Token
To get writing access to the board you need to have a token. You can get one by using the call below. Don’t forget to replace substitutewithyourapplicationkey with your key.
After you have done that and you are logged in Trello you will get a notification which you have to accept. It goes to a page after that with the token.
List
Then you need to get the correct list to add the card to. Replace substitutewithyourboardid with your board id.
https://api.trello.com/1/boards/substitutewithyourboardid/lists
You will get all lists in that board. You have to get the id of the list you want to use.
Labels
You have to do the same thing as the list to get the id of the label you want
https://api.trello.com/1/boards/substitutewithyourboardid/labels
C++ Code
First add the HTTP module to your project build file with:
PublicDependencyModuleNames.AddRange(new string] { “HTTP” });
I added the function to the gamemode, but you can put it where you want it. Here is the header:
#pragma once
#include "GameFramework/GameMode.h"
#include "Http.h"
#include "TrelloProjectGameMode.generated.h"
UCLASS()
class TRELLOPROJECT_API ATrelloProjectGameMode : public AGameMode
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "Trello")
void ReportBug(FString Name, FString Description);
UFUNCTION(BlueprintImplementableEvent)
void ReportBugComplete(bool bWasSuccessful);
private:
void OnReportBugComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
};
And below is the source file. Add all the IDs you got to the strings at the top of the file.
#include "TrelloProject.h"
#include "TrelloProjectGameMode.h"
const FString TrelloCards = "https://api.trello.com/1/cards?";
const FString Key = "";
const FString Token = "";
const FString Label = "";
const FString List = "";
void ATrelloProjectGameMode::ReportBug(FString Name, FString Description)
{
TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
Request->SetVerb("POST");
//Replace all the spaces with +
Name.Replace(L" ", L"+");
Description.Replace(L" ", L"+");
//Construct the http url
FString URL = TrelloCards +
"key=" + Key +
"&token=" + Token +
"&name=" + Name +
"&desc=" + Description +
"&idLabels=" + Label +
"&idList=" + List;
Request->SetURL(URL);
//Call OnReportBugComplete once the request is done
Request->OnProcessRequestComplete().BindUObject(this, &ATrelloProjectGameMode::OnReportBugComplete);
//Do the request
Request->ProcessRequest();
}
void ATrelloProjectGameMode::OnReportBugComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
//Go to blueprints
ReportBugComplete(bWasSuccessful);
}
I put this together really fast so, I am not going to explain the blueprints/UMG. So you can check that out in the download. I would love to hear if you have any questions!!!
You can download the project here.
Later