API Config Module for real time integration of Product Sync from NetSuite to Mearsk WMS : Create/Update/Delete

const mearskAPIObj = {            
 getBasicAuthorisation: function () {
                return encode.convert({
                    string: mearskAPIObj.Authentication.username + ":" +    mearskAPIObj.Authentication.password,
                    inputEncoding: encode.Encoding.UTF_8,
                    outputEncoding: encode.Encoding.BASE_64
                })
            },

            getBearerAuthorization: function () {
                var createResponse = https.post({
                    url:mearskAPIObj.Authentication.url +"/a/rgn/a/p/v1/oa2token",
                    headers: {
                        "Content-Type": "application/x-www-form-urlencoded",
                        "Authorization": "Basic " + mearskAPIObj.getBasicAuthorisation(),
                    },
                    body:{
                        "grant_type":"client_credentials"
                    }
                });
               
                var response = JSON.parse(createResponse.body)
                var token = response.access_token
              
                return token;
            },

            createMearskItem: function (itemDetails) {
                var createItemResponse = https.post({
                    url: mearskAPIObj.Authentication.url + "/wms/uae/madlh/p/v1/ProductCreate_MADIAE" ,
                    headers: {
                        "Accept": "application/json",
                        "Content-Type": "application/json",
                        "Authorization": "Bearer " + mearskAPIObj.getBearerAuthorization(),
                    },
                    body: JSON.stringify(itemDetails)
                });
                
                var ItemResponse = JSON.parse(createItemResponse.body);
                
                return ItemResponse;
            }
}
return mearskAPIObj;

Leave a comment

Your email address will not be published. Required fields are marked *