Shopify custom api calling

Jitali_2103
Shopify Partner
7 0 0

Here is the URL for my custom API: 
e326-2402-a00-404-b400-21a8-77a9-589f-66ef.ngrok-free.app/api/editWhatsApp/660ce205573a34cf199154ac
This API is part of my custom Shopify app. Could you guide me on how to call this API and retrieve data from it within Shopify?

Replies 5 (5)

ankitpateldev
Shopify Partner
15 1 2

Hi @Jitali_2103 ,

 

To utilize App Proxy for retrieving or sending data to a custom Shopify app, follow these steps:

  1. Navigate to the Shopify Partner Dashboard and locate the "Apps" section in the left-hand menu.

  2. Click on the desired app from the list of apps you have created.

  3. Find the configuration navigation menu from the left sidebar and open it.

  4. Move to the "App Proxy" section and add your URL under the "Proxy URL" field. From the "Prefix subpath" dropdown, choose any option, and under the "Subpath" field, add your desired text.

  5. Save the settings.

  6. Edit your code to make a GET request call. Now you can retrieve your data on the storefront proxy URL, which would be your Shopify BASE_URL/subpath_prefix/subpath.

Please replace BASE_URL, subpath_prefix, and subpath as per your configuration.

Let me know if you need further help.

Best regards,
Ankit Patel | Shopify Expert
Jitali_2103
Shopify Partner
7 0 0

Hi, @ankitpateldev 

Thanks for the replay.

I am currently using the ngrok API,
I have found my solution.

Now the question I have is how should I bring that data dynamic, Like I want to show the data of the user and fetch the name of the user's shop.

ankitpateldev
Shopify Partner
15 1 2

As I understand from your question, If you want to fetch the user's shop from the frontend, maybe from an app extension, and send that data to your app admin while also returning the user data from the app to the user storefront, you can pass the user's shop name as a URL parameter and make a GET request. Then, you can pass the user's data in response to that request call.

 

Storefront Call

this.cart = document.querySelector('cart-notification') || document.querySelector('cart-drawer');
const sectionMapped = this.cart.getSectionsToRender().map((section) => section.id).toString();

await fetch(`/apps/front?cartId=${cartId}&variantId=${variantId}&sections=${sectionMapped}`)
.then(response => {
    if (!response.ok) {
        throw new Error(response.status);
    }
    return response.json();
})
.then(data => {
    // GET UPDATED CART DATA IN RESPONSE
});

 

App Admin Page

export async function loader({ request }) {
   const url = new URL(request.url);
   const variantId = url.searchParams.get("variantId");
   const cartId = url.searchParams.get("cartId");
   const sections = url.searchParams.get("sections");

   // Use variantId, cartId, and sections as needed
}

Best regards,
Ankit Patel | Shopify Expert
Jitali_2103
Shopify Partner
7 0 0

Hi, @ankitpateldev 

I want to get the shop name of the user who installed my app. how can I get that for a specific user?

ankitpateldev
Shopify Partner
15 1 2

Hello @Jitali_2103 ,

 

There isn't a specific way to get user information directly, but you can use the Shopify API to request shop information when the user lands on your app's landing page. Below is the link to the official Shopify API documentation. You can follow that to get all the required user information in the API call:

Shopify API Documentation - Shop Resource

 

This approach will allow you to retrieve all the necessary user information from the Shopify API.

Best regards,
Ankit Patel | Shopify Expert