Skip to content

eCMR con SAP: Adjuntar PDF a facturas

Descargar PDF del eCMR

bash
curl -X GET "https://ecmr.api.pro.cargoffer.com/ecmr/file/{service_code}" \
  -H "Authorization: Bearer *** \
  -o "ecmr_{service_code}.pdf"

Adjuntar a SAP

bash
curl -X POST "https://tu-sap:50000/b1s/v1/Attachments2" \
  -H "Cookie: B1SESSION=..." \
  -H "Content-Type: application/json" \
  -d '{
    "Attachments2_Lines": [{
      "SourcePath": "/tmp",
      "FileName": "ecmr_{service_code}.pdf",
      "FileExtension": "pdf"
    }]
  }'

Automatizacion

python
def adjuntar_ecmr_sap(service_code, doc_entry):
    pdf = requests.get(
        f"https://ecmr.api.pro.cargoffer.com/ecmr/file/{service_code}",
        headers={"Authorization": f"Bearer {TOKEN}"}
    ).content
    
    with open(f"/tmp/ecmr_{service_code}.pdf", "wb") as f:
        f.write(pdf)
    
    # Adjuntar via SAP Service Layer
    sap.post("/Attachments2", json={
        "Attachments2_Lines": [{
            "SourcePath": "/tmp",
            "FileName": f"ecmr_{service_code}.pdf",
            "FileExtension": "pdf"
        }]
    })

Documentación de Cargoffer