Savon::SOAPFault: (s:Client) Element 'RequestContext' is missing from the header - ruby-on-rails-3

I am using savon gem in rails to call purolator E-Ship soap APIs,
gem 'savon', version 2.12.0
Here is my code sample where I am calling the actual API
#client = Savon.client(wsdl: "#{Rails.root.to_s}/app/carriers/wsdls/purolator/tracking_service/TrackingServiceDev.wsdl",
"soap_header" => {
"RequestContext" => {
"Version" => '1.2',
"Language" => 'en_US',
"GroupID" => 'xxx',
"RequestReference" => 'Rating Example'
}
},
:basic_auth => ["xxxxxxxxxx", "xxxxxxxxx"],
:log => true, :pretty_print_xml => true, :element_form_default => :unqualified)
body = {
"PIN" => {
"Value" => 329014521622
}
}
#client.call(:get_delivery_details, message: body).body
Here is the Request XML that is being generated and displayed by Savon
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:q12="http://purolator.com/pws/service/v1" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="http://purolator.com/pws/datatypes/v1" xmlns:ins1="http://www.microsoft.com/practices/EnterpriseLibrary/2007/01/wcf/validation" xmlns:ins2="http://schemas.datacontract.org/2004/07/Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF">
<env:Header>
<RequestContext>
<Version>1.2</Version>
<Language>en_US</Language>
<GroupID>xxx</GroupID>
<RequestReference>Rating Example</RequestReference>
</RequestContext>
</env:Header>
<env:Body>
<q12:GetDeliveryDetailsRequest>
<PIN>
<Value>329014521622</Value>
</PIN>
</q12:GetDeliveryDetailsRequest>
</env:Body>
</env:Envelope>
and here is the response I am getting back from the API
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
<faultstring xml:lang="en-CA">Element 'RequestContext' is missing from the header</faultstring>
</s:Fault>
</s:Body>
</s:Envelope>
API is throwing an error message that Element 'RequestContext' is missing from the header but I provided this header and it is displayed in request as well.
Can anyone please point me in the right direction and let me know what I am missing here.

When adding a namespace it works:
'purolator:RequestContext' => {
'purolator:Version' => '1.2',
'purolator:Language' => 'en_US',
'purolator:GroupID' => 'xxx',
'purolator:RequestReference' => 'Rating Example'
}

Related

React native fetch response bad characters

So i need to communicate with server. Here is my code
fetch('http://localhost:444/xml', {
method: 'POST',
headers: {
'STW-Authorization': 'Basic YmFybmk6YmFybmkxNTY=',
'Content-Type': 'text/xml',
},
})
.then(response => {
console.log(response.status)
return response.text()
})
.then(data => {
console.log(data)
})
And this prints badly encoded characters like �
Here is the result.
<?xml version="1.0" encoding="Windows-1250"?>
<rsp:responsePack version="2.0" id="" state="error" programVersion="12003.3 (21.11.2018)" ico="" note="Nebol n�jden� �iadny s�bor pre spracovanie." xmlns:rsp="http://www.stormware.cz/schema/version_2/response.xsd" xmlns:rdc="http://www.stormware.cz/schema/version_2/documentresponse.xsd" xmlns:typ="http://www.stormware.cz/schema/version_2/type.xsd" xmlns:lst="http://www.stormware.cz/schema/version_2/list.xsd" xmlns:lStk="http://www.stormware.cz/schema/version_2/list_stock.xsd" xmlns:lAdb="http://www.stormware.cz/schema/version_2/list_addBook.xsd" xmlns:acu="http://www.stormware.cz/schema/version_2/accountingunit.xsd" xmlns:inv="http://www.stormware.cz/schema/version_2/invoice.xsd" xmlns:vch="http://www.stormware.cz/schema/version_2/voucher.xsd" xmlns:int="http://www.stormware.cz/schema/version_2/intDoc.xsd" xmlns:stk="http://www.stormware.cz/schema/version_2/stock.xsd" xmlns:ord="http://www.stormware.cz/schema/version_2/order.xsd" xmlns:ofr="http://www.stormware.cz/schema/version_2/offer.xsd" xmlns:enq="http://www.stormware.cz/schema/version_2/enquiry.xsd" xmlns:vyd="http://www.stormware.cz/schema/version_2/vydejka.xsd" xmlns:pri="http://www.stormware.cz/schema/version_2/prijemka.xsd" xmlns:bal="http://www.stormware.cz/schema/version_2/balance.xsd" xmlns:pre="http://www.stormware.cz/schema/version_2/prevodka.xsd" xmlns:vyr="http://www.stormware.cz/schema/version_2/vyroba.xsd" xmlns:pro="http://www.stormware.cz/schema/version_2/prodejka.xsd" xmlns:con="http://www.stormware.cz/schema/version_2/contract.xsd" xmlns:adb="http://www.stormware.cz/schema/version_2/addressbook.xsd" xmlns:prm="http://www.stormware.cz/schema/version_2/parameter.xsd" xmlns:lCon="http://www.stormware.cz/schema/version_2/list_contract.xsd" xmlns:ctg="http://www.stormware.cz/schema/version_2/category.xsd" xmlns:ipm="http://www.stormware.cz/schema/version_2/intParam.xsd" xmlns:str="http://www.stormware.cz/schema/version_2/storage.xsd" xmlns:idp="http://www.stormware.cz/schema/version_2/individualPrice.xsd" xmlns:sup="http://www.stormware.cz/schema/version_2/supplier.xsd" xmlns:prn="http://www.stormware.cz/schema/version_2/print.xsd" xmlns:sEET="http://www.stormware.cz/schema/version_2/sendEET.xsd" xmlns:act="http://www.stormware.cz/schema/version_2/accountancy.xsd" xmlns:bnk="http://www.stormware.cz/schema/version_2/bank.xsd" xmlns:sto="http://www.stormware.cz/schema/version_2/store.xsd" xmlns:grs="http://www.stormware.cz/schema/version_2/groupStocks.xsd" xmlns:acp="http://www.stormware.cz/schema/version_2/actionPrice.xsd" xmlns:csh="http://www.stormware.cz/schema/version_2/cashRegister.xsd" xmlns:bka="http://www.stormware.cz/schema/version_2/bankAccount.xsd" xmlns:ilt="http://www.stormware.cz/schema/version_2/inventoryLists.xsd" xmlns:nms="http://www.stormware.cz/schema/version_2/numericalSeries.xsd" xmlns:pay="http://www.stormware.cz/schema/version_2/payment.xsd" xmlns:mKasa="http://www.stormware.cz/schema/version_2/mKasa.xsd" xmlns:gdp="http://www.stormware.cz/schema/version_2/GDPR.xsd" xmlns:ftr="http://www.stormware.cz/schema/version_2/filter.xsd"></rsp:responsePack>
The note text should be
Nebol nájdené žiadny súbor pre spracovanie.
Please help me found out the answer.

How to send a XML API request in cypress (SOAP API)

I need to send XML requests in cypress but I don't know how to do that. Generally, I worked with cy.request with rest API's. Is it possible to send XML requests in cypress?
How can I do that? Any help would be great!! An example would be lovely!
I left an example request that I use in postman without a problem. But to automate my test I need to send that request in cypress.
(POST request)
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<MT_ServiceOrderInitiaionandMgmt xmlns:prx="***"
xmlns="***">
<VKONTO>***</VKONTO>
<NAME>***</NAME>
<PORTION>***</PORTION>
<AKLASSE/>
<DATUM>***</DATUM>
<Contact>
<RELTYP/>
<NAME>***</NAME>
<TEL_NUMBER>***</TEL_NUMBER>
<PHTYPE>***</PHTYPE>
<SMTP_ADDR>***</SMTP_ADDR>
</Contact>
<LifeSupportIndicator/>
<QMNUM>***</QMNUM>
<QMART>***</QMART>
<MNCOD>***</MNCOD>
<QMTXT>***</QMTXT>
<NOTST>***</NOTST>
<ServiceAddress>
<STREET>***</STREET>
<CITY1>***</CITY1>
<REGIO>***</REGIO>
<LOCATION>***</LOCATION>
<POST_CODE1>***</POST_CODE1>
<HAUS_NUM2/>
</ServiceAddress>
<ABLEINH>***</ABLEINH>
<CO_ASTTX>***</CO_ASTTX>
<STRMN/>
<STRUR>***</STRUR>
<LTRMN/>
<LTRUR>***</LTRUR>
<ERDAT>***</ERDAT>
<MZEIT>***</MZEIT>
<ERNAM>***</ERNAM>
<AEDAT/>
<AEZEIT>***</AEZEIT>
<AENAM/>
<PPSID>***</PPSID>
<ExternalReference>
<ID></ID>
<SYSNAME>***</SYSNAME>
<TYPE>***</TYPE>
</ExternalReference>
<REFNUM/>
<PRIOK/>
<LONT_TXT>***</LONT_TXT>
<PREMS>***</PREMS>
<Meters>
<TPLNR>***</TPLNR>
<VBSARTTEXT>***</VBSARTTEXT>
<TERMSCHL/>
<DLNOT>***</DLNOT>
<STORT>***</STORT>
<KTEXT>***</KTEXT>
<EINBDAT>***</EINBDAT>
<ISPRIM>***</ISPRIM>
<SERNR>***</SERNR>
<MET_SERNR></MET_SERNR>
<HERST>***</HERST>
<TYPBZ/>
<PREISKLA>***</PREISKLA>
<EQKTX>***</EQKTX>
<DSTAT>***</DSTAT>
<MEINS>***</MEINS>
<STANZVORE>***</STANZVORE>
<ISTABLART>***</ISTABLART>
<V_ZWSTAND></V_ZWSTAND>
<E_ZWSTANDO>***</E_ZWSTANDO>
<E_ZWSTANDU>***</E_ZWSTANDU>
<E_VERBERW>***</E_VERBERW>
<ADAT>***</ADAT>
<ATIM>***</ATIM>
<MTU_TPLNR/>
<MTUSN>***</MTUSN> >
<MTU_EQKTX/>
<MTU_EINBDAT>***11</MTU_EINBDAT>
<MTU_SERNR></MTU_SERNR>
<PORT>***</PORT>
</Meters>
</MT_ServiceOrderInitiaionandMgmt>
</soap:Body>
</soap:Envelope>
there are no big differences between standard rest API requests and XML Soap API requests.
cy.request({
method: "POST",
url: "Request URL",
headers: {
"Content-Type": "text/xml;charset=UTF-8",
authorization: "Bearer " + "auth token",
SOAPAction: "serviceOrder",
},
//you have to write your XML body here as a string. I leave a small part
//of my API's body to be an example if someone needs it in the future.
body: '<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><MT_ServiceOrderInitiaionandMgmt xmlns:prx="***" xmlns="***"><VKONTO>5883000</VKONTO><NAME>cypress</NAME><PORTION>MBC87<MTU_EINBDAT>2002-05-11</MTU_EINBDAT><MTU_SERNR></MTU_SERNR><PORT>1</PORT></Meters></MT_ServiceOrderInitiaionandMgmt></soap:Body></soap:Envelope>',
})
.then((res) => {
//Do something with the response.
});

unable to access data from soap api response json

I am using soap api request and its returning me this response.
That's my laravel controller code.
public function testResponseSRI($phone, $code)
{
$url = 'https://tamimahsms.com/user/bulkpush.asmx?wsdl';
$body = '
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SendSMS xmlns="https://www.tamimahsms.com/">
<UserName>username</UserName>
<Password>password</Password>
<Message>test message with code '.$code.'</Message>
<Priority>1</Priority>
<Schdate>07/18/2018</Schdate>
<Sender>AsifSource</Sender>
<AppID>123456</AppID>
<SourceRef>7654321</SourceRef>
<MSISDNs>'.$phone.'</MSISDNs>
</SendSMS>
</soap:Body>
</soap:Envelope>';
$headers = ['Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen($body)];
$result = SoapClientRequest::send($url, $headers, $body);
return response()->json($result);
}
I want to get <StatusCode>00</StatusCode> from body object.
How can I get this?
Thanks
Finally, I figured out. The response was not a regular JSON, firstly convert it:
$data = $jsonResponse->getData();
Then treat it as a regular json. Now I can easily get <StatusCode>00</StatusCode> by using php preg_match
method like this:
if(preg_match("!<StatusCode>(.+)</StatusCode>!i",$data->body,$matches))
{
return $matches[1] // return 00
}

eBay API in Perl - can't use SetShipmentTrackingInfoRequest to update tracking information

I'm trying to figure out why I can't seem to update a tracking number using the eBay API. Here is the page I'm referencing:
http://developer.ebay.com/DevZone/merchant-data/CallRef/SetShipmentTrackingInfo.html
Based on that, I've got the following code in Perl:
use Net::eBay;
my $ebay = new Net::eBay( {
SiteLevel => 'prod',
DeveloperKey => 'x',
ApplicationKey => 'xxxx',
CertificateKey => 'xxx',
Token => 'xxxx',
} );
$ebay->setDefaults( { API => 2, compatibility => 900 } );
my $result = $ebay->submitRequest( "SetShipmentTrackingInfoRequest",
{
DetailLevel => "ReturnAll",
ErrorLevel => "1",
SiteId => "1",
OrderID => 1234546, # not the real order ID I'm using :)
ShipmentTrackingDetails => {
ShipmentTrackingNumber => "12345",
ShippingCarrierUsed => "Hermes"
}
});
print $IN->header;
use Data::Dumper;
print Dumper($result);
When running it, I get an error in $result:
$VAR1 = {
'Errors' => {
'ErrorClassification' => 'RequestError',
'SeverityCode' => 'Error',
'ShortMessage' => 'Unsupported API call.',
'ErrorCode' => '2',
'LongMessage' => 'The API call "SetShipmentTrackingInfoRequest" is invalid or not supported in this release.'
},
'xmlns' => 'urn:ebay:apis:eBLBaseComponents',
'Timestamp' => '2016-10-21 07:03:04',
'Build' => '18007281',
'Version' => '900',
'Ack' => 'Failure'
};
I'm a bit confused, as it looks like SetShipmentTrackingInfoRequest is the API call I need to be making? I've not really done much with the eBay API, so it's possible I'm missing something stupid.
UPDATE: As per feedback below, I'm now using the CompleteSale API call:
http://developer.ebay.com/Devzone/XML/docs/Reference/eBay/CompleteSale.html
my $result = $ebay->submitRequest( "CompleteSale ",
{
DetailLevel => "ReturnAll",
ErrorLevel => "1",
SiteId => "1",
OrderID => 1933420817015,
Shipment => {
ShipmentTrackingDetails => {
ShipmentTrackingNumber => "77293124902615",
ShippingCarrierUsed => "Hermes"
}
}
});
When I run it, I now get the error:
'LongMessage' => 'XML Error Text: "; nested exception is:
org.xml.sax.SAXParseException: Attribute name "Request" associated with an element type "CompleteSale" must be followed by the
\' = \' character.".',
Enabling debugging, the XML being sent is:
<?xml version='1.0' encoding='utf-8'?>
<CompleteSale Request xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>xxxx</eBayAuthToken>
</RequesterCredentials>
<DetailLevel>ReturnAll</DetailLevel>
<ErrorLevel>1</ErrorLevel>
<OrderID>xxxxx</OrderID>
<Shipment>
<ShipmentTrackingDetails>
<ShipmentTrackingNumber>xxxx</ShipmentTrackingNumber>
<ShippingCarrierUsed>Hermes</ShippingCarrierUsed>
</ShipmentTrackingDetails>
</Shipment>
<SiteId>1</SiteId>
</CompleteSale Request>
From looking at the eBay API doc link you posted doesn't the second 'Note' entirely explain why it doesn't work as a single API call?
Note: SetShipmentTrackingInfo cannot be issued on its own like an ordinary API call, using an endpoint
It then goes on to say:
In the Trading API, the CompleteSale call provides similar functionality that you can invoke directly
So perhaps looking there should be the next step

Rails Savon SOAP Authentication

I am developing on Rails 3 and using Savon(savonrb.com)
I need to connect to Web Services via SOAP
Web Services require authentication
I can connect but can't get authonticated...
I used SOAP UI for testing & all works fine.
Here how my Rails code looks like:
client = Savon::Client.new do
wsdl.document = "http://services.blahblah.com/Service.asmx?WSDL"
end
client.wsse.credentials "username", "password", :digest
if response.success?
#soap_status = 'Connected'
#data = response.to_array(:get_brochure_response, :error_message)
end
I get response but :error_message returns Authentication failed...
Here is how it looks in SOAP UI
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ser="http://services.blahblah.com/service">
<soap:Header>
<ser:ICEAuthHeader>
<!--Optional:-->
<ser:Username>username</ser:Username>
<!--Optional:-->
<ser:Password>password</ser:Password>
</ser:ICEAuthHeader>
</soap:Header>
<soap:Body>
<ser:GetBrochure>
<!--Optional:-->
<ser:MappedID>123</ser:MappedID>
</ser:GetBrochure>
</soap:Body>
</soap:Envelope>
Are the username and password sent with the SOAP request in the headers? If so, you could go about doing this when initializing the Savon client (see cannot set SOAP header parameters on savon call):
client = Savon.client(
wsdl: SOAP_WSDL,
endpoint: SOAP_URL,
soap_header: { :username => username, :password => password }
)
Incidentally, if only certain calls need authentication, you can make calls like so:
response = client.call(
:soap_call,
:soap_header => { :username => username, :password => password },
message: {message}
)
You could try this to authenticate using basic auth:
client = Savon::Client.new do
wsdl.document = "http://services.blahblah.com/Service.asmx?WSDL"
http.auth.basic "username", "password"
end
client = Savon.client( wsdl: 'http://service.example.com?wsdl',soap_header: { "AuthenticateRequest" => {"apiKey" => "****** your api *********"}}, pretty_print_xml: true)
client.operations
response = client.call(:function)
here "apiKey" is my prams to authenticate api, your can be different