{
  "info": {
    "name": "MagniFinance REST 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). 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 **Get Partner Access Tokens** sends it). Set `partnerTaxId` to the partner's tax id.\n2. Send **Add Partner**. Its response has no partner data: 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 **Get Partner Access Tokens**. It stores the partner's first token in `partnerToken`.\n4. Send **Communicate Partner Series** (a SOAP call, the only way to do it) once tax communication is active for the partner. Then issue documents with the Finance API, sending `partnerToken` as `token`: https://developer.magnifinance.com/finance/postman/invoicing-waybills-rest.json\n\nDocs: https://developer.magnifinance.com/ippn/rest/",
    "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 Get Partner Access Tokens" },
    { "key": "partnerTaxId", "value": "599138645", "description": "The partner's tax id (NIF)" },
    { "key": "partnerToken", "value": "", "type": "secret", "description": "Filled in by Get Partner Access Tokens; 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 contentType = pm.response.headers.get('Content-Type') || '';",
          "if (contentType.includes('json')) {",
          "    const body = pm.response.json();",
          "    const error = body.ErrorValue ? `${body.ErrorValue.Name}: ${JSON.stringify(body.ValidationErrors || body.ErrorHumanReadable)}` : '';",
          "    pm.test('Type is Success', () => pm.expect(body.IsError, error).to.be.false);",
          "    if (Array.isArray(body.Object) && body.Object[0] && body.Object[0].AccessToken) pm.collectionVariables.set('partnerToken', body.Object[0].AccessToken);",
          "} else if (contentType.includes('xml')) {",
          "    const text = pm.response.text();",
          "    const error = (text.match(/<ErrorValue>[\\s\\S]*?<Name>([^<]*)<\\/Name>/) || [])[1] || '';",
          "    pm.test('Type is Success', () => pm.expect(text, error).to.include('<Type>Success</Type>'));",
          "}"
        ]
      }
    }
  ],
  "item": [
    {
      "name": "Add Partner",
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/json" },
          { "key": "email", "value": "{{email}}" },
          { "key": "token", "value": "{{token}}" }
        ],
        "url": { "raw": "{{baseUrl}}/api/v1.1/partner", "host": ["{{baseUrl}}"], "path": ["api", "v1.1", "partner"] },
        "body": {
          "mode": "raw",
          "options": { "raw": { "language": "json" } },
          "raw": "{\n  \"CompanyTaxId\": \"{{partnerTaxId}}\",\n  \"CompanyLegalName\": \"Magni EShop Partner, Lda.\",\n  \"CompanyAddress\": \"Av. Sidónio Pais, n.º 2\",\n  \"CompanyPostCode\": \"1050-214\",\n  \"CompanyCity\": \"Lisboa\",\n  \"CompanyCountry\": \"PT\",\n  \"UserName\": \"João Cardoso\",\n  \"UserEmail\": \"joao.cardoso@partner.pt\",\n  \"UserPhone\": \"912345678\"\n}"
        },
        "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/rest/add-partner/"
      }
    },
    {
      "name": "Get Partner Access Tokens",
      "request": {
        "method": "GET",
        "header": [
          { "key": "email", "value": "{{email}}" },
          { "key": "token", "value": "{{token}}" },
          { "key": "password", "value": "{{password}}" }
        ],
        "url": { "raw": "{{baseUrl}}/api/v1.1/partner/accessTokens?partnerTaxId={{partnerTaxId}}", "host": ["{{baseUrl}}"], "path": ["api", "v1.1", "partner", "accessTokens"], "query": [{ "key": "partnerTaxId", "value": "{{partnerTaxId}}" }] },
        "description": "The partner's tokens, once the partnership is in the **access granted** state. Needs the `password` of your main user on top of `email` and `token`. Stores the first token in `partnerToken`.\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/rest/get-partner-access-tokens/"
      }
    },
    {
      "name": "Communicate Partner Series (SOAP)",
      "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. This operation exists only over SOAP, so it is included here with the envelope already set. It sends the **partner's** token from `partnerToken`.\n\nTax communication must be active for the partner first (Activation Set 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/"
      }
    }
  ]
}
