Integrating Third Party API into Shopify

Guillermo31
New Member
6 0 0

Hi Shopify Experts,

Can someone help me with the installation of the API?

 

I am looking to integrate a third party REST API that handles the printing and shipping of my customers items. 
Documentation https://portal.printapi.nl/test/docs/section/general?l=PHP&t=EN

 

I am trying to understand how to set up the connection between Print API and my Shopify Store.
This is what I have figured out so far:

 

1) I need to connect the Shopify API with the Print API
2) I can create a custom app in Shopify via Partners or private App 
3) Something with webhooks? 

I don't understand how and where I need to actually put my code. Is it only webhooks, do I need to put the API .php code somewhere in my Shopify Code? How does this work? 
Also I don't even know how to authenticate a custom app even when I have read the turtorials.
My main language is Dutch so it is difficult for me to understand some parts.


Hope someone can give me some more detailed information, I am eager to learn/implement this. 

0 Likes
policenauts
Pathfinder
108 6 19

Since it is just for you or a single client, I suggest to use a private app instead of custom app so you don't need to deal with OAuth in terms of authentication.

Please describe the flow you are hoping to accomplish (what happens in Shopify => print API)?

0 Likes
Guillermo31
New Member
6 0 0

Thanks for replying!

 

I want to intergrate an API that sends orders to the company I am working with so they can immediately start the printing production.

 

I got alot of code which I need to install but don't know how to install even when I red alot of turtorials on the shopify forms.

Also I got API keys from the documentaire itself.

An Private app is also good for me I just want the API to be working  

0 Likes
policenauts
Pathfinder
108 6 19

OK I gotcha. Yes, in that case the easiest is probably webhooks. This is the process I would do: 

  1. Create a webhook for orders/created that points to your http endpoint (you can create a webhook either manually in the Shopify Admin or programmatically using the API)
  2. After an order is created in Shopify, it will send a POST request to your endpoint with the order details in the body
  3. Parse the JSON and perform your business logic to translate Shopify's order details into an order that your print API will understand
  4. Then send the http request to your Print API 

Because you are using webhooks, depending on what you are doing you may not necessarily even need to do any additional auth in terms of the Shopify API since all of the order details are included in the webhook's payload.  

 

0 Likes
Guillermo31
New Member
6 0 0

Thank you so much!

 

This is what they say:

General

Your website, plugin or app can communicate with our REST API by sending HTTP requests. This means you can use Print API from any programming language. In our documentation we provide working code samples in PHP, C# and plain HTTP.

So if I understand correctly I have to use the HTTP code? 

This is an example for an order:

Example

To create an order, you must POST the order details to the API. We recommend supplying JSON data, but XML is also supported. Make sure your Content-Type and Accept HTTP headers are set correctly.

Request:

image.pngimage.png

Just to be sure, when I follow your steps it will work?

 

Thanks again for putting your time into helping me!

0 Likes
Guillermo31
New Member
6 0 0

I have not that many knowledge about Api's. So maybe with these screenshots I can clear things up for you what I need to do.

Also I don't know if I need to have some kind of code program to edit the code or whatever. 

Basically the only knowledge I have right now is the things that are in the screenshots.

The first thing I have to do is to authenticate the API or something:

image.png

 

 

 

 

 

 

 

 

 

 

image.png

 

 

 

 

 

 

 

 

 

Maybe this can help you understand more of what I need to do?

0 Likes
policenauts
Pathfinder
108 6 19

You are asking a lot, but I will try to help because I was also once a beginner learning about APIs and OAuth2. Here is what I would do:

  • Download and install a program called Postman. This will help you manually send http requests and test your API calls
  • Use Postman to follow the steps in their http Authentication section. Make a request to https://test.printapi.nl/v2/oauth using your app's client_id and secret (you should have this after you register with them)
  • Then they will provide you with a "token" that expires in 4 hours which you can use to make actual requests to their API
  • Then practice making a test request in Postman to the print API and get that working. 

Once you have that working, you will have figured out how to authenticate manually and send requests manually. Now, you will want to figure out how to do this programmatically with the Shopify order data after an order is created.

  • You mentioned you don't even have a way to write any code. As a beginner, I suggest using Google Apps Script (script.google.com) and create a new script file
  • Read the documentation for Google Apps Scripts and publish a public web app URL set to anyone, even anonymous
  • Manually create a webhook for orders/create using the Shopify Admin (this is well documented) and for the endpoint set it to your Google Apps Script URL. Now, whenever a Shopify order is created, it will send the order details to that URL
  • Read the documentation for Google Apps Scripts doPost(e) which lets you handle a POST request to your script file
  • Also read the documentation for UrlFetchApp. This will allow you to write Javascript to make your API requests (as you have done manually using Postman). 

Essentially, you want the code in your script file to handle the request from Shopify each time and programmatically:

  1. Parse the Shopify order data into your desired payload that your print API will understand
  2. Re-authenticate with the print OAuth each time to get a new access token (since theirs is always going to expire) 
  3. Use that access token to then make the http print request to the print API with the actual Shopify order data

You will run into a lot questions and errors because you are learning many things (basic Javascript, Postman, fetch requests, JSON, Apps Script, etc.). You will find all the answers on Stackoverflow. Don't give up. Good luck. 

0 Likes
Guillermo31
New Member
6 0 0

Thank you so much for your time and effort!

I will give it a try!

0 Likes