I'm getting the location_id as null in shopify order api - shopify

I created an order through shopify admin and added the customer details , when i executes the orders.json api , I'm getting location_id ="null"
Now i'm in need of location id to update the fulfillment status.
How to update the location id for an order if possible .This is my response when i created an order .
{
"orders": [
{
"id": 568323571800,
"email": "sample_test_123_gmail#gmail.com",
"closed_at": null,
"created_at": "2018-08-02T15:41:06+05:30",
"updated_at": "2018-08-02T15:46:06+05:30",
"number": 9,
"note": "",
"token": "a666eb3aea251cc585afc006cbf5b315",
"gateway": "Cash on Delivery (COD)",
"test": false,
"total_price": "200.00",
"subtotal_price": "200.00",
"total_weight": 100,
"total_tax": "0.00",
"taxes_included": false,
"currency": "INR",
"financial_status": "pending",
"confirmed": true,
"total_discounts": "0.00",
"total_line_items_price": "200.00",
"cart_token": null,
"buyer_accepts_marketing": false,
"name": "#1009",
"referring_site": null,
"landing_site": null,
"cancelled_at": null,
"cancel_reason": null,
"total_price_usd": "2.92",
"checkout_token": null,
"reference": null,
"user_id": 23090102360,
"location_id": null,

location ID is tied to your inventory. First off, ensure you have set a location for your inventory. Second, make sure Shopify is set as your inventory management provider. If you now create an order for items managed by Shopify, you might see a location ID. Your test of creating a draft order like that might also not be fully integrated yet with Shopify locations? What happens when you book an order using the front end and not the API?

location_id on an order will return null unless the order is made from a Shopify POS location in which case it will return the location_id associated with that location.
See the guide on fulfillments: https://help.shopify.com/en/api/guides/managing-fulfillments

To get locationId in order, need to pass inventoryQuantities input with location id and available quantity in productCreate Mutation.Then You will get locationId in order
{
"input": {
"title": "Demo Product",
"descriptionHtml": "des",
"productType": "type",
"vendor": "vendor",
"handle": "abc1",
"tags": ["tag1", "tag2"],
"variants": [
{
"title": "small",
"price": 100,
"compareAtPrice": 110,
"position": 1,
"inventoryQuantities": {
"availableQuantity": 100,
"locationId": "gid://shopify/Location/55274340513"
},
"inventoryItem": {
"cost": 200,
"tracked": true
}
}
]
}
}

You can find location_id from the /admin/api/2021-04/locations.json API.
You will get response like this:
{
"locations": [
{
"id": location_id,
"name": "location_name",
"address1": "location_address",
"address2": null,
"city": "Faisalabad",
"zip": "38000",
"province": "",
"country": "PK",
"phone": "",
"created_at": "2021-02-25T15:34:18+05:00",
"updated_at": "2021-02-25T15:34:20+05:00",
"country_code": "PK",
"country_name": "Pakistan",
"province_code": null,
"legacy": false,
"active": true,
"admin_graphql_api_id": "gid://shopify/Location/location_id",
"localized_country_name": "Pakistan",
"localized_province_name": null
}
]
}

Related

Microsoft Booking Appointment Graph API -Only Post Request Not working

when I trying to create Microsoft Booking Appointment through Graph API
Only Post Request Not working .
GET , PATCH , DELETE Reuqest are working fine
through postman
same post request is working find on graph explorer platform . but not on posmant with
my auth token
my post API
https://graph.microsoft.com/v1.0/solutions/bookingBusinesses/XXXXXXXXXXXXXXX.com/appointments
and body (took example from here)
excluded optional properties like servicename and customers
{
"#odata.type": "#microsoft.graph.bookingAppointment",
"customerTimeZone": "America/Chicago",
"smsNotificationsEnabled": false,
"endDateTime": {
"#odata.type": "#microsoft.graph.dateTimeTimeZone",
"dateTime": "2023-01-02T14:30:00.0000000",
"timeZone": "UTC"
},
"isLocationOnline": true,
"optOutOfCustomerEmail": false,
"anonymousJoinWebUrl": null,
"postBuffer": "PT10M",
"preBuffer": "PT5M",
"price": 10,
"priceType#odata.type": "#microsoft.graph.bookingPriceType",
"priceType": "fixedPrice",
"reminders#odata.type": "#Collection(microsoft.graph.bookingReminder)",
"reminders": [
{
"#odata.type": "#microsoft.graph.bookingReminder",
"message": "This service is tomorrow",
"offset": "P1D",
"recipients#odata.type": "#microsoft.graph.bookingReminderRecipients",
"recipients": "allAttendees"
},
{
"#odata.type": "#microsoft.graph.bookingReminder",
"message": "Please be available to enjoy your lunch service.",
"offset": "PT1H",
"recipients#odata.type": "#microsoft.graph.bookingReminderRecipients",
"recipients": "customer"
},
{
"#odata.type": "#microsoft.graph.bookingReminder",
"message": "Please check traffic for next cater.",
"offset": "PT2H",
"recipients#odata.type": "#microsoft.graph.bookingReminderRecipients",
"recipients": "staff"
}
],
"serviceId": "XXXXXXXXXXXXXXXXXXXXX",
"serviceLocation": {
"#odata.type": "#microsoft.graph.location",
"address": {
"#odata.type": "#microsoft.graph.physicalAddress",
"city": "Buffalo",
"countryOrRegion": "USA",
"postalCode": "98052",
"postOfficeBox": null,
"state": "NY",
"street": "123 First Avenue",
"type#odata.type": "#microsoft.graph.physicalAddressType",
"type": null
},
"coordinates": null,
"displayName": "Customer location",
"locationEmailAddress": null,
"locationType#odata.type": "#microsoft.graph.locationType",
"locationType": null,
"locationUri": null,
"uniqueId": null,
"uniqueIdType#odata.type": "#microsoft.graph.locationUniqueIdType",
"uniqueIdType": null
},
"serviceNotes": "Customer requires punctual service.",
"startDateTime": {
"#odata.type": "#microsoft.graph.dateTimeTimeZone",
"dateTime": "2023-01-02T14:00:00.0000000",
"timeZone": "UTC"
},
"maximumAttendeesCount": 1,
"filledAttendeesCount": 1
}

Get nested data c.<type>.<type> in SQL Query?

I've been searching everywhere for this seemingly simple action: I'd like to select only a certain few data type from a nested source.
The closest that I can get to the solution is this:
SELECT c.receipt_number, c.millitime, c.email, c.phone, c.shipping, c.shipping_note, c.amount_paid, i.description, i.quantity
FROM c
JOIN i IN c.line_items
WHERE c.millitime > 1627813253000
But this will create lots of duplicated data, like the receipt_number, email, etc in the example:
[
{
"receipt_number": null,
"millitime": 1627813377000,
"email": "test#gmail.com",
"phone": "000000000",
"shipping": {
"address": {
"city": "Sydney",
"country": "AU",
"line1": "Test Street",
"line2": null,
"postal_code": "3000",
"state": "VIC"
},
"name": "New Cust"
},
"shipping_note": "Please knock on door.",
"amount_paid": 104,
"description": "Curry Chicken",
"quantity": 1
},
{
"receipt_number": null,
"millitime": 1627813377000,
"email": "test#gmail.com",
"phone": "000000000",
"shipping": {
"address": {
"city": "Sydney",
"country": "AU",
"line1": "Test Street",
"line2": null,
"postal_code": "3000",
"state": "VIC"
},
"name": "New Cust"
},
"shipping_note": "Please knock on door.",
"amount_paid": 104,
"description": "Chicken Noodle",
"quantity": 8
}
]
Is there a way to create a nested result of c.line_items with just the desired data description and quantity? The final result should be similar to:
[
{
"receipt_number": null,
"millitime": 1627813377000,
"email": "test#gmail.com",
"phone": "000000000",
"shipping": {
"address": {
"city": "Sydney",
"country": "AU",
"line1": "Test Street",
"line2": null,
"postal_code": "3000",
"state": "VIC"
},
"name": "New Cust"
},
"shipping_note": "Please knock on door.",
"amount_paid": 104,
"line_items": [
{
"description": "Chicken Noodle",
"quantity": 8
},
{
"description": "Curry Chicken",
"quantity": 1
}
]
}
]
I have created the same in
You can use distinct keyword to remove duplicates from the results.
Add c.line_items to your select list and change i.description, i.quantity to c.description, c.quantity to add view under line_items.
Query:
SELECT distinct c.receipt_number, c.millitime, c.email, c.phone, c.shipping, c.shipping_note, c.amount_paid, c.line_items
FROM c
JOIN i IN c.line_items
WHERE c.millitime > 1627813253000
Result:
Reference: Azure Cosmos DB SQL query - JSON items

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']

Get products of an order with Spree API

I simply want to get all the orders of my Spree e-commerce system, with all products the user bought in an order. I see I can grab all orders, all shipments, but there is no information about a "complete" query that includes products a user bought.
There is a way to do that ?
GET /api/v1/orders is a paginated query which respons should look something like that:
{
"orders": [
{
"id": 1,
"number": "R335381310",
"item_total": "100.0",
"display_item_total": "$100.00",
"total": "100.0",
"display_total": "$100.00",
"state": "cart",
"adjustment_total": "-12.0",
"user_id": null,
"created_at": "2012-10-24T01:02:25Z",
"updated_at": "2012-10-24T01:02:25Z",
"completed_at": null,
"payment_total": "0.0",
"shipment_state": null,
"payment_state": null,
"email": null,
"special_instructions": null,
"total_quantity": 1,
"token": "abcdef123456",
"line_items": [
],
"adjustments": [
],
"payments": [
],
"shipments": [
]
}
],
"count": 25,
"pages": 5,
"current_page": 1
}
Each Order contains line_items, which are products that you are looking for.
Source: http://guides.spreecommerce.org/api/orders.html

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.