Re: Server.callWithPost content type
Hello everyone,
I'm currently working on implementing a licensing system using Moonbase within HISE. One issue I recently faced regarding user sign-in was working with the callWithPOST function. As the Moonbase API requires me to pass text/plain instead of a json object, I can't get the sign-in to properly work. Is there any way to just pass a simple string via the callWithPOST function? anyone else, who faced a similar issue and found an workaround?
Moonbase Docs Sign-In: https://moonbase.sh/docs/licensing/api/#sign-in-a-customer
inline function makeHttpRequest(method, endpoint, data, callback)
{
// Set base URL
Server.setBaseURL(MOONBASE_API);
Server.setHttpHeader("Content-Type: text/plain");
currentHttpCallback = callback;
if (method == "POST") {
Server.callWithPOST(endpoint, data, function(status, response) {
if (status == Server.StatusOK) {
Console.print("LicenseManager: Request successful");
currentHttpCallback(true, response);
} else {
Console.print("LicenseManager: Request failed with status: " + status);
currentHttpCallback(false, {"error": "HTTP " + status});
}
});
} else {
Server.callWithGET(endpoint, data, function(status, response) {
if (status == Server.StatusOK) {
Console.print("LicenseManager: Request successful");
currentHttpCallback(true, response);
} else {
Console.print("LicenseManager: Request failed with status: " + status);
currentHttpCallback(false, {"error": "HTTP " + status});
}
});
}
}
/**
* Sign in customer to get access token
*/
inline function signInCustomer(email, password, callback)
{
// Store callback in global variable for nested function access
currentSignInCallback = callback;
// Make sign-in request
makeHttpRequest("POST", "/customer/identity/sign-in?email=" + email, password, function(success, response) {
if (success) {
Console.print("LicenseManager: Sign-in response received");
// Parse JSON response directly without storing in variable
if (isDefined(parseSimpleJSON(response).accessToken)) {
Console.print("LicenseManager: Access token received");
currentSignInCallback(true, parseSimpleJSON(response));
} else {
Console.print("LicenseManager: No access token in response");
currentSignInCallback(false, "No access token received");
}
} else {
Console.print("LicenseManager: Sign-in request failed");
currentSignInCallback(false, "Sign-in request failed");
}
});
}
@tobbentm any recommendation from your side on implementation? why cant we just pass json with the sign-in function? would have loved to use the JUCE module from you, but as you already pointed out, this is only compatible with JUCE 7.
Any help is greatly appreciated!