Skip to content

Commit eef20a4

Browse files
committed
docs(readme): add transaction id documentation
1 parent 74e7919 commit eef20a4

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ Doing so will call your `onFailure()` implementation.
395395

396396
### Transaction IDs
397397

398-
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.
398+
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.
399399

400400
```java
401401
Assistant service = new Assistant("2019-02-28");
@@ -405,14 +405,28 @@ Response<WorkspaceCollection> response;
405405
try {
406406
// In a successful case, you can grab the ID with the following code.
407407
response = service.listWorkspaces(options).execute();
408-
String transactionId = response.getHeaders().values("x-global-transaction-id").get(0);
408+
String transactionId = response.getHeaders().values("X-Global-Transaction-Id").get(0);
409409
} catch (ServiceResponseException e) {
410410
// This is how you get the ID from a failed request.
411411
// Make sure to use the ServiceResponseException class or one of its subclasses!
412-
String transactionId = e.getHeaders().values("x-global-transaction-id").get(0);
412+
String transactionId = e.getHeaders().values("X-Global-Transaction-Id").get(0);
413413
}
414414
```
415415

416+
However, the transaction ID isn't available when the API doesn't return a response for some reason. In that case, you can set your own transaction ID in the request. For example, replace `<my-unique-transaction-id>` in the following example with a unique transaction ID.
417+
```java
418+
Authenticator authenticator = new IamAuthenticator("apiKey");
419+
service = new Assistant("{version-date}", authenticator);
420+
service.setServiceUrl("{serviceUrl}");
421+
422+
Map<String, String> headers = new HashMap<>();
423+
headers.put("X-Global-Transaction-Id", "<my-unique-transaction-id>");
424+
service.setDefaultHeaders(headers);
425+
426+
MessageOptions options = new MessageOptions.Builder(workspaceId).build();
427+
MessageResponse result = service.message(options).execute().getResult();
428+
```
429+
416430
## FAQ
417431

418432
### Does this SDK play well with Android?

0 commit comments

Comments
 (0)