import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.Map;
@RestController
public class SessionController {
@PostMapping("/api/getSessionToken")
public Map<String, String> getSessionToken(@RequestBody Map<String, Object> requestBody) {
String importerSlug = (String) requestBody.get("importerSlug");
Map<String, Object> metadata = new HashMap<>();
metadata.put("user_id", 123);
RestTemplate restTemplate = new RestTemplate();
String url = "https://fuse.flatirons.com/api/v1/importer/sessions";
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer YOUR_API_TOKEN");
Map<String, Object> body = new HashMap<>();
body.put("importer_slug", importerSlug);
body.put("metadata", metadata);
HttpEntity<Map<String, Object>> entity = new HttpEntity<>(body, headers);
ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.POST, entity, Map.class);
if (response.getStatusCode().is2xxSuccessful()) {
Map<String, String> result = new HashMap<>();
result.put("token", (String) response.getBody().get("token"));
return result;
} else {
throw new RuntimeException("Failed to get session token");
}
}
}