Get match between webhook payload array and HTTP call result

I don’t know if this should be done using Make, but I’m trying to find a way to match between 2 array and then construct another array using the information.

  1. Send webhook that contains an array called “packages” with elements containing “sku” and “quantity”
  2. Make HTTP call to get an array called “orderLines” containing “sku”, “quantity” and “lineNumber”
  3. Transform elements of “packages” to an array called “boxItems” that retains “sku” and “quantity” but also has the matching “lineNumber” from “orderLines”.
  4. Use the array from 3 to make HTTP requests

Because the same “sku” can populate multiple “orderLines”, there needs to be some way to keep track of which “orderLines” have already been used after each HTTP request in step 4.

Webhook payload contains the “packages” array:

[
	{   
		"name": "Package 1",		
		"line_items": [
			{
				"sku": "1001",				
				"quantity": 2				
			}
		]
	},
	{  
		"name": "Package 2",		
		"line_items": [
			{
				"sku": "1001",			
				"quantity": 1
			}		
		]
   }
]

HTTP call response contains the “orderLines” array

[
	{
	"lineNumber": "1",
	"item": {	
		"sku": "1001"
	},
	"orderLineQuantity": {		
		"amount": "1"
		}
	},
	{
		"lineNumber": "2",
		"item": {	
			"sku": "1001"
		},
		"orderLineQuantity": {		
			"amount": "1"
			}
	},
	{
		"lineNumber": "3",
		"item": {	
			"sku": "1001"
		},
		"orderLineQuantity": {		
			"amount": "1"
			}
	}
]

I need to match the sku and quantity in the first array against the sku and lineNumber in the second array to get the following array:

for package 1

[
	{
		"lineNumber": "1",
		"sku": "1001",
		"quantity": 1
	}
	{
		"lineNumber": "2",
		"sku": "1001",
		"quantity": 1
	}
]

for package 2

[
	{
		"lineNumber": "3",
		"sku": "1001",
		"quantity": 1
	}
]