Custom HTTP Socket Datasource > Create with related data

Hi all,

I’m working on a HTTP Socket Datasource for an API integration and want to POST a new resource including related resource data.

Problem is the related resource data is being stripped out of the request as it’s not in the schema declarations.

Any tips from you guys on how I submit a POST request with a JSON data string that matches the following structure would be greatly appreciated:

{
  "addresses": [
      {
        "city": "Dallas",
        "country": "US",
        "state":-"TX",
        ...
      }
  ],
  "first_name": "Don",
  "last_name": "Parsley",
  ...
}

Hi phpMagpie,

not sure I correctly understand what do you mean, but what about this example here:
http://book.cakephp.org/3.0/en/core-libraries/httpclient.html#sending-request-bodies

Andrej,

Thanks for responding … I’m using HttpSocket in CakePHP 2.x unfortunately, my bad for not being more clear about my environment.

The problem is when I pass in a data array() to Model::save() is it checked against the model’s schema declaration and if values in your data array are not in the schema, they are stripped from the request.

I have found that I can then intercept the data array and re-inject my extra data before calling $this->_request('POST', $url, json_encode($data)), but this feels a bit hacky and wondered how I could get CakePHP’s models setup to accept my original data array.

Thanks, Paul.