SyncMadeEasy/force-app/main/default/classes/UpdateInventoryLevelsFromSh...

34 lines
2.6 KiB
OpenEdge ABL

/**
* ─────────────────────────────────────────────────────────────────────────────────────────────────┐
* This web service class is use for handle Shopify's Inventory Levels/Items and Location webhook response.
* Trigger on Product item update then it will update it's inventory update.
* Shopify API Documentation: https://shopify.dev/docs/admin-api/rest/reference
* Create Shopify Store: https://www.shopify.com/signup?itcat=identity&itterm=create-new-store
* Shopify API Release 2020: https://www.shopify.in/partners/blog/shopify-api-release-january-2020
* What is Person Account in Salesforce ? https://help.salesforce.com/articleView?id=account_person.htm&type=5
* ──────────────────────────────────────────────────────────────────────────────────────────────────
* @author Sumit <sumit@hicShopify.com>
* ──────────────────────────────────────────────────────────────────────────────────────────────────
*/
@RestResource(urlMapping='/UpdateInventoryLevelsFromShopify/*')
global with sharing class UpdateInventoryLevelsFromShopify {
@HttpPost
global static void UpdateIventory(){
RestRequest request = RestContext.request;
String store = 'Default';
Map <String, String> params = request.params;
if(!params.isEmpty() && params.containsKey('store') && params.get('store') != null)
store = params.get('store');
RestResponse response = RestContext.response;
String JSONResponseBody = request.requestBody.ToString().Trim();
Map<String, Object> meta = (Map<String, Object>) JSON.deserializeUntyped(JSONResponseBody);
String inventoryItemId = String.valueof(meta.get('inventory_item_id'));
String locationId = String.valueof(meta.get('location_id'));
FetchLocationWebhook fetch = new FetchLocationWebhook(locationid, inventoryItemId, JSONResponseBody,store);
System.scheduleBatch(fetch, 'FetchLocationWebhook '+inventoryItemId + locationId +String.valueOf(System.Now().millisecond()), 1, 1);
}
}