{
  "info": {
    "name": "MagniFinance SOAP API - IPPN Partner Invoicing",
    "description": "Register a partner in your IPPN network, fetch its tokens and communicate its document series to the Tax Authority (AT), over SOAP 1.1. Every request already has the envelope, `Content-Type` and `SOAPAction` set. The requests are in the order of the kick-off; run them one after the other.\n\n1. Open the collection's **Variables** tab and fill in `email` and `token` with your IPPN account's main user and token, and `password` with that user's password (only **GetPartnerAccessTokens** sends it). Set `partnerTaxId` to the partner's tax id.\n2. Send **AddPartner**. Its response has no `Object`: a partner new to MagniFinance is created a few times per business day, an existing one has to accept by e-mail.\n3. Once access is granted, send **GetPartnerAccessTokens**. It stores the partner's first token in `partnerToken`.\n4. Send **IPPNCommunicatePartnerSeries** once tax communication is active for the partner. Then issue documents with the Finance API, sending `partnerToken` in `Authentication`: https://developer.magnifinance.com/finance/postman/invoicing-waybills-soap.json\n\nWSDL: https://bo.magnifinance.com/MagniAPI/Invoicing.asmx?WSDL and https://bo.magnifinance.com/MagniAPI/taxcommunication.asmx?wsdl\nDocs: https://developer.magnifinance.com/ippn/soap/",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    { "key": "baseUrl", "value": "https://bo.magnifinance.com" },
    { "key": "email", "value": "", "description": "The e-mail of your IPPN account's main user" },
    { "key": "token", "value": "", "type": "secret", "description": "Your IPPN account's token" },
    { "key": "password", "value": "", "type": "secret", "description": "The password of your IPPN account's main user; sent only by GetPartnerAccessTokens" },
    { "key": "partnerTaxId", "value": "992281008", "description": "The partner's tax id (NIF)" },
    { "key": "partnerToken", "value": "", "type": "secret", "description": "Filled in by GetPartnerAccessTokens; send it as Token to act on the partner's behalf" }
  ],
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "pm.test('HTTP 200', () => pm.response.to.have.status(200));",
          "const text = pm.response.text();",
          "const error = (text.match(/<ErrorValue>[\\s\\S]*?<Name>([^<]*)<\\/Name>/) || [])[1] || '';",
          "const detail = (text.match(/<Detail>([^<]*)<\\/Detail>/) || [])[1] || '';",
          "pm.test('Type is Success', () => pm.expect(text, `${error} ${detail}`.trim()).to.include('<Type>Success</Type>'));",
          "const accessToken = (text.match(/<AccessToken>([^<]*)<\\/AccessToken>/) || [])[1];",
          "if (accessToken) pm.collectionVariables.set('partnerToken', accessToken);"
        ]
      }
    }
  ],
  "item": [
    {
      "name": "AddPartner",
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "text/xml; charset=utf-8" },
          { "key": "SOAPAction", "value": "\"http://MagniAPI/Invoicing/AddPartner\"" }
        ],
        "url": { "raw": "{{baseUrl}}/MagniAPI/Invoicing.asmx", "host": ["{{baseUrl}}"], "path": ["MagniAPI", "Invoicing.asmx"] },
        "body": {
          "mode": "raw",
          "options": { "raw": { "language": "xml" } },
          "raw": "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:inv=\"http://MagniAPI/Invoicing/\">\n  <soapenv:Header/>\n  <soapenv:Body>\n    <inv:AddPartner>\n      <inv:Authentication>\n        <inv:Email>{{email}}</inv:Email>\n        <inv:Token>{{token}}</inv:Token>\n      </inv:Authentication>\n      <inv:PartnerInformation>\n        <inv:UserName>João Cardoso</inv:UserName>\n        <inv:UserEmail>joao.cardoso@partner.pt</inv:UserEmail>\n        <inv:UserPhone>912345678</inv:UserPhone>\n        <inv:CompanyTaxId>{{partnerTaxId}}</inv:CompanyTaxId>\n        <inv:CompanyLegalName>Magni EShop Partner, Lda.</inv:CompanyLegalName>\n        <inv:CompanyAddress>Av. Sidónio Pais, n.º 2</inv:CompanyAddress>\n        <inv:CompanyCity>Lisboa</inv:CompanyCity>\n        <inv:CompanyPostCode>1050-214</inv:CompanyPostCode>\n        <inv:CompanyCountry>PT</inv:CompanyCountry>\n      </inv:PartnerInformation>\n    </inv:AddPartner>\n  </soapenv:Body>\n</soapenv:Envelope>"
        },
        "description": "Registers the partner (a company or an individual, Portuguese only) in your IPPN network. The response has no `Object`: it only records the request. `CompanyWithTaxIdAlreadyExists` means there is already an open request for this tax id.\n\nDocs: https://developer.magnifinance.com/ippn/soap/add-partner/"
      }
    },
    {
      "name": "GetPartnerAccessTokens",
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "text/xml; charset=utf-8" },
          { "key": "SOAPAction", "value": "\"http://MagniAPI/Invoicing/GetPartnerTokens\"" }
        ],
        "url": { "raw": "{{baseUrl}}/MagniAPI/Invoicing.asmx", "host": ["{{baseUrl}}"], "path": ["MagniAPI", "Invoicing.asmx"] },
        "body": {
          "mode": "raw",
          "options": { "raw": { "language": "xml" } },
          "raw": "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:inv=\"http://MagniAPI/Invoicing/\">\n  <soapenv:Header/>\n  <soapenv:Body>\n    <inv:GetPartnerAccessTokens>\n      <inv:SpecialAuthentication>\n        <inv:Email>{{email}}</inv:Email>\n        <inv:Token>{{token}}</inv:Token>\n        <inv:Password>{{password}}</inv:Password>\n      </inv:SpecialAuthentication>\n      <inv:PartnerTaxId>{{partnerTaxId}}</inv:PartnerTaxId>\n    </inv:GetPartnerAccessTokens>\n  </soapenv:Body>\n</soapenv:Envelope>"
        },
        "description": "The partner's tokens, once the partnership is in the **access granted** state. Needs the `password` of your main user in `SpecialAuthentication`. Stores the first token in `partnerToken`. The SOAPAction is `…/GetPartnerTokens`, as the WSDL defines it.\n\n`NoPartnerFoundWithTaxId` means access is not granted yet (pending, rejected, revoked or never requested): check the state in MagniFinance under Config → IPPN → Partnership Management.\n\nDocs: https://developer.magnifinance.com/ippn/soap/get-partner-access-tokens/"
      }
    },
    {
      "name": "IPPNCommunicatePartnerSeries",
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "text/xml; charset=utf-8" },
          { "key": "SOAPAction", "value": "\"http://MagniAPI/TaxCommunication/IPPNCommunicatePartnerSeries\"" }
        ],
        "url": { "raw": "{{baseUrl}}/MagniAPI/TaxCommunication.asmx", "host": ["{{baseUrl}}"], "path": ["MagniAPI", "TaxCommunication.asmx"] },
        "body": {
          "mode": "raw",
          "options": { "raw": { "language": "xml" } },
          "raw": "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tax=\"http://MagniAPI/TaxCommunication/\">\n  <soapenv:Header/>\n  <soapenv:Body>\n    <tax:IPPNCommunicatePartnerSeries>\n      <tax:authentication>\n        <tax:Email>{{email}}</tax:Email>\n        <tax:Token>{{partnerToken}}</tax:Token>\n      </tax:authentication>\n    </tax:IPPNCommunicatePartnerSeries>\n  </soapenv:Body>\n</soapenv:Envelope>"
        },
        "description": "Communicates all of the partner's series (`<CODE>`, `<CODE>NC`, and `<CODE>AF` / `<CODE>NCAF` for self-billing partnerships) to the AT. It sends the **partner's** token from `partnerToken`.\n\nTax communication must be active for the partner first (ActivationSet with the partner's token and its AT credentials), otherwise the answer is `ATInvalidCredencials`. Safe to repeat: series already registered come back as `Communicated`.\n\nDocs: https://developer.magnifinance.com/ippn/partner-series/"
      }
    }
  ]
}
