How to save json feed to MongoDB in Laravel and get the key? - laravel

I need the following: I make GET requests to the API and receive responses in JSON format.
We have some sort of logs about responses and I'd like to keep record about the content of these JSON objects on the moment of the request.
In the Laravel command, I have to:
1) Save JSON object to MongoDB and get the unique key "feed_id" from collection under which it was saved.
2) Save the "feed_id" to the table column, where we store logs about history of requests.
How can I implement the first step in Laravel? I have seen some example, but without getting the id.

there is a excellent package for mongoDB in laravel named jenssegers/mongodb
you can install it via composer.
once you've installed it , you can simply insert an object and get the id in response like you do with eloquent and mysql

Related

Creating ResponseEntity CREATED for multiple records

I have an application that exposed an endpoint to insert multiple records into the DB. It takes in a list of ids and inserts them into the DB.
Now I have already worked on an endpoint, where I was getting a DTO and then I inserted that DTO into the DB which gave back the UID of the record. Using this UID I created the URI that I used to create and return the ResponseEntity.created() like below:
return ResponseEntity.created(URI.create(location)).body(roId);
The challenge here is that it works for only one location and one UID. Is it possible to do that same in case I am inserting multiple records in the DB and I will be getting a list of ids? Is this even the right approach?
NOTE: I do not want to return the List<ResponseEntity<Long>>. I require ResponseEntity<List<Long>>.

Rest API Call in uipath

My requirement is to fetch the data from rest api data and store it in separate variable. I had the endpoint url(https://abcdev.service-now.com/api/now/table/sc_multi_row_question_answer?sysparm_query=parent_id%3Dxxxxxxxxxxxxxxxxxxxx&sysparm_display_value=true&sysparm_exclude_reference_link=true&sysparm_fields=variable_set%2Cvalue%2Citem_option_new%2Crow_index).This is fetching the datas for all 3 rows. But i wants that this user needs to be added in this delegate access like that.
I have attached the image for which field i want to fetch.
I wants to fetch user to be added,level of access required,inbox,calender,tasks,contacts,notes,journal,select required send rights for these field i wants to fetch row by row.kindly assist me in that.
You will receive the response in JSON with all the rows, but you can use de serialize JSON Array activity to de serialize the JSON in each record with all the columns you have mentioned.
And Once you have the rows in the array JSON you can loop through it and get the details for each field.

How to fetch the variable value in service now when ordering item from service catalog?

I have successfully ordered an item from service catalog using REST API. While ordering I sent a JSON data in the request body containing certain key value pairs which are meant to be stored in variable of the catalog item. After the successful order, the response generated contains the sys_id, request_number, request_id, table name. Now, when I want to fetch the values passed to variables, the only way available is to make a GET call using the REST API for Tables. So, I am fetching the record using the generated sys_id and table name which is generated as response of order API. The table name is sc_request.
But that is not providing the variable value information in the response body of the GET call.
You should be able to get the values of variables using the Table API. If you go to the REST API explorer in ServiceNow, notice the field "sysparm_fields". put the name of your variabe(s) in there like this "variables.var_name". This will retrieve their values and display values in the response.

Will laravel reconnect to the database for any where on returned model collection?

If we have a find like this:
$returnedModel = Flight::
with("passengers")
->find(1);
Now if I add a where on returnedModel like this:
$returnedModel->passengers()->where("name" , "hamid")->first();
Will Laravel reconnect to the database for any where on returned model collection?
I added DB::getQueryLog() and there is a query with this where! how can I get this without reconnect to database?
You need to access your passengers as a property, not a method, by the way you get a Laravel collection already loaded from the DB (thanks to the with eager-loading).
$returnedModel->passengers->firstWhere('name', 'hamid');

Push data using routes in laravel

I'm trying to have an api which stores the information into my CRM, to push the details I've following parameters/details to store into the data:
Called_number, caller_number, agent_number, date, time, call_status, total_call_duration, Call_UUID, Recording_URL, conversation_duration
I've created the migration table with the same data name mentioned above, request protocol is HTTP, request data type is Query String and response data type is JSON.
Data is being sent by simple URL from third party so I'm using simple post route to insert the data into the database like this:
Route::post('/calllogs/{called_number}/{caller_number}/{agent_number}/{date}/{time}/{call_status}/{total_call_duration}/{call_UUID}/{recording_URL}/{converstation_duration}', 'CalllogController#insert')
Is there any way to secure this with some dynamic API keys to prevent inserting fake data? I mean any person having idea of the URL, can make the url and will insert data into my database, I want to have something like this:
Route::post('/calllogs/{api_key}/{caller_number}....
where I can check the api_key dynamically and then insert into the database.
Thanks.
This library (API Guard) is probably what you're looking for, it does exactly what you want: securing API calls with authorization keys.

Resources