FedEx Package Rate Integration with NetSuite direct integrate by WebServices
Quick TECHNICAL Note
Reality: UPS only support WebServices integration(or window platform exe application: FedEx Ship Manager® Lite), friendly for JAVA, PHP or C#.
We need to calling UPS SOAP services in NetSuite directly, so there is JSON -> XML for input expected XML parameters and parse API return result XML -> JSON action.
Different from UPS, There is high request for xml's element order/sequence for FedEx API.
This's a re-usable framework for intergration with WebServices platform/application.
Registration for the Developer Keys
We will need registration on webside got
1 2 | Developer Test Key: PFPtfQE9ME1N**** Required for FedEx Web Services for Intra Country Shipping in US and Global |
and the Email Box:
1 2 3 4 5 6 7 8 9 10 11 | Title: Your Developer Test Key Registration is complete Test Account Information <spacer.gif> Test URL: https: //wsbeta.fedex.com:443/web-services Test Password: H6F4kyFrYIQxALXOTbH53**** FedEx Web Services Testing Information: FedEx Shipping Account Number: **0088000 FedEx Meter Number: ***2012** |
On NetSuite Side we are targeting to achieve xml files like the sample:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | Example 1:Rate Request <SOAP-ENV:Envelope xmlns:SOAP-ENV= "http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP- ENC= "http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd= "http://www.w3.org/2001/XMLSchema" xmlns= "http://fedex.com/ws/rate/v28" > <SOAP-ENV:Body> <RateRequest> <WebAuthenticationDetail> <ParentCredential> <Key>XXXXXX</Key> <Password>XXXXXX</Password> </ParentCredential> <UserCredential> <Key>XXXXXX</Key> <Password>XXXXXX</Password> </UserCredential> </WebAuthenticationDetail> <ClientDetail> <AccountNumber>XXXXXX</AccountNumber> <MeterNumber>XXXXXX</MeterNumber> </ClientDetail> <TransactionDetail> <CustomerTransactionId>RateRequest_v28</CustomerTransactionId> </TransactionDetail> <Version> <ServiceId>crs</ServiceId> <Major>28</Major> <Intermediate>0</Intermediate> <Minor>0</Minor> </Version> <RequestedShipment> <ShipTimestamp>2020-02-25T12:34:56-06:00</ShipTimestamp> <DropoffType>REGULAR_PICKUP</DropoffType> <ServiceType>PRIORITY_OVERNIGHT</ServiceType> <PackagingType>FEDEX_BOX</PackagingType> <TotalWeight> <Units>LB</Units> <Value>20.0</Value> </TotalWeight> <Shipper> <AccountNumber>XXXXXX</AccountNumber> <Contact> <CompanyName>FedEx-WAPI</CompanyName> <PhoneNumber>XXXXXX</PhoneNumber> </Contact> <Address> <StreetLines>SN2000 Test Meter 8</StreetLines> <StreetLines>10 Fedex Parkway</StreetLines> <City>AUSTIN</City> <StateOrProvinceCode>TX</StateOrProvinceCode> <PostalCode>XXXXXX</PostalCode> <CountryCode>US</CountryCode> </Address> </Shipper> <Recipient> <AccountNumber>XXXXXX</AccountNumber> <Contact> <PersonName>Recipient Contact</PersonName> <PhoneNumber>XXXXXX</PhoneNumber> </Contact> <Address> <StreetLines>Recipient Address Line 1</StreetLines> <StreetLines>Recipient Address Line 2</StreetLines> <City>Collierville</City> <StateOrProvinceCode>TN</StateOrProvinceCode> <PostalCode>XXXXXX</PostalCode> <CountryCode>US</CountryCode> </Address> </Recipient> <ShippingChargesPayment> <PaymentType>SENDER</PaymentType> <Payor> <ResponsibleParty> <AccountNumber>XXXXXX</AccountNumber> <Tins> <TinType>BUSINESS_STATE</TinType> <Number>123456</Number> </Tins> </ResponsibleParty> </Payor> </ShippingChargesPayment> <RateRequestTypes>LIST</RateRequestTypes> <PackageCount>1</PackageCount> <RequestedPackageLineItems> <SequenceNumber>1</SequenceNumber> <GroupNumber>1</GroupNumber> <GroupPackageCount>1</GroupPackageCount> <Weight> <Units>LB</Units> <Value>20.0</Value> </Weight> <Dimensions> <Length>12</Length> <Width>12</Width> <Height>12</Height> <Units>IN</Units> </Dimensions> <ContentRecords> <PartNumber>XXXXXX</PartNumber> <ItemNumber>XXXXXX</ItemNumber> <ReceivedQuantity>12</ReceivedQuantity> <Description>ContentDescription</Description> </ContentRecords> </RequestedPackageLineItems> </RequestedShipment> </RateRequest> </SOAP-ENV:Body> |
And all above xml element is dynamically transfered from NetSuite Sales Order data(and also data from location, currency, custom record types, settings), We got those data(in expected order), using the Google Project's X2JS to convert from JSON to XML.
Next resolve the across domain ajax call by using NetSuite 2.0 API https.post
1 2 3 4 5 6 7 8 9 | var response = https.post({ url: 'https://wsbeta.fedex.com:443/web-services' , body: new X2JS().json2xml_str(PostDataObj), headers: { "Accept" : "image/gif, image/jpeg, image/pjpeg, text/plain, text/html, */*" , "Content-Type" : "text/xml" , "Access-Control-Allow-Origin" : '*' , } }); |
Need to thanks this thread for useful notes: https://stackoverflow.com/questions/62523251/creating-a-http-post-call-for-fedex-web-services
FedEx Webservices Errors
- Response Code 400 or 500
- Accross domain Error
- Schema Error
-
<cause>UnrecoverableClientError</cause>
<code>SchemaError</code>
<desc>validation failure for RateRequest Error:cvc-complex-type.2.4.a: Invalid content was found starting with element- Check the XML object sent to FedEx, the order of the element MUST match to the WDSL schema
- Check the XML object elements if there is addtional property
- FedEx 404 Unrecoverable ClientError
- Double check the target server url address
- test url: https://wsbeta.fedex.com:443/web-services
- production url: https://ws.fedex.com:443/web-services
Share tools used between XML and JSON
- Testing/xmlTOjson/jsonTOxml: https://peterdaugaardrasmussen.com/json2xml/
- Source Code: https://github.com/abdolence/x2js
- Useful Javascript framework for convention between XML and JSON
- Format XML: https://jsonformatter.org/xml-formatter
- Format JSON: https://www.sojson.com/json/json_online.html
- XML compare/diff https://extendsclass.com/xml-diff.html
- Be careful, the result of the xml diff is not in element order, the diff not acurate for FedEx test
- Comparing XML files: https://extendsclass.com/xml-diff.html
- POSTMAN simulate and compare the input and output
- Powerful and Easy to use
- XML Formatter https://www.freeformatter.com/xml-formatter.html
- Make XML clean and clear
- JSON Reviewer/Formatter http://jsonviewer.stack.hu
- Clean and clear
- JSON to XML https://www.convertjson.com/json-to-xml.htm
Estimate Rate
- UPS https://www.theupsstore.com/tools/estimate-shipping-cost
- FedEx https://www.fedex.com/en-us/online/rating.html
Integrate with existing UPS integration
While end-use switching shipping carries, we need to clean up the backend package list data and rebuild for current shipping carrier, since UPS and FedEx are using DIFFERENT formating and propertys.
本文来自博客园,作者:CarlZeng,转载请注明原文链接:https://www.cnblogs.com/backuper/p/FedEx_Package_Rate_Integration_with_NetSuite.html
需求沟通链接 扫客服加群:

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话