ATF: Inbound REST API_how to retrieve data from response body

chetanka
Tera Contributor

Hi, I have 2 queries..need your help

 

1. I have done a inbound transaction and transaction got created in Custom table with a transaction number in response body, How to fetch tat transaction number from response body using ATF so that I can use it in my further steps. 

 

2. I have triggered and inbound Rest APi and in the next step I want to verify that the Response body is updated with Transaction number can we achieve this using ATF.

TIA

 

Regards,

Chetan

 

 

1 REPLY 1

ethanklein
Kilo Contributor

 

To retrieve data from the response body of an inbound REST API, you need to parse the response body using the appropriate programming language and extract the data that you need. The exact method of parsing and extracting data depends on the programming language and framework that you are using to consume the API.

Here is a general process for retrieving data from a response body:

  1. Make a request to the REST API using an HTTP client library, such as requests in Python or HttpClient in .NET.

  2. Receive the response from the REST API, which typically includes a status code, headers, and a response body.

  3. Parse the response body to extract the data that you need. The response body may be in a variety of formats, such as JSON, XML, or plain text.

  4. Use the parsed data in your application as needed.

For example, in Python, you might use the requests library to make a GET request to an API endpoint and parse the response body as JSON:

response = requests.get('https://api.example.com/data') data = response.json() # Extract specific data from the JSON response value = data['key']

 

 

In .NET, you might use the HttpClient class to make a GET request to an API endpoint and parse the response body as JSON using the Newtonsoft.Json library:

 

 
using System.Net.Http; using Newtonsoft.Json; HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync("https://api.example.com/data"); string responseBody = await response.Content.ReadAsStringAsync(); dynamic data = JsonConvert.DeserializeObject(responseBody); // Extract specific data from the JSON response string value = data.key;

Note that the exact code you need may vary depending on the specifics of your API and your programming language and framework.