Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

post purchase extension proxy issue

post purchase extension proxy issue

ecom-star-dev
Shopify Partner
1 0 2

I am building a post purchase extension and I want to send a request to my server so I created a proxy, the proxy is working when I try to access it in the browser.

I get into an issue when I try to use the proxy URL inside the extension.

Proxy config -

 

 

import { createVerifyAppProxyMiddleware } from 'shopify-verify-app-proxy-middleware';

const { SHOPIFY_API_SECRET } = process.env;
const verifyAppProxyMiddleware = createVerifyAppProxyMiddleware(SHOPIFY_API_SECRET);

app.use('/api/proxy/', verifyAppProxyMiddleware, proxyRoutes);

 

 

proxyRoutes - 

 

 

import { Router } from 'express';
import { getAllFunnels } from '../controllers/funnel.controller';

const router = Router();

router.get('/funnels/get', getAllFunnels);

export default router;

 

 

 App settings -

Screenshot 2024-02-14 at 19.37.10.png

Post purchase extension - 

 

 

// For local development, replace APP_URL with your local tunnel URL.
const APP_URL = 'https://something.trycloudflare.com';

extend('Checkout::PostPurchase::ShouldRender', async ({ inputData }) => {
	try {
		const response = await fetch(`${APP_URL}/apps/proxy-1`, {
			method: 'GET',
			headers: {
				'Authorization': `Bearer ${inputData.token}`,
				'Content-Type': 'application/json',
				'Access-Control-Allow-Origin': '*',
			},
		});

		if (!response.ok) {
			// Handle non-2xx responses
			throw new Error(`HTTP error! status: ${response.status}`);
		}

		const x = await response.json();
		console.log(x);

		// For local development, always show the post-purchase page
		return { render: true };
	} catch (error) {
		console.error('Failed to fetch funnels:', error);
		// Decide how to handle the error, e.g., not rendering the post-purchase page
		return { render: false };
	}
});

 

 

shopify.extension.toml file -

 

 

type = "checkout_post_purchase"
name = "some-name"

[capabilities]
network_access = true

 

 

 notice here is that I use [capabilities] and not [extensions.capabilities] like it says in the docs - link, when I try to use [extensions.capabilities] I got the following error when I tried to publish the extension -

 

 

 [                                                                                             │
│    {                                                                                           │
│      "code": "invalid_type",                                                                   │
│      "expected": "array",                                                                      │
│      "received": "object",                                                                     │
│      "path": [                                                                                 │
│        "extensions"                                                                            │
│      ],                                                                                        │
│      "message": "Expected array, received object"                                              │
│    }                                                                                           │
│  ]  

 

 

so I tried to use just [capabilities] and it didn't crash the publish but I have no idea how can I check if it's working besides actually succeeding to access a network. 


the response I get from the request in the extension -
Screenshot 2024-02-14 at 19.40.35.png

Reply 1 (1)

Liam
Community Manager
3108 344 902

Have you enabled "Allow network access" on your partner dashboard?

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog