CXML請求書にエンコードされた添付ファイルを追加する
請求書cXMLの一部として請求書の添付ファイルを送信する方法を学びます。
概要
Base 64マルチパートを使用して、請求書cXMLの一部として請求書の添付ファイルを送信できます。 3つの入力を取り、添付ファイルと画像スキャン( cXMLではありません)をBase 64マルチパート形式でエンコードする独自のスクリプトを構築する必要があります。 また、スクリプトは、以下のエンコードされた請求書の例に示されているように、ランダムな境界を作成する必要があります。 また、各ファイルに Content - Type と Content - ID を含める必要があります。
スクリプト入力
のマルチパートファイルアップロードを処理する場合、正しい改行文字シーケンスが使用されていることを確認する必要があります。 マルチパート境界を解析するには、改行文字を CRLF (\r\n) に設定する必要があります。 フォーマットが正しくないと、500内部サーバーエラーが発生する可能性があります。
詳細については、 Multipart requests for Windows and Unix based systemsを参照してください。
エンコードされた添付ファイルを含むcXML請求書を生成するには、特定の入力を取り、エンコードされた添付ファイルを含むcXML請求書を生成するスクリプトを作成する必要があります。
通常のcXML請求書ファイルに、添付ファイルと外部画像スキャンの次の要素が含まれていることを確認してください。
<Comments> <Attachment> <URL>https://www.google.com/images/srpr/logo11w.png</URL> //添付ファイルがURLで公開されている場合は、URLを指定します。 </Attachment> <Attachment> <URL>cid: test.pdf</URL> //ローカルに添付ファイルがある場合は、URLにcontent - IDを指定します。 </Attachment> </Comments> <Extrinsic name="ImageScanAttachmentUrl">cid: test.csv</Extrinsic> // ImageScansをcontent - IDで指定します。スクリプト出力
スクリプトは出力をファイルに保存し、curlを使用してバイナリファイルとして顧客のインスタンスに投稿できるようにする必要があります。
curl - X POST - H 'Accept: application/xml' - H 'Content - Type: multipart/related; boundary =<boundary_value_that_you_have>; type = text/xml; start =<cXML_Invoice_content_id>' -- data - binary @<output_file_name>.xml https ://<customer_name>.coupahost.com/cxml/invoicesCXML請求書に添付ファイルを追加し、Postmanでテストする
エンコードされた請求書の例
--ec6xAZMGCwZhdyY0 //Random Boundary Content-type: text/xml; charset=UTF-8 //Content type Content-ID: <payload.xml> //content ID for cXML Invoice file <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE cXML SYSTEM "http://xml.cXML.org/schemas/cXML/1.2.020/InvoiceDetail.dtd"> <cXML version="1.2.020" xml:lang="en-US" timestamp="2018-03-08T13:08:23-08:00" payloadID="2018-03-08T13:08:23-08:00"> <Header> <From> <Credential domain="dwqsdg"> <Identity>vcbv</Identity> </Credential> </From> <To> <Credential domain="vfdfvb"> <Identity>dbfg</Identity> </Credential> </To> <Sender> <Credential domain="dwqsdg"> <Identity>vcbv</Identity> <SharedSecret>fdbgfg</SharedSecret> </Credential> <UserAgent>Coupa Procurement 1.0</UserAgent> </Sender> </Header> <Request deploymentMode="production"> <InvoiceDetailRequest> <InvoiceDetailRequestHeader invoiceDate="2018-03-08T13:08:23-08:00" operation="new" purpose="standard" invoiceOrigin="supplier" invoiceID="COUPATEST21"> <InvoiceDetailHeaderIndicator /> <InvoiceDetailLineIndicator isAccountingInLine="yes" /> <PaymentTerm payInNumberOfDays="30" /> //Lines 35-43 are for Attachments //Use filenames as content-IDs so it's easy to recognizing which content-ID refers to which encoded format <Comments> <Attachment> <URL>https://www.google.com/images/srpr/logo11w.png</URL> </Attachment> <Attachment> <URL>cid:test.pdf</URL> </Attachment> </Comments> <Extrinsic name="ImageScanAttachmentUrl">cid:test.csv</Extrinsic> </InvoiceDetailRequestHeader> <InvoiceDetailOrder> <InvoiceDetailOrderInfo> <OrderReference> <DocumentReference payloadID="2820" /> </OrderReference> </InvoiceDetailOrderInfo> <InvoiceDetailItem quantity="1.0" invoiceLineNumber="1"> <UnitOfMeasure>EA</UnitOfMeasure> <UnitPrice> <Money currency="USD">23.34</Money> </UnitPrice> <InvoiceDetailItemReference lineNumber="1"> <ItemID> <SupplierPartID /> <SupplierPartAuxiliaryID /> </ItemID> <Description xml:lang="en-US">test items s</Description> </InvoiceDetailItemReference> <SubtotalAmount> <Money currency="USD">23.34</Money> </SubtotalAmount> </InvoiceDetailItem> </InvoiceDetailOrder> <InvoiceDetailSummary> <SubtotalAmount> <Money currency="USD">23.34</Money> </SubtotalAmount> <Tax> <Money currency="USD">0</Money> <Description xml:lang="en-US" /> <TaxDetail purpose="tax" category="USD" percentageRate="0" taxPointDate="2018-03-08T13:08:23-08:00"> <TaxableAmount> <Money currency="USD">23.34</Money> </TaxableAmount> <TaxAmount> <Money currency="USD">0</Money> </TaxAmount> <TaxLocation xml:lang="en">USD</TaxLocation> </TaxDetail> </Tax> <NetAmount> <Money currency="USD">23.34</Money> </NetAmount> </InvoiceDetailSummary> </InvoiceDetailRequest> </Request> </cXML> --ec6xAZMGCwZhdyY0 //Boundary is displayed as the cXML Invoice ends here Content-Type: text/plain; charset=utf-8 //This content-type refers the test in file Content-Disposition: inline; filename="test.pdf" //Specify the filename and content-disposition remains smae Content-Transfer-Encoding: base64 //input is encoded in base64 foramt Content-ID: <test.pdf> //which file is encoded below //Base64 multipart encoding starts here ... JVBERi 0 xLjMKJcTl 8 uXrp/Og 0 MTGCjQgMCBvYmoKPDwgL 0 xlbmd 0 aCA 1 IDAg UiAvRmlsdGVyIC 9 GbGF 0 ZURlY 29 kZSA + PgpzdHJlYW 0 KeAHlnGuPJbdxhr/3 r + gYWO + ZxNvb 94 u/SSsntmzBEjxOsIgNYz 0 z 8 trZ 0 UozUja +6 L/7 KRZZTZ 6 +... -- ec 6 xAZMGCwZhdyY 0 // boundary is displayed as above input of file is completed Content - Type: text/plain; charset = utf -8 // This content - type refers the text/details in file Content - Disposition: inline; filename =" test.csv "// Specify the filename and content - disposition remains the same Content - Transfer - Encoding: base 64 // input is encoded in base 64 for the file's encoded for content - id: <test.csv> /which's CjAwMDAxOTQ 0 MjkgMDAwMDAgbiAKMDAwMDE 5 NDk 1 NiAwMDAwMCBuIAowMDAw MTk 1 MjE 4 IDAwMDAwIG 4 gCjAwMDAyMjAyMTQgMDAwMDAgbiAKMDAwMDIyMDY 4 NyAwMDAwMCBuIAowMDAwMjIwOTU 2 IDAwMDAwIG 4 gCjAwMDAyMzc 3 OTYgMDAw... -- ec 6 xAZMGCwZhdyY 0 --/Base 64マルチパートエンコーディングはここで終了します