使用联邦快递API和Power Query发布XML跟踪请求

使用联邦快递API和Power Query发布XML跟踪请求,xml,api,xmlhttprequest,powerquery,fedex,Xml,Api,Xmlhttprequest,Powerquery,Fedex,我花了一个星期的大部分时间试图弄明白这件事,但仍然没有做到。我正在尝试使用XML方法在MS Excel Power Query中使用联邦快递的Track API。我已经完成了获取测试凭证和产品凭证的所有过程 感谢@Diegocolaantoni对其他用户的惊人反馈,我终于想出了以下代码: <?xml version="1.0" encoding="UTF-8"?> <TrackRequest xmlns:xsi=&qu

我花了一个星期的大部分时间试图弄明白这件事,但仍然没有做到。我正在尝试使用XML方法在MS Excel Power Query中使用联邦快递的Track API。我已经完成了获取测试凭证和产品凭证的所有过程

感谢@Diegocolaantoni对其他用户的惊人反馈,我终于想出了以下代码:

     <?xml version="1.0" encoding="UTF-8"?>
     <TrackRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://fedex.com/ws/track/v19">
           <WebAuthenticationDetail>
                <UserCredential>
                    <Key>MYKEY</Key>
                    <Password>MYPWD</Password>
                </UserCredential>
            </WebAuthenticationDetail>
            <ClientDetail>
                <AccountNumber>MYACCOUNT</AccountNumber>
                <MeterNumber>MYMETER</MeterNumber>
            </ClientDetail>
            <TransactionDetail>
                <CustomerTransactionId>TestTest</CustomerTransactionId>
            </TransactionDetail>
            <Version>
                <ServiceId>trck</ServiceId>
                <Major>19</Major>
                <Intermediate>0</Intermediate>
                <Minor>0</Minor>
            </Version>
            <SelectionDetails>
                <PackageIdentifier>
                    <Type>TRACKING_NUMBER_OR_DOORTAG</Type>
                    <Value>785459309647</Value>
                </PackageIdentifier>
            </SelectionDetails>
        </TrackRequest>
由于它与邮递员一起工作,我认为这与请求本身有关,但我真的不明白哪里出了问题

下面是完整的Excel Power查询

let
   url = "https://ws.fedex.com:443/xml",
   Body = Text.ToBinary("
        <?xml version=""1.0"" encoding=""UTF-8""?>
        <TrackRequest xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns=""http://fedex.com/ws/track/v19"">
            <WebAuthenticationDetail>
                <UserCredential>
                    <Key>MYKEY</Key>
                    <Password>MYPWD</Password>
                </UserCredential>
            </WebAuthenticationDetail>
            <ClientDetail>
                <AccountNumber>MYACCT</AccountNumber>
                <MeterNumber>MYMETER</MeterNumber>
            </ClientDetail>
            <TransactionDetail>
                <CustomerTransactionId>PruebaPrueba</CustomerTransactionId>
            </TransactionDetail>
            <Version>
                <ServiceId>trck</ServiceId>
                <Major>19</Major>
                <Intermediate>0</Intermediate>
                <Minor>0</Minor>
            </Version>
            <SelectionDetails>
                <PackageIdentifier>
                    <Type>TRACKING_NUMBER_OR_DOORTAG</Type>
                    <Value>785459309647</Value>
                </PackageIdentifier>
            </SelectionDetails>
        </TrackRequest>
    "),
    Source = Web.Contents(url, [Headers=[Accept="image/gif, image/jpeg, image/pjpeg, text/plain, text/html, */*", #"Content-Type"="text/xml"], Content = Body])
in
    Source
let
url=”https://ws.fedex.com:443/xml",
Body=Text.ToBinary(“
我的钥匙
MYPWD
MYACCT
万用表
普鲁巴普鲁巴
trck
19
0
0
追踪号码或门牌
785459309647
"),
Source=Web.Contents(url,[Headers=[Accept=“image/gif,image/jpeg,image/pjpeg,text/plain,text/html,*/*”,#“Content Type”=“text/xml”],Content=Body])
在里面
来源

就请求主体而言,联邦快递XML普通Web服务非常具体:XML开头的空行可能导致500响应

这就是Excel Power查询的情况,请参见实际xml前后的新行。移除它们就可以了。也就是说,这应该是可行的:

let
   url = "https://ws.fedex.com:443/xml",
   Body = Text.ToBinary("<?xml version=""1.0"" encoding=""UTF-8""?>
        <TrackRequest xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns=""http://fedex.com/ws/track/v19"">
            <WebAuthenticationDetail>
                <UserCredential>
                    <Key>MYKEY</Key>
                    <Password>MYPWD</Password>
                </UserCredential>
            </WebAuthenticationDetail>
            <ClientDetail>
                <AccountNumber>MYACCT</AccountNumber>
                <MeterNumber>MYMETER</MeterNumber>
            </ClientDetail>
            <TransactionDetail>
                <CustomerTransactionId>PruebaPrueba</CustomerTransactionId>
            </TransactionDetail>
            <Version>
                <ServiceId>trck</ServiceId>
                <Major>19</Major>
                <Intermediate>0</Intermediate>
                <Minor>0</Minor>
            </Version>
            <SelectionDetails>
                <PackageIdentifier>
                    <Type>TRACKING_NUMBER_OR_DOORTAG</Type>
                    <Value>785459309647</Value>
                </PackageIdentifier>
            </SelectionDetails>
        </TrackRequest>"),
    Source = Web.Contents(url, [Headers=[Accept="image/gif, image/jpeg, image/pjpeg, text/plain, text/html, */*", #"Content-Type"="text/xml"], Content = Body])
in
    Source
let
url=”https://ws.fedex.com:443/xml",
Body=Text.ToBinary(“
我的钥匙
MYPWD
MYACCT
万用表
普鲁巴普鲁巴
trck
19
0
0
追踪号码或门牌
785459309647
"),
Source=Web.Contents(url,[Headers=[Accept=“image/gif,image/jpeg,image/pjpeg,text/plain,text/html,*/*”,#“Content Type”=“text/xml”],Content=Body])
在里面
来源

我感到受宠若惊!谢谢虽然我现在也感觉到了压力。不幸的是,我没有权力去尝试你的代码,我只能看着它。在我看来,正文开头和结尾的新行可能是您的查询失败的原因。Try:Body=Text.ToBinary("嗯,@Diego先生,你真是个天使。联邦快递应该付钱给你…我按照你的建议做了,就是把整个身体贴在
文本中。ToBinary
成功了…所以是的,Excel函数将文本转换为二进制编码,换行符也被忽略了,这就是为什么它会在那里工作。如果你在意的话诸如此类的事情,你可以把你的评论作为一个答案,这样我就可以把它标记为解决方案。如果没有,那么非常感谢你。
let
   url = "https://ws.fedex.com:443/xml",
   Body = Text.ToBinary("<?xml version=""1.0"" encoding=""UTF-8""?>
        <TrackRequest xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns=""http://fedex.com/ws/track/v19"">
            <WebAuthenticationDetail>
                <UserCredential>
                    <Key>MYKEY</Key>
                    <Password>MYPWD</Password>
                </UserCredential>
            </WebAuthenticationDetail>
            <ClientDetail>
                <AccountNumber>MYACCT</AccountNumber>
                <MeterNumber>MYMETER</MeterNumber>
            </ClientDetail>
            <TransactionDetail>
                <CustomerTransactionId>PruebaPrueba</CustomerTransactionId>
            </TransactionDetail>
            <Version>
                <ServiceId>trck</ServiceId>
                <Major>19</Major>
                <Intermediate>0</Intermediate>
                <Minor>0</Minor>
            </Version>
            <SelectionDetails>
                <PackageIdentifier>
                    <Type>TRACKING_NUMBER_OR_DOORTAG</Type>
                    <Value>785459309647</Value>
                </PackageIdentifier>
            </SelectionDetails>
        </TrackRequest>"),
    Source = Web.Contents(url, [Headers=[Accept="image/gif, image/jpeg, image/pjpeg, text/plain, text/html, */*", #"Content-Type"="text/xml"], Content = Body])
in
    Source