See this example https://gist.github.com/jimgwhit/cbbe5bb0d2556fdc7e37a86d3630239c
Oct 17, 2023
6
Level 5
Unable to process incoming JSON Data
Hi All,
I'm running into an issue where I cannot seem to get the 'value' key of the POSTED JSON to my API Endpoint. I've spent several hours trying to troubleshoot this but just can't seem to figure it out. Can anyone please take a look and let me know what I might be missing?
namespace App\Http\Controllers\Email;
use App\Http\Controllers\Controller;
use App\Console\Commands\Email\ChangeNotifications\ProcessEmailChangeNotificationCommand;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
class EmailChangeNotificationController extends Controller
{
public function index(Request $request)
{
if (request()->query('validationToken')) {
return request()->query('validationToken');
} else {
$jsonData = $request->json()->all();
if (isset($jsonData['value']) && is_array($jsonData['value'])) {
$firstValue = $jsonData['value'][0];
$subscriptionId = $firstValue['subscriptionId'];
$changeType = $firstValue['changeType'];
if (isset($firstValue['resourceData']['id'])) {
$resourceId = $firstValue['resourceData']['id'];
} else {
return response()->json(['success' => false, 'message' => 'resourceData.id is not set'], 400);
}
$tenantId = $firstValue['tenantId'];
Artisan::call(ProcessEmailChangeNotificationCommand::class, [
'--resourceId' => $resourceId,
'--subscriptionId' => $subscriptionId,
'--changeType' => $changeType,
]);
return response()->json(['success' => true]);
} else {
return response()->json(['success' => false, 'message' => 'value is not set'], 400);
}
}
}
}
Here's the JSON that is being posted:
{
"value": [
{
"subscriptionId": "string",
"subscriptionExpirationDateTime": "2023-10-17T17:00:28.854381+00:00",
"changeType": "updated",
"resource": "string",
"resourceData": {
"@odata.type": "#Microsoft.Graph.Message",
"@odata.id": "string",
"@odata.etag": "string",
"id": "string"
},
"clientState": null,
"tenantId": "string"
}
]
}
Please or to participate in this conversation.