0

A third party service is sending JSON data to me, which I receive at a PHP page.

I access the data using the following, then insert the whole $data value in to a database just to see what I'm being sent. This works.

$data = json_decode(file_get_contents('php://input'), true);

The data I receive and can see in the database is:

[{"import_id":65748,"sheet_id":3637,"sheet_name":"Contacts","row_number":1,"total_rows":1,"custom_fields":{"user_id":"default123"},"row_data":{"email":"fred@test.com","_unmapped_data":{"first name":"first name","lastname":"lastname","phone":"phone"}}}]

However I then want to access individual pieces of data, not the whole thing. Usually I'd do:

$import_id = $data["import_id"];

And that would give me the "65748" value from the "import_id" part of the data.

This doesn't work. I get an empty cell in the database for the $import_id value.

I've tested it using my own page to generate JSON and send it to the page and it works there. So it has to be something specific about the structure of the data I'm being sent. The only thing I can see different is my own JSON doesn't have the [] at the beginning and end of the data, it starts/ends just with the {}

Is this relevant? If so, what do I need to do to handle this properly? If not, what dumb thing am I missing?

covgdn
  • 55
  • 5

0 Answers0