メインコンテンツまでスキップ

 

 

Coupa Japanese

エンコードされた添付ファイルをcXMLインボイスに追加

概要

Base64マルチパートを使用して、インボイスの添付ファイルをインボイスcXMLの一部として送信できます。3つの入力を受け取り、添付ファイルと画像スキャン(cXMLは除く)をBase64マルチパート形式でエンコードする独自のスクリプトを作成する必要があります。また、スクリプトは、以下のエンコードされたインボイスの例に示すように、ランダムな境界を作成する必要があります。また、各ファイルにContent-TypeContent-IDを含める必要があります。

スクリプト入力

添付ファイルがエンコードされたcXMLインボイスを生成するには、特定の入力を受け取り、エンコードされた添付ファイルを含むcXMLインボイスを生成するスクリプトを作成する必要があります。

通常のcXMLインボイスファイルに、添付ファイルと外部画像スキャンに関する以下の要素が含まれていることを確認します。

<Comments>
  <Attachment>
    <URL>https://www.google.com/images/srpr/logo11w.png</URL>
    //If your attachment is publicly accessible by a URL, specify the URL.
  </Attachment>
  <Attachment>
    <URL>cid:test.pdf</URL>
    //If we have the attachment locally, then specify the content-ID in URL.
  </Attachment>
</Comments>
<Extrinsic name="ImageScanAttachmentUrl">cid:test.csv</Extrinsic>
//Specify ImageScans with the content-ID.

スクリプト出力

スクリプトは、curlを使用して顧客のインスタンスにPOSTできるように、出力をファイルに保存する必要があります。

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/invoices

出力ファイルが生成されたら、開かないでください。開かずに、顧客のインスタンスにPOSTするだけです。出力ファイルを開いてからPOSTすると、502 Bad Gatewayエラーが発生します。

エンコードされたインボイスの例

--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
...
JVBERi0xLjMKJcTl8uXrp/Og0MTGCjQgMCBvYmoKPDwgL0xlbmd0aCA1IDAg
UiAvRmlsdGVyIC9GbGF0ZURlY29kZSA+PgpzdHJlYW0KeAHlnGuPJbdxhr/3
r+gYWO+ZxNvb94u/SSsntmzBEjxOsIgNYz0z8trZ0UozUja+6L/7KRZZTZ6+
...

--ec6xAZMGCwZhdyY0 //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 same
Content-Transfer-Encoding: base64 //input is encoded in base64 foramt
Content-ID: <test.csv> //which file's is encoded below

...
CjAwMDAxOTQ0MjkgMDAwMDAgbiAKMDAwMDE5NDk1NiAwMDAwMCBuIAowMDAw
MTk1MjE4IDAwMDAwIG4gCjAwMDAyMjAyMTQgMDAwMDAgbiAKMDAwMDIyMDY4
NyAwMDAwMCBuIAowMDAwMjIwOTU2IDAwMDAwIG4gCjAwMDAyMzc3OTYgMDAw
...

--ec6xAZMGCwZhdyY0--
//Base64 multipart encoding ends here

  • この記事は役に立ちましたか?