Export project via REST-API from Language Studio

87 Views Asked by At

I used the REST-API to export an QnA-Project with Postman. The result is a 202, so it should work. But the response body is empty. The documentation shows a link to a job. But I don't get that link. I used: URL: https://[HOST]/language/query-knowledgebases/projects/myproject/:export?api-version=2021-10-01&format=Excel

I set the Ocp-Apim-Subscription-Key in the header as an authetification. But the result is still empty.

Who had the same problem? Regards Andreas

1

There are 1 best solutions below

0
Venkatesan On

I set the Ocp-Apim-Subscription-Key in the header as an authentication. But the result is still empty. the result is a 202, so it should work.

If your response code of 202 indicates that the request has been approved and the export task has been started. It still does not mean that the export task has been finished. Before the export task is completed, the response body will remain blank.

You can use the code below and check the job's status using Python.

Code:

import requests

# Set the URL of the export endpoint
url = 'https://endpoint/language/query-knowledgebases/projects/projectname/:export?api-version=2021-10-01&format=Excel'

# Set the subscription key
subscription_key = 'your-subscription-key'

# Set the headers
headers = {
    'Ocp-Apim-Subscription-Key': subscription_key
}

# Send the export request
response = requests.post(url, headers=headers)
print(response.headers)

print(response.status_code)

status_url = response.headers['operation-location']

# Send a GET request to the export job status endpoint to get the status and link to the exported file
response = requests.get(status_url, headers=headers)

# Parse the response JSON to get the status and link to the exported file
response_json = response.json()
status = response_json['status']

print(status)
print(response_json)
print(response.url)

Output:

{'Content-Length': '0', 'operation-location': 'https://xxxxxx.cognitiveservices.azure.com:443/language/query-knowledgebases/projects/ashoksearch/export/jobs/baxxxxxx?api-version=2021-10-01', 'x-envoy-upstream-service-time': '29', 'apim-request-id': 'exxxxxxx1', 'Strict-Transport-Security': 'max-age=31xxx; includeSubDomains; preload', 'x-content-type-options': 'nosniff', 'x-ms-region': 'East US', 'Date': 'Thu, 17 Aug 2023 14:45:33 GMT'}
202
running
{'createdDateTime': '2023-08-17T14:45:33+00:00', 'expirationDateTime': '2023-08-17T20:45:33+00:00', 'jobId': 'ba3722xxxxxxx', 'lastUpdatedDateTime': '2023-08-17T14:45:34+00:00', 'status': 'running'}
https://xxxxx.cognitiveservices.azure.com:443/language/query-knowledgebases/projects/xxxxx/export/jobs/xxxxxx?api-version=2021-10-01
{
  "createdDateTime": "2023-08-17T14:45:33+00:00",
  "expirationDateTime": "2023-08-17T20:45:33+00:00",
  "jobId": "xxxxx",
  "lastUpdatedDateTime": "2023-08-17T14:45:34+00:00",
  "status": "running"
}

enter image description here

Reference:

Question Answering Projects - Export - REST API (Azure Cognitive Services) | Microsoft Learn