Fulfilling multiple Gift cards within an order one at a time

New Member
1 0 0

Hi im having a few issues with an app im building.

Currently I have a web hook which checks for orders created, then im looping through the line items and it checks either if the Gift card contains an email within the properties or not. If the Gift card contains an email then it will change the customer email over to this one. then fulfil the line item then replace the email with the old one and if its a normal Gift card without an email it will just fulfil.

For some reason it kept failing with a 422 error on the second iteration. But the first run through is fine.

So I've even attempted to just fulfil all line items one at a time within the order and this still doesn't work. The code for that is below.

 

axios.post(`https://${STORE}/admin/api/${API_VERSION}/orders/${orderId}/fulfillments.json`, {
                 fulfillment: {
                     location_id: LOCATION_ID,
                     line_items: [{
                         id: ctxNew.line_items[i].id
                     }]
                 }
             },{
                 headers: {
                     'X-Shopify-Access-Token': accessTokenForApi
                 }
             })
             .then(function (response) {
                 console.log(response);
             })
             .catch(function (errors) {
                 console.log(errors);
             });

 

Any guidance on why this fails or if there is a solution to this would be amazing!

 

Thanks,

Ken 

 

0 Likes
Shopify Staff
Shopify Staff
39 5 3

@Kennethhhhh ,

Hey Ken, I can look into this some more for you. Before I do, would it be possible to provide the x-request-id found in the headers of the response. 

Thanks,

John

John C | Developer Support Specialist @Shopify
0 Likes