API poor response: Bad Request

Trying to make a call to the Figma API, nodes endpoint, from c++ in Unreal Engine.

void AMyTest::SendRequest(){

	FString APIKey = "XXXXXXXXXX"; 
	FString FILEKey = "YYYYYYYYY"; 
	FString URL = "https://api.figma.com/v1/files/" + FILEKey + "/nodes?ids=202:595"; 
   
	FHttpRequestRef reqRef = FHttpModule::Get().CreateRequest();
	reqRef->SetURL(URL);
	reqRef->SetVerb("GET");
	reqRef->SetHeader(TEXT("X-FIGMA-TOKEN"), APIKey);

    // line commented out but not working even including it
	//reqRef->AppendToHeader(TEXT("User-Agent"), TEXT("X-UnrealEngine-Agent"));
	
	reqRef->OnProcessRequestComplete().BindUObject(this, &AMyActor::OnResponseReceived);
	reqRef->ProcessRequest();
}

With this, and after having made various variations of this script, the only that the Figma API keeps responding is “Bad request”.

Could anyone help pointing out what it is going in here.

What does the response body contain?

that is all i can get

<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
</body>
</html>

I’m not familiar with Unreal, but you can play around with curl or Postman or any http client of your choice to try out different request settings. For example:

curl "https://api.figma.com/v1/files/yourFileKey/nodes?ids=100:100" -H "X-FIGMA-TOKEN: yourToken"

should work just fine.

I’m not sure how FStrings and TEXT() work, but I’d try hard-coding the url and api key without any variables or string concat to make sure you’re constructing the request correctly.

Thanks for your answer, I have already tested:

curl request works
postman request works
python request works
jasvascript request works

it is only the c++ request from unreal that seems to not be working for some reason

During my many attempts I have tried also hard-coding the key and it is not working.

That is why I am saying the response from the API is so poor…it should provide more info to be able to debug further

Hey.
I have the same problem. I tried diffent rest api and It works, but api.figma responses Bad Request.

@James_Yang @Vadim_Pechenkin1 Looks like Unreal’s FCurlHttpRequest sends “Content-Length: 0” which is not very common and this thing freaks out the Figma API, I tried to skip that part in the debugger and got the response successfully!

// Source\Runtime\Online\HTTP\Private\Curl\CurlHttp.cpp:791 (FCurlHttpRequest::SetupRequest)
// content-length should be present http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4
if (GetHeader(TEXT("Content-Length")).IsEmpty())
{
	SetHeader(TEXT("Content-Length"), FString::Printf(TEXT("%d"), RequestPayload->GetContentLength()));
}

So, any chance that Figma API starts ignoring Content-Length: 0 on GET requests? Since it should be fine to send that by W3C spec.

We looked into this and it is not possible to ignore Content-Length: 0 headers on GET requests. This behavior comes as part of a bundle of checks for HTTP desync mitigation in our application load balancer, and we cannot selectively disable individual checks.

So the recommendation going forward is to apply the workaround above, or to remove the Content-Length header from the request.