Skip to content

Commit 80b3306

Browse files
authored
Merge pull request #725 from watson-developer-cloud/transaction-id
Add documentation for getting transaction id
2 parents e0e5f83 + bdfd2c3 commit 80b3306

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

.env.enc

48 Bytes
Binary file not shown.

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Python client library to quickly get started with the various [Watson APIs][wdc]
3131
* [Setting the service url](#setting-the-service-url)
3232
* [Sending request headers](#sending-request-headers)
3333
* [Parsing HTTP response information](#parsing-http-response-information)
34+
* [Getting the transaction ID](#getting-the-transaction-id)
3435
* [Using Websockets](#using-websockets)
3536
* [Cloud Pak for Data(CP4D)](#cloud-pak-for-data)
3637
* [Logging](#logging)
@@ -362,6 +363,30 @@ This would give an output of `DetailedResponse` having the structure:
362363
```
363364
You can use the `get_result()`, `get_headers()` and get_status_code() to return the result, headers and status code respectively.
364365

366+
## Getting the transaction ID
367+
Every SDK call returns a response with a transaction ID in the x-global-transaction-id header. This transaction ID is useful for troubleshooting and accessing relevant logs from your service instance.
368+
### Suceess
369+
```python
370+
from ibm_watson import MyService
371+
372+
service = MyService(authenticator=my_authenticator)
373+
response_headers = service.my_service_call().get_headers()
374+
print(response_headers.get('x-global-transaction-id'))
375+
```
376+
377+
### Failure
378+
```python
379+
from ibm_watson import MyService, ApiException
380+
381+
try:
382+
service = MyService(authenticator=my_authenticators)
383+
service.my_service_call()
384+
except ApiException as e:
385+
print(e.global_transaction_id)
386+
# OR
387+
print(e.http_response.headers.get('x-global-transaction-id'))
388+
```
389+
365390
## Using Websockets
366391
The Text to Speech service supports synthesizing text to spoken audio using web sockets with the `synthesize_using_websocket`. The Speech to Text service supports recognizing speech to text using web sockets with the `recognize_using_websocket`. These methods need a custom callback class to listen to events. Below is an example of `synthesize_using_websocket`. Note: The service accepts one request per connection.
367392

examples/personality_insights_v3.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
../resources/personality-v3-expect2.txt
44
"""
55
import json
6-
from os.path import join, dirname
6+
import os
7+
from os.path import join
78
from ibm_watson import PersonalityInsightsV3
89
import csv
910
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
1011

11-
# Authentication via IAM
12+
# # Authentication via IAM
1213
# authenticator = IAMAuthenticator('your_api_key')
1314
# service = PersonalityInsightsV3(
1415
# version='2017-10-13',
@@ -17,7 +18,7 @@
1718

1819
# Authentication via external config like VCAP_SERVICES
1920
service = PersonalityInsightsV3(version='2017-10-13')
20-
service.set_service_url('https://gateway.watsonplatform.net/personality-insights/api')
21+
service.set_service_url('https://api.us-east.personality-insights.watson.cloud.ibm.com/instances/4c18b521-3abd-4c7c-bec7-6a3fd03644f1')
2122

2223
############################
2324
# Profile with JSON output #

0 commit comments

Comments
 (0)