Adam_Kaluza
January 17 |
Can someone provide how the upload of the file should look like? I can find any example in the web.
Visit Topic to respond.
Adam_Kaluza
January 16 |
Hello,
I try to create a flow from exported Architect flow yaml file. I'm using
POST /api/v2/flows/jobs endpoint to create a job and get a URL for upload YAML file. Response for upload is always 200 but when I try to check the status I always get.
{
"id": "d9726edf-820b-4fec-b190-b5bb9412b62c",
"status": "Failure",
"command": "Publish",
"selfUri": "/api/v2/flows/jobs/d9726edf-820b-4fec-b190-b5bb9412b62c"
}
What's strange is that when I try to do this request in postman, it passes and create a flow.... The biggest problem is that I didn't get any fail reason even with query ?expand=messages. Do you guys know what's can be problem? Here are my two solutions which I try to implement in java. One for sending a file and other one to only a content.
I need this feature to create architect flow by API for creating an app foundry app.
@org.springframework.beans.factory.annotation.Value("classpath:/Test_v3-0.yaml")
private Resource yamlResource;
public void uploadFlowToGenesys() {
try {
RegisterArchitectJobResponse registerArchitectJobResponse = genesys.architectApi().postFlowsJobs();
String presignedUrl = registerArchitectJobResponse.getPresignedUrl();
Map<String, String> headers = registerArchitectJobResponse.getHeaders();
URI uri = new URI(presignedUrl);
ResponseEntity<Object> response = sendPutRequest(uri, headers);
if (response.getStatusCode().is2xxSuccessful()) {
System.out.println("File uploaded successfully");
} else {
System.err.println("File upload failed. Status code: " + response.getStatusCode());
System.err.println("Response body: " + response.getBody());
}
} catch (IOException | URISyntaxException e) {
throw new RuntimeException("Failed to upload the YAML file", e);
} catch (ApiException e) {
throw new RuntimeException("Failed to communicate with Genesys API", e);
}
}
private ResponseEntity<Object> sendPutRequest(URI baseUrl, Map<String, String> headers) throws IOException {
RestTemplate restTemplate = new RestTemplate();
File yamlFile = yamlResource.getFile();
Resource resource = new org.springframework.core.io.FileSystemResource(yamlFile);
System.out.println("Uploading file: " + yamlFile.getName());
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.forEach(httpHeaders::set);
HttpEntity<Resource> requestEntity = new HttpEntity<>(resource, httpHeaders);
return restTemplate.exchange(baseUrl, HttpMethod.PUT, requestEntity, Object.class);
}
public void uploadFlowToGenesys() {
try {
RegisterArchitectJobResponse registerArchitectJobResponse = genesys.architectApi().postFlowsJobs();
String presignedUrl = registerArchitectJobResponse.getPresignedUrl();
Map<String, String> headers = registerArchitectJobResponse.getHeaders();
URI uri = new URI(presignedUrl);
ResponseEntity<Object> response = sendPutRequest(uri, headers);
if (response.getStatusCode().is2xxSuccessful()) {
System.out.println("File uploaded successfully");
} else {
System.err.println("File upload failed. Status code: " + response.getStatusCode());
System.err.println("Response body: " + response.getBody());
}
} catch (IOException | URISyntaxException e) {
throw new RuntimeException("Failed to upload the YAML file", e);
} catch (ApiException e) {
throw new RuntimeException("Failed to communicate with Genesys API", e);
}
}
private ResponseEntity<Object> sendPutRequest(URI baseUrl, Map<String, String> headers) throws IOException {
RestTemplate restTemplate = new RestTemplate();
File yamlFile = yamlResource.getFile();
String fileContent = Files.readString(yamlFile.toPath(), StandardCharsets.UTF_8);
System.out.println("File content to upload:");
System.out.println(fileContent);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
headers.forEach(httpHeaders::set);
HttpEntity<String> requestEntity = new HttpEntity<>(fileContent, httpHeaders);
return restTemplate.exchange(baseUrl, HttpMethod.PUT, requestEntity, Object.class);
}
Visit Topic to respond.
You are receiving this because you enabled mailing list mode.
To unsubscribe from these emails, click here.