Unable to fetch results of member functions of Data Exchange

0

Hi, actually I am new to the AWS services and was going through the various methods provided by the DataExchange Client class. I am working with PHP SDK and when I am using the ListDataSets method it is returning the desired results but when I am trying to get the response of API (to which I have already subscribed), then it is not giving me the desired output.

Whereas, when I am doing the API call through POSTMAN, I am getting the response. For example, this is the response of postman:

Everything is as expected in Postman

As defined in the documentation, when sendApiAsset() will be called, in the response object there will be two things: One being the body and the second one being Response Headers. But in my case, the body is empty always. Why is that? The method should return the JSON object so that I can use it for further processing. I have searched every available resource but can't find a reason why that's happening.

Enter image description here

Here is the output which doesn't have anything in the body: Enter image description here

Please help me out.

asked a year ago229 views
1 Answer
2

From what you posted, it appears that the response is, in fact, coming back with contents. The response message body is wrapped in a Stream Object (ref: https://docs.guzzlephp.org/en/stable/psr7.html#streams). To read it, you should be able cast or parse it:

$contents = (string) $result->getBody();

or

$contents_json = json_decode($result->getBody());
AWS
jchan
answered a year ago
  • Thanks for your help. Actually, your solution almost worked but I just had to change the getBody() method with an associative key because this method was not working.

    So, the solution was like this: $contents = (string) $result['Body'] OR $contents_json = json_decode($result['Body']);

  • Ah, right.. the body itself is in an associative array -- nice catch. Glad to hear that it helped get you on your way!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions