Integration with ShipStation from Salesforce

ShipStation is a web-based, multi-carrier shipping solution for eCommerce retailers.

Salesforce is a leading cloud sales platform with diverse CRM functionality on multiple devices and a robust app marketplace. With ShipStation you can manage and ship your orders across one or more of your stores. Connect your e-commerce store with ShipStation to import orders and start shipping them.

Salesforce to ShipStation integration process:-

In this process, firstly we collect all information about the ShipStation And fulfil all the requirements which are given below:

1. Firstly we register a developer Account on ShipStation on this URL:

Create My Account

ShipStation also provides a free trial account for 30 days, after 30 days it will be expired.

2. If you have created your developer account successfully, then the next step is you need to go to ‘Setting’ icon then select ‘Account’, under the ‘Account’ section select ‘API Setting’ then you will get an API key and API Secret. Use these in a custom setting in salesforce.

3. Now create webhook, for that click on ‘Setting’ icon then select ‘Integration’, under this select ‘Integration Partners’,
Go to the webhook and add a webhook endpoint.

4. As in the above process when you create a site in salesforce org, you will get “Default Web Address” , insert that URL in this above (“ URL to be called “).
5. After that site Url to be added (“ /services/apexrest/classname ”). In the place of the class name write the name of your class which you want to use for Url Mapping. Click on the Save button.
6. The class which you add in URL, In that class you have to write the logic for creating ShipStation order in Salesforce.
7.  Here is related code for your consideration:

global class ClassName {
global static void shipStationRouted(){
string str = RestContext.request.requestBody.toString();
Map<String, Object> ResultMap =(Map)Json.deserializeUntyped(str);
ShipStation__c ShipStationUser=[select Domain_Name__c,userName__c, password__c from ShipStation__c where isLive__c=true limit 1];
String Header=EncodingUtil.base64Encode(blob.valueOf(ShipStationUser.userName__c +’:’+ShipStationUser.password__c));
String url=String.valueOf(ResultMap.get(‘resource_url’));
String EventType=String.valueOf(ResultMap.get(‘resource_type’));
try {
if(url != null) {
HttpRequest req= new HttpRequest();
req.setHeader(‘Authorization’, ‘Basic ‘+Header);
Http htp= new Http();
HttpResponse res=htp.send(req);
String Respons=res.getBody();
/* Write the code which you want to implement */
catch(exception e){}

Callout From Salesforce to Shipstation

1. From Setup, enter Remote Site Settings in the Quick Find box, then click Remote Site Settings.
2. Click New Remote Site.
3. For the remote site name, enter animals_http.
4. For the remote site URL, enter
5. For the description, enter Trailhead animal service: HTTP.
6. Click Save & New.
7. For the second remote site name, enter animals_soap.
8. For the remote site URL, enter
9. For the description, enter Trailhead animal service: SOAP.
10. Click Save.

Here is callout class for your consideration:

public static String createShipOrder(String shipOrderId) {
ShipStation_Orders__c shipVal = new ShipStation_Orders__c();
shipVal =[select id,Name,orderId__c,Order_Number__c,customerUsername__c,modifyDate__c,OwnerId,Contact__c from ShipStation_Orders__c,orderKey__c where id =: shipOrderId LIMIT 1 ];
String Body = orderId=’+shipVal .orderId__c+’&orderKey=’+shipVal .orderKey__c+’&orderNumber=’+shipVal.orderNumber__c;
HttpRequest htt = new HttpRequest();
htt.setHeader(‘Content-Type’, ‘application/x-www-form-urlencoded’);
htt.setHeader(‘Authorization’,’Basic put your secret key here);
Http con = new Http();
HttpResponse hs = new HttpResponse();
hs = con.send(htt);
if(hs.getBody() != null) {
System.debug(‘ — — hs — — -’+hs.getBody());

Now you are connected with ShipStation.

Comments: 6

Leave a comment