How to create the model from a dynamic api and pass it to Realmlist in kotlin - kotlin

need help. i have a dynmic API key as shown in pic. based on some solutions, i need to use map to handle dynamic. my issue is how to create the model for Realmlist as it is complaining on Map<>. pls help.
already created model for single item:
open class SingleMultipleOptions (
var key :String ?= null,
var option_name:String?= null,
var id:Long?= null,
var item_price:Double?= null ,
var item_name:String?= null
)
and this is for Map<>
#SerializedName("multiple_item_options")
#Expose
val multiple_item_options: Map<String, List<SingleMultipleOptions>>?= null,
my issue
var item_groups: #WriteWith<OOMenuItemGroupListParceler> RealmList<OOMenuItemGroup>? = null,
var item_options: #WriteWith<OOMenuItemOptionListParceler> RealmList<OOMenuItemOption>? =
null,
var multiple_item_options:RealmList<?????????????????>
var hasItemIcon: Boolean = false,
var is_chargeable: Boolean = false,
API response
"item_options": [],
"multiple_item_options": {
"151668": [ //Dynamic key
{
"option_name": "Dipping Sauce",
"option_display_name": null,
"id": "573738",
"item_price": "0",
"item_name": "Aioli Dipping Sauce",
"hide_price": false,
"min_permitted": "1",
"max_permitted": "1"
},
{
"option_name": "Dipping Sauce",
"option_display_name": null,
"id": "573739",
"item_price": "0",
"item_name": "Peri Peri Dipping Sauce",
"hide_price": false,
"min_permitted": "1",
"max_permitted": "1"
},
{
"option_name": "Dipping Sauce",
"option_display_name": null,
"id": "573740",
"item_price": "0",
"item_name": "Tomato Relish Dipping Sauce",
"hide_price": false,
"min_permitted": "1",
"max_permitted": "1"
},
{
"option_name": "Dipping Sauce",
"option_display_name": null,
"id": "573741",
"item_price": "0",
"item_name": "Ranch Dipping Sauce",
"hide_price": false,
"min_permitted": "1",
"max_permitted": "1"
}
],
"151670": [
{
"option_name": "Meat Lovers Opt",
"option_display_name": null,
"id": "573744",
"item_price": "0",
"item_name": "BBQ Base",

Related

convert list of value in nested dictionary to dataframe

i have a dictionary in the form
req_rep = {
"enrichments": [
{
"data": {
"Company_name": "tester",
"Company_CXO_Count__c": null,
"fbm__Company_Employee_Size__c": "11-50",
"fbm__Person_Title__c": "instructor",
"fbm__Professional_Email__c": "small#tester.com",
"fbm__Status__c": "Completed"
},
"id": "t1",
"status": "COMPLETED"
},
{
"data": {
"Company_name": "test3",
"Company_CXO_Count__c": null,
"fbm__Company_Employee_Size__c": "11-50",
"fbm__Person_Title__c": "driver",
"fbm__Professional_Email__c": "big#test3.com",
"fbm__Status__c": "Completed"
},
"id": "t2",
"status": "COMPLETED"
},
{
"data": {
"Company_name": "tryiu",
"Company_CXO_Count__c": null,
"fbm__Company_Employee_Size__c": null,
"fbm__Person_Title__c": null,
"fbm__Professional_Email__c": "dar#tryiu.co",
"fbm__Status__c": "Completed"
},
"id": "t2",
"status": "COMPLETED"
}
],
"expiry_date": "2022-03-11 11:24:35",
"remaining_requests": 19106,
"request_id": "16642740180563593e3c",
"total_requests": 20000
}
i wish to create a new dataframe off enrichments key value pairs to look like the table below.
i have tried a few results off my search here on stack overflow but i'm yet to get the expected result i am looking for.
df_2 = pd.DataFrame([{
'Company_name': "tester",
'Company_CXO_Count__c': null,
'fbm__Company_Employee_Size__c': "11-50",
'fbm__Person_Title__c': "instructor",
'fbm__Professional_Email__c': "big#test3.com",
'fbm__Status__c': "Completed"},
{'Company_name': "tester",
'Company_CXO_Count__c': null,
'fbm__Company_Employee_Size__c': "11-50",
'fbm__Person_Title__c': "instructor",
'fbm__Professional_Email__c': "small#tester.com",
'fbm__Status__c': "Completed"},
{ 'Company_name': "tryiu",
'Company_CXO_Count__c': null,
'fbm__Company_Employee_Size__c': null,
'fbm__Person_Title__c': null,
'fbm__Professional_Email__c': "dar#tryiu.com",
'fbm__Status__c': "Completed"}])
any help would be greatly appreciated
You need to apply pd.Series to enrichments and data:
df = pd.DataFrame(req_rep)
final_df = df['enrichments'].agg(pd.Series)['data'].agg(pd.Series)
use:
df=pd.DataFrame(req_rep['enrichments'])
final = pd.json_normalize(df["data"])
try json_normalize
df2 = pd.json_normalize(data=req_rep["enrichments"])
df2.columns = df2.columns.str.split(".").str[-1]
df2 = df2.drop(columns=["id", "status"])

how to convert json response to List in c# RestSharp

Currently I am working on asp .NET 5 console application with Restsharp, My Api Get request is working on postman, but I am struggling to convert this json object to a list .
This is my json object:
"data": {
"domain": "intel.com",
"disposable": false,
"webmail": false,
"accept_all": false,
"pattern": "{first}.{last}",
"organization": "Intel",
"country": "US",
"state": null,
"emails": [
{
"value": "danielle.sikich#intel.com",
"type": "personal",
"confidence": 99,
"sources": [
{
"domain": "github.com",
"uri": "http://github.com/hpc/mpifileutils",
"extracted_on": "2021-10-28",
"last_seen_on": "2021-10-28",
"still_on_page": true
}
],
"first_name": "Danielle",
"last_name": "Sikich",
"position": null,
"seniority": null,
"department": null,
"linkedin": null,
"twitter": null,
"phone_number": null,
"verification": {
"date": "2021-11-05",
"status": "valid"
}
},
I tried this but its not working:
List<Job> JobList = JsonConvert.DeserializeObject<List<Job>>(jsonResponse["data"]["emails"]["value"].ToString());

Order ID in shopify webhooks

I'm trying to integrate my app with shopify shop. So far, i configured webhooks to send data to my app on certain system events - like creating an order.
Everything is working just great with one exception - i can't understand how to get the order ID from those webhooks. There is no any param present in them that looks like an order id which i later need to use in any requests to shopify API to retrieve info about the order.
Example webhook (order-created event):
{
"id": 488245657691,
"email": "",
"closed_at": null,
"created_at": "2018-05-10T14:05:02-04:00",
"updated_at": "2018-05-10T14:05:03-04:00",
"number": 6,
"note": "raz dwa trzy",
"token": "xxx",
"gateway": "manual",
"test": false,
"total_price": "2000.00",
"subtotal_price": "2000.00",
"total_weight": 0,
"total_tax": "373.98",
"taxes_included": true,
"currency": "PLN",
"financial_status": "paid",
"confirmed": true,
"total_discounts": "0.00",
"total_line_items_price": "2000.00",
"cart_token": null,
"buyer_accepts_marketing": false,
"name": "#1006",
"referring_site": null,
"landing_site": null,
"cancelled_at": null,
"cancel_reason": null,
"total_price_usd": "555.69",
"checkout_token": null,
"reference": null,
"user_id":"",
"location_id":"",
"source_identifier": null,
"source_url": null,
"processed_at": "2018-05-10T14:05:02-04:00",
"device_id": null,
"phone": null,
"customer_locale": null,
"app_id": "",
"browser_ip": null,
"landing_site_ref": null,
"order_number": 1006,
"discount_codes": [],
"note_attributes": [],
"payment_gateway_names": [
"manual"
],
"processing_method": "manual",
"checkout_id": null,
"source_name": "shopify_draft_order",
"fulfillment_status": null,
"tax_lines": [
{
"title": "VAT",
"price": "373.98",
"rate": 0.23
}
],
"tags": "",
"contact_email": null,
"order_status_url": "",
"line_items": [
{
"id": 1241199411291,
"variant_id": 8135591723099,
"title": "Above elbow glass",
"quantity": 1,
"price": "2000.00",
"sku": "",
"variant_title": null,
"vendor": "",
"fulfillment_service": "manual",
"product_id": 750373666907,
"requires_shipping": true,
"taxable": true,
"gift_card": false,
"name": "Above elbow glass",
"variant_inventory_management": null,
"properties": [],
"product_exists": true,
"fulfillable_quantity": 1,
"grams": 0,
"total_discount": "0.00",
"fulfillment_status": null,
"tax_lines": [
{
"title": "VAT",
"price": "373.98",
"rate": 0.23
}
]
}
],
"shipping_lines": [],
"fulfillments": [],
"refunds": []
}
The only params that looks like might be handy are token and order_number but token is probably nor what i'm looking for, just like the order_number. Third one is id but, based on shopify docs, id is a webhook id, not order id. Do you have any idea on how can i obtain such order ID from the webhook?
Just like the domain the webhook is coming from, the order ID is in the header. That will help you out. Simply grab the order ID from there, and move on.
example:
domain = request.env['HTTP_X_SHOPIFY_SHOP_DOMAIN']
order_id = request.env['HTTP_X_SHOPIFY_ORDER_ID']

How to get list of Users under a certain Manager/Approver in Coupa API?

I'm lost and I'm hoping that someone may have worked on this before.
So Coupa has its API:
https://coupadocs.atlassian.net/wiki/display/integrate/Users+API
I was able to retrieve user information together with the corresponding manager. Sample response:
https://unknownserver-test.coupahost.com/api/users?employee-number=10003323
[
{
"id": 2756,
"created-at": "2017-03-30T09:29:19-05:00",
"updated-at": "2017-03-31T04:30:53-05:00",
"login": "user1.user1",
"email": "staging23#coupa.com",
"purchasing-user": false,
"expense-user": false,
"sourcing-user": false,
"inventory-user": false,
"employee-number": "10003323",
"phone-work": null,
"phone-mobile": null,
"firstname": "user1",
"lastname": "user1",
"fullname": "user1 user1",
"api-user": false,
"active": false,
"salesforce-id": null,
"account-security-type": 0,
"authentication-method": "coupa_credentials",
"sso-identifier": null,
"default-locale": null,
"default-account": null,
"business-group-security-type": null,
"edit-invoice-on-quick-entry": false,
"avatar-thumb-url": null,
"mention-name": "user1user1",
"company-employee-id": "10003323",
"netsuite-employee-id": "10003323",
"subsidiary": {
"id": 1592,
"external-ref-num": null,
"external-ref-code": "company North America:1"
},
"job-title": {
"id": 2591,
"external-ref-num": null,
"external-ref-code": "VP, Sales"
},
"employee-type": "",
"default-expense-region": "",
"default-geo-spend": "",
"notes": "",
"exclude-from-autosarf": "",
"roles": [
{
"id": 10,
"name": "Expense User"
}
],
"manager": {
"id": 838,
"login": "john.doe",
"email": "staging#coupa.com"
},
"default-currency": {
"id": 1,
"code": "USD"
},
"department": {
"id": 342,
"name": "Sales - Exec:176"
},
"expenses-delegated-to": [],
"can-expense-for": [],
"content-groups": [],
"account-groups": [],
"approval-groups": [],
"working-warehouses": [],
"inventory-organizations": [],
"created-by": {
"id": 2748,
"login": "user1 creator",
"email": "user1.creator#company.com"
},
"updated-by": {
"id": 2748,
"login": "user1 creator",
"email": "user1.creator#company.com"
}
}
]
What I've tried are these:
https://unknownserver-test.coupahost.com/api/users?user[manager][id]=838&return_object=shallow
https://unknownserver-test.coupahost.com/api/users?manager[id]=838&return_object=shallow
https://unknownserver-test.coupahost.com/api/users?users[user][manager][id]=838&return_object=shallow
https://{{URL PREFIX}}.{{HOST}}.com/api/users?manager_id=838&return_object=shallow
If you only need the IDs of the users, you'd get better performance with return_object=limited
If there are more than 50 users returned, you'll have to paginate with the offset query param.

Access subscription details with Stripes Webhooks PHP

I haven't been able to find any details for this with PHP, so I am hoping somebody can help me complete this script?
I am searching for the Subscription details from the Stripe API Webhook event. The event I am working on is invoice.payment_succeeded although I am struggling to access the subscription information from this. Here is the test event in full:
{
"id": "evt_19HdmRL346436RYAmvgxkr",
"object": "event",
"api_version": "2016-07-06",
"created": 1479580899,
"data": {
"object": {
"id": "in_19HdmRLniq434634643dO2gU",
"object": "invoice",
"amount_due": 700,
"application_fee": null,
"attempt_count": 1,
"attempted": true,
"charge": "ch_19Hdm3463464365IDDXX",
"closed": true,
"currency": "gbp",
"customer": "315464619",
"date": 1479580899,
"description": null,
"discount": null,
"ending_balance": 0,
"forgiven": false,
"lines": {
"object": "list",
"data": [
{
"id": "sub_9apRC346346CMNg",
"object": "line_item",
"amount": 700,
"currency": "gbp",
"description": null,
"discountable": true,
"livemode": false,
"metadata": {
"website_ref": "Z8ckRo2x",
"user_id": "1"
},
"period": {
"start": 1479580899,
"end": 1482172899
},
"plan": {
"id": "AdFree",
"object": "plan",
"amount": 700,
"created": 1479261871,
"currency": "gbp",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {},
"name": "AdFree",
"statement_descriptor": "SNAPPYSITES ADFREE",
"trial_period_days": null
},
"proration": false,
"quantity": 1,
"subscription": null,
"type": "subscription"
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/invoices/in_19HdmRLn34353465dO2gU/lines"
},
"livemode": false,
"metadata": {},
"next_payment_attempt": null,
"paid": true,
"period_end": 1479580899,
"period_start": 1479580899,
"receipt_number": null,
"starting_balance": 0,
"statement_descriptor": null,
"subscription": "sub_9a2552OA5553MNg",
"subtotal": 700,
"tax": null,
"tax_percent": null,
"total": 700,
"webhooks_delivered_at": null
}
},
"livemode": false,
"pending_webhooks": 1,
"request": "req_9apRx9555ZVm55",
"type": "invoice.payment_succeeded"
}
I am currently listening with this unfinished script:
$input = #file_get_contents("php://input");
$event_json = json_decode($input);
$event_id = $event_json->id;
$event = \Stripe\Event::retrieve($event_id);
if($event->type == 'invoice.payment_succeeded'){
$invoice = $event->data->object;
$subscription = $invoice->lines->data->plan;
$customer = \Stripe\Customer::retrieve($invoice->customer);
print_r($subscription);
}
Unfortunately I'm not getting any response from the $subscription array. And I have attempted various methods, such as; $subscription = $invoice->plan; or $subscription = $invoice->data->plan; etc...
I do receive data for $invoice & $customer so I know they both function correctly. My main focus is to retrieve the Metadata information:
"metadata": {
"website_ref": "Z8ckRo2x",
"user_id": "1"
}
So I know which account this payment relates to. Hoping somebody might know what I'm doing wrong.
Have you tried $invoice->lines->data->Metadata->website_ref to get the metadata you are after?
Your Invoice consists of a list of subscriptions, in this case just 1. Each subscription is a result of the user selecting a plan. The metadata is stored at the subscription level as it's specific for the customer, not on the plan.