2

I'm trying to pull some data into Drupal from a service, via Guzzle. I've got several clients like this working, but the data returned by this service is structured a bit differently:

{
  pager: [ ],
  row_count: 101,
  data: {
    "794": {
      InventoryID: "794",
      AddressID: "618"
    },
    "2318": {
      InventoryID: "2318",
      AddressID: "536"
    }
  }
}

A service description like this:

operations:
  GetInventoryList:
    httpMethod: "GET"
    uri: "current-stock/inventory?_format=json"
    summary: "Gets all current inventory items"
    responseClass: "InventoryList"

models:
  InventoryListItem:
    type: "object"
    location: "json"
    properties:
      InventoryID:
        location: "json"
        type: "string"
      AddressID:
        location: "json"
        type: "string"
  InventoryList:
    type: "array"
    location: "json"
    items:
      "$ref": "InventoryListItem"

...doesn't work, of course, because it targets the top level of the response. Is there a way to define the models so that the contents of the 'data' array are returned, rather than the top level array?

closed as unclear what you're asking by Kevin, Pierre.Vriens, leymannx, mradcliffe, kiamlaluno Jul 19 at 10:34

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I don't understand what you're asking based on the code you provided. Why do you have a service description for a http client? You can do whatever you need to with the response from Guzzle. Feed it into serializer (if you have a normalizer defined). – mradcliffe Jul 17 at 18:43
  • I'm interested in this but I also don't understand the implementation – Ismail Cherri Jul 18 at 13:18
  • I typically use this module when building my clients: drupal.org/project/http_client_manager -- it uses the service description to query the service and parse the response. – WRD Jul 18 at 20:07

Browse other questions tagged or ask your own question.