How do i parse products/update webhook to backend server

NewToAppDevHere
Shopify Partner
2 0 0

Hi, I'm using Shopify's Remix App Template, and have setup a webhook for products updated. I want it to send the updated product to my backend server. However I'm having some issues doing so.

 

I get this error:

15:42:55 │ remix │ PRODUCTS_UPDATE error: SyntaxError: Unexpected token 'o', "[object Rea"... is not valid JSON
and:

Request.body: ReadableStream { locked: true, state: 'closed', supportsBYOB: false }

 

Here is my case for product update:

case 'PRODUCTS_UPDATE':
console.log('PRODUCTS_UPDATE case called.');
    console.log('PRODUCTS_UPDATE called.');
    if ( !request.body ) {
        console.log('PRODUCTS_UPDATE request.body is null.', request.body);
        break
    }
    try {
        const product = JSON.parse(request.body.toString());
        console.log('PRODUCTS_UPDATE product:', product);
        const response = await axios.post(
            `${API_DOMAIN}/products/update`,
            {
                store_url: shop,
                product: product
            },

            {
                headers: {
                    'Content-Type': 'application/json',
                },
            },
        );
    }catch (error: unknown) {
    console.log('PRODUCTS_UPDATE error:', error)
    console.log("Request.body: ______" ,request.body, "______ REQUEST: ______", request, "______");
    }break;
Replies 0 (0)