Skip to main content
Question

API poor response: Bad Request


Pedro8

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.

This topic has been closed for replies.

8 replies

James_Yang
Figmate
  • Figmate
  • 82 replies
  • July 17, 2023

What does the response body contain?


Pedro8
  • Author
  • 9 replies
  • July 18, 2023

that is all i can get

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

James_Yang
Figmate
  • Figmate
  • 82 replies
  • July 18, 2023

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.


Pedro8
  • Author
  • 9 replies
  • July 18, 2023

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.


NeilAkhmetovCR

@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()));
}

NeilAkhmetovCR

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.


James_Yang
Figmate
  • Figmate
  • 82 replies
  • September 6, 2023

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.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings