Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Send UBL 2.1 via API POST
Message
From
02/12/2021 06:55:27
 
 
To
30/11/2021 09:53:11
General information
Forum:
Visual FoxPro
Category:
XML, XSD
Miscellaneous
Thread ID:
01682832
Message ID:
01682890
Views:
47
>Hi Antonio,
>

>I've try (many solution, this is one), but this code in VFP - not working:
>
>
>srcFile = [MyUBL2-1-File.xml]
>data = Filetostr(m.srcFile)
>fileName = justfName(m.srcFile)
>boundary = "----WebKitFormBoundary7MA4YWxkTrZu0gW"   
>
>TEXT TO m.lcContent TEXTMERGE NOSHOW
>----WebKitFormBoundary7MA4YWxkTrZu0gW
>Content-Disposition: form-data; name="data"; filename="MyUBL2-1-File.xml"
>Content-Type: text/xml
>
><<data>>
>----WebKitFormBoundary7MA4YWxkTrZu0gW
>Content-Disposition: form-data; name="type"
>
>0
>----WebKitFormBoundary7MA4YWxkTrZu0gW
>Content-Disposition: form-data; name="sef"
>
>1
>----WebKitFormBoundary7MA4YWxkTrZu0gW
>Content-Disposition: form-data; name="contacts[0][email]"
>
>MyEmailAddress@MyDomen4Email.rs
>----WebKitFormBoundary7MA4YWxkTrZu0gW
>Content-Disposition: form-data; name="contacts[0][name]"
>
>FirstName LastName
>----WebKitFormBoundary7MA4YWxkTrZu0gW
>ENDTEXT
>
[...]

>
>But if I make it from a cURL (from PostMan) .bat file - then it works
>

Two things for you to try with your VFP solution:

a) the last boundary must be

----WebKitFormBoundary7MA4YWxkTrZu0gW--

(note the two final dashes '--').

b) you must insert a final blank line so that the TEXT .. ENDTEXT construct creates an additional (but required) CRLF.

That is:
----WebKitFormBoundary7MA4YWxkTrZu0gW--

ENDTEXT
>
>If you have an idea how to convert C # code to VFP - it would be great.
>

Porting the C# code into VFP requires writing a REST class for VFP, similar in specs to the .NET class. I think there are a few classes or functions out there for the urlencoding EncType, adding the multipart EncType wouldn't be too difficult, probably.
**-------------------------------

I do as you stated, but I get an error:

m.loXMLHTTP.statustext Unprocessable Entity
m.loXMLHTTP.Status 422
m.loXMLHTTP.responseTExt {"status":"failed","error":{"data":["Parametar data je obavezan"],"type":["Parametar type je obavezan"],"sef":["Parametar sef je obavezan"],"contacts":["Parametar contacts je obavezan"]}}


this is xml (part of the file):
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="data"; filename="My_Ubl_File.xml"
Content-Type: text/xml

<?xml version="1.0" encoding="utf-8"?>
<Invoice xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
	<cbc:ID>2118495-10</cbc:ID>
	<cbc:IssueDate>2021-10-23</cbc:IssueDate>
	<cbc:DueDate>2021-10-26</cbc:DueDate>
	<cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
	<cbc:Note></cbc:Note>
	<cac:PaymentMeans>
		<cbc:PaymentMeansCode>42</cbc:PaymentMeansCode>		
		<cbc:InstructionNote>Nalogom</cbc:InstructionNote>
	<cac:TaxTotal>
		<cbc:TaxAmount currencyID="RSD">180.0000</cbc:TaxAmount>
		<cac:TaxSubtotal>
			<cbc:TaxableAmount currencyID="RSD">900.0000</cbc:TaxableAmount>
			<cbc:TaxAmount currencyID="RSD">180.0000</cbc:TaxAmount>
			<cac:TaxCategory>
				<cbc:ID>S</cbc:ID>
				<cbc:Percent>20</cbc:Percent>
				<cac:TaxScheme>
					<cbc:ID>VAT</cbc:ID>
				</cac:TaxScheme>
			</cac:TaxCategory>
		</cac:TaxSubtotal>
	</cac:TaxTotal>
	<cac:LegalMonetaryTotal>
		<cbc:LineExtensionAmount currencyID="RSD">900.0000</cbc:LineExtensionAmount>
		<cbc:TaxExclusiveAmount currencyID="RSD">900.0000</cbc:TaxExclusiveAmount>
		<cbc:TaxInclusiveAmount currencyID="RSD">1080.0000</cbc:TaxInclusiveAmount>
		<cbc:AllowanceTotalAmount currencyID="RSD">0.0000</cbc:AllowanceTotalAmount>
		<cbc:ChargeTotalAmount currencyID="RSD">0.0000</cbc:ChargeTotalAmount>
		<cbc:PrepaidAmount currencyID="RSD">1080.0000</cbc:PrepaidAmount>
		<cbc:PayableAmount currencyID="RSD">0.0000</cbc:PayableAmount>
	</cac:LegalMonetaryTotal>
		<cac:InvoiceLine>
			<cbc:ID>1</cbc:ID>
		</cac:InvoiceLine>
</Invoice>
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="type"

0
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="sef"

1
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="contacts[0][email]"

myemailaddress@mydomain.rs
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="contacts[0][name]"

FirstName Secondname
----WebKitFormBoundary7MA4YWxkTrZu0gW--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform