{
  "info": {
    "name": "MEGOGO Partner Billing API (internet providers)",
    "description": "Requests of the MEGOGO Partner Billing API for partners that activate MEGOGO subscriptions of their subscribers and give them a MEGOGO account.\n\nPut your values (partner_id, identifier, service_id, login, password) in a Postman environment. Send the requests from a computer with an IP address of your list.\n\nGuide: https://megogo-partner-billing-docs.pages.dev/reference/postman/",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "partners_api",
      "value": "https://billing.megogo.net",
      "description": "Base URL of the Partner Billing API"
    },
    {
      "key": "partner_id",
      "value": "",
      "description": "Your partner ID. Put it in your environment"
    },
    {
      "key": "identifier",
      "value": "",
      "description": "Identifier of a test subscriber, for example test-0001"
    },
    {
      "key": "service_id",
      "value": "",
      "description": "Service ID of a test subscription"
    },
    {
      "key": "login",
      "value": "",
      "description": "Login (e-mail) of the test subscriber, for example test-0001@your-isp.example"
    },
    {
      "key": "password",
      "value": "",
      "description": "Password of the test subscriber: 6 or more characters. Put it only in your environment, as a secret"
    },
    {
      "key": "new_identifier",
      "value": "",
      "description": "New identifier for the request Change the identifier"
    }
  ],
  "item": [
    {
      "name": "Subscribe",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "pm.test('successful', () => pm.expect(body.successful).to.eql(true));",
              "if (!body.successful) console.log('Error: ' + body.message);"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "description": "Starts the subscription `service_id`. Makes the subscriber if MEGOGO does not know the identifier.",
        "url": {
          "raw": "{{partners_api}}/partners/{{partner_id}}/subscription/subscribe?userId={{identifier}}&serviceId={{service_id}}",
          "host": [
            "{{partners_api}}"
          ],
          "path": [
            "partners",
            "{{partner_id}}",
            "subscription",
            "subscribe"
          ],
          "query": [
            {
              "key": "userId",
              "value": "{{identifier}}"
            },
            {
              "key": "serviceId",
              "value": "{{service_id}}"
            }
          ]
        }
      }
    },
    {
      "name": "Subscriptions of the subscriber",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "pm.test('list of subscriptions', () => pm.expect(body.svod).to.be.an('array'));",
              "if (body.svod) body.svod.forEach(s => console.log(s.serviceId + ' until ' + s.dateFinishString + ' UTC'));"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "description": "Active subscriptions of the subscriber.",
        "url": {
          "raw": "{{partners_api}}/partners/{{partner_id}}/user/subscriptions?identifier={{identifier}}",
          "host": [
            "{{partners_api}}"
          ],
          "path": [
            "partners",
            "{{partner_id}}",
            "user",
            "subscriptions"
          ],
          "query": [
            {
              "key": "identifier",
              "value": "{{identifier}}"
            }
          ]
        }
      }
    },
    {
      "name": "Set the login and the password",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "pm.test('successful', () => pm.expect(body.successful).to.eql(true));",
              "if (!body.successful) console.log('Error: ' + body.message);"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "description": "Makes the MEGOGO account of the subscriber, or changes its login or password. Before a password change, get the current login with **Get the MEGOGO user**.",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"isdn\": \"{{identifier}}\",\n  \"email\": \"{{login}}\",\n  \"password\": \"{{password}}\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{partners_api}}/partners/{{partner_id}}/user/changeCredentials",
          "host": [
            "{{partners_api}}"
          ],
          "path": [
            "partners",
            "{{partner_id}}",
            "user",
            "changeCredentials"
          ]
        }
      }
    },
    {
      "name": "Get the MEGOGO user",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "pm.test('MEGOGO user ID', () => pm.expect(body).to.have.property('uid'));",
              "console.log(body.email ? 'Login: ' + body.email : 'The subscriber has no login');"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "description": "MEGOGO user ID and the current login. Makes the subscriber if MEGOGO does not know the identifier.",
        "url": {
          "raw": "{{partners_api}}/partners/{{partner_id}}/user/innerId?identifier={{identifier}}",
          "host": [
            "{{partners_api}}"
          ],
          "path": [
            "partners",
            "{{partner_id}}",
            "user",
            "innerId"
          ],
          "query": [
            {
              "key": "identifier",
              "value": "{{identifier}}"
            }
          ]
        }
      }
    },
    {
      "name": "Suspend",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "pm.test('successful', () => pm.expect(body.successful).to.eql(true));",
              "if (!body.successful) console.log('Error: ' + body.message);"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "description": "Stops the access until `resume`. The time that is left stays.",
        "url": {
          "raw": "{{partners_api}}/partners/{{partner_id}}/subscription/suspend?userId={{identifier}}&serviceId={{service_id}}",
          "host": [
            "{{partners_api}}"
          ],
          "path": [
            "partners",
            "{{partner_id}}",
            "subscription",
            "suspend"
          ],
          "query": [
            {
              "key": "userId",
              "value": "{{identifier}}"
            },
            {
              "key": "serviceId",
              "value": "{{service_id}}"
            }
          ]
        }
      }
    },
    {
      "name": "Resume",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "pm.test('successful', () => pm.expect(body.successful).to.eql(true));",
              "if (!body.successful) console.log('Error: ' + body.message);"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "description": "Starts a suspended subscription again. Send it only after your own `suspend`.",
        "url": {
          "raw": "{{partners_api}}/partners/{{partner_id}}/subscription/resume?userId={{identifier}}&serviceId={{service_id}}",
          "host": [
            "{{partners_api}}"
          ],
          "path": [
            "partners",
            "{{partner_id}}",
            "subscription",
            "resume"
          ],
          "query": [
            {
              "key": "userId",
              "value": "{{identifier}}"
            },
            {
              "key": "serviceId",
              "value": "{{service_id}}"
            }
          ]
        }
      }
    },
    {
      "name": "Unsubscribe",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "pm.test('successful', () => pm.expect(body.successful).to.eql(true));",
              "if (!body.successful) console.log('Error: ' + body.message);"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "description": "Stops the subscription immediately.",
        "url": {
          "raw": "{{partners_api}}/partners/{{partner_id}}/subscription/unsubscribe?userId={{identifier}}&serviceId={{service_id}}",
          "host": [
            "{{partners_api}}"
          ],
          "path": [
            "partners",
            "{{partner_id}}",
            "subscription",
            "unsubscribe"
          ],
          "query": [
            {
              "key": "userId",
              "value": "{{identifier}}"
            },
            {
              "key": "serviceId",
              "value": "{{service_id}}"
            }
          ]
        }
      }
    },
    {
      "name": "Make a MEGOGO user",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "pm.test('MEGOGO user ID', () => pm.expect(body).to.have.property('uid'));",
              "console.log('MEGOGO user ID: ' + body.uid);"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "description": "Makes a MEGOGO user for the identifier without a subscription.",
        "url": {
          "raw": "{{partners_api}}/partners/{{partner_id}}/user/create?identifier={{identifier}}",
          "host": [
            "{{partners_api}}"
          ],
          "path": [
            "partners",
            "{{partner_id}}",
            "user",
            "create"
          ],
          "query": [
            {
              "key": "identifier",
              "value": "{{identifier}}"
            }
          ]
        }
      }
    },
    {
      "name": "Change the identifier",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "pm.test('MEGOGO user ID', () => pm.expect(body).to.have.property('uid'));",
              "console.log('MEGOGO user ID: ' + body.uid);"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "description": "Moves the subscriber to `new_identifier`. After the request, put the new identifier in `identifier`.",
        "url": {
          "raw": "{{partners_api}}/partners/{{partner_id}}/user/changeLogin?identifier={{identifier}}&newIdentifier={{new_identifier}}",
          "host": [
            "{{partners_api}}"
          ],
          "path": [
            "partners",
            "{{partner_id}}",
            "user",
            "changeLogin"
          ],
          "query": [
            {
              "key": "identifier",
              "value": "{{identifier}}"
            },
            {
              "key": "newIdentifier",
              "value": "{{new_identifier}}"
            }
          ]
        }
      }
    }
  ]
}
