How can we create a Customer and a SalesOrder using API from Shopify or Laravel

Hello guys !

I needed some help in order to integrate Shopify and ERPNext platform for sales.

I have the integration setup in place and its working seamlessly - the blocker that I am facing is with the products which have variants on Shopify Store.

I am looking for a way where we can overcome this by using Rest API and create a Customer and Sales Order using API endpoint and have the order items updated accordingly.

Looking forward for a positive and quick response.

TIA !

Hi there,

Frappe comes with a full REST API built-in. Is that what you’re looking for?

Hey @peterg

Thank you for your quick response.

I am looking forward to consume an API call to create a customer and once the customer is created, create a SalesOrder with the same customer details.

Can you please share some details on the above scenario ?

Cheers !

Hello,

What kind of details are you looking for? I don’t know anything about your context, especially w.r.t. how the calls are going to be made, so it’s hard to be specific.

What you’re describing is exactly what the REST API was designed to do. Make a POST call to the customer endpoint, then use the returned value when making a POST call to the Sales Order endpoint.

https://frappeframework.com/docs/v13/user/en/api/rest

Hey @peterg

Thank you so much for a lightning fast response - much appreciated !

Yes, you are right, I will be making a POST call - I am looking for an example if you can help me with one, so that it would help me understand it better - For eg, Enpoint URL, Where to find the API key for authentication, etc.

I did look into the docs, but it got me confused so reached out to the forums ! :confused:

It would be great if you could help me with an example for this approach.

Cheers !

If you’re new to working with APIs, I would recommend getting something like Postman so you can play around in realtime without having to wonder if the errors you’re getting are from the API call or from how they get represented in laravel/shopify/etc.

The endpoints are defined in the document I linked, specifically here for create calls:
https://frappeframework.com/docs/v13/user/en/api/rest#create

So, /api/resource/Customer and /api/resource/Sales Order.

In the request, you’ll need an Authorization header using a token that you’ve created from your User account page:
https://frappeframework.com/docs/v13/user/en/api/rest#1-token-based-authentication

Then, in the body, it’s just a json object representing the fields values you want to create. To see examples of those objects, you could use a GET request on a Customer/Sales Order document that already exists.

Whoa !

That is great - I will quickly setup a postman instance and will try to use the API as suggested.

Will check and get back to you in sometime if further help is required.

Thanks !

1 Like

have you tried shopify integration? https://github.com/frappe/ecommerce_integrations

Hi @ankush

Thank you for your suggestions - this integration is already in place but the issue that we are facing here is with product variants - they are not synced as expected, it always picks the default variant when order is created.

Can you please suggest here if there is a way out for this ?

Thanks !

Your variants already exist on ERPNext site or they are synced via orders from Shopify?

products are synced with ERPNext when the order is placed on shopify website - but only the default variant is updated within ERPNext and not the selected variant while placing an order.

Hi @peterg - can you please let me know what will the endpoint url over here, as I have not set this up on my local system :confused:

It should just be:

https://yoursite.com/api/resource/Customer

Hey @peterg - I havent installed this on any of the domain. Can you please share a guide for the installation so that I can give it a try with Ngrok or something with setting it up on local system ?

Looking forward for a headsup on this!

Regards.

Is the Shopify installation on the same localhost? If so, you can just use localhost:8000 as your domain. If not, you need a way to make your local installation visible to the internet somehow. Is that what Ngrok does? I’m not familiar.

hey @ankush - can you please share your observation here, are we missing anything here ?

Hi @HashSam, I’m not following where you’re stuck. Deploying to a domain is usually part of the set up process. If you haven’t done that yet, it’s well documented:

https://frappeframework.com/docs/v13/user/en/bench/guides/adding-custom-domains

Hey @peterg

Apologies for the delay in response - we have hosted the site on FrappeCloud platform and created one user to create API Key and API Secret - everything seems good till here.

Now the issue that I am facing is with the authentication in Postman - please find the below attached screenshot -

Can you please check the same and let me know if I have missed anything here ?

@ankush - the items which are created on ERP platform are synced when the order is placed on shopify website. However, the SKU added in the Shopify website is not attached to the Item created on ERP Platform - can you please let me know if we are missing anything here ?

Looking forward to a response !

Thanks !