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?

4
  • 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, 2019 at 18:43
  • I'm interested in this but I also don't understand the implementation Jul 18, 2019 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, 2019 at 20:07
  • Hi WRD, were you able to find a solution to this ? trying to do something similar. Mar 16, 2021 at 16:44

0

Browse other questions tagged or ask your own question.