{
  "info": {
    "_postman_id": "c448f2e7-ffdf-433e-9ca4-da2394a9849c",
    "name": "BCS PA - B - Onboarding",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "_exporter_id": "50267719",
    "_collection_link": "https://go.postman.co/collection/50267719-c448f2e7-ffdf-433e-9ca4-da2394a9849c?source=collection_link"
  },
  "item": [
    {
      "name": "1. Auth - Get OAuth2 token",
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "pm.test('Status code is 200', function () {",
              "    pm.response.to.have.status(200);",
              "});",
              "const json = pm.response.json();",
              "pm.test('Response contains access_token', function () {",
              "    pm.expect(json.access_token).to.exist;",
              "});",
              "pm.collectionVariables.set('access_token', json.access_token);",
              "if (json.token_type) pm.collectionVariables.set('token_type', json.token_type);",
              "if (json.expires_in) pm.collectionVariables.set('token_expires_in', String(json.expires_in));",
              "console.log('access_token env =', pm.environment.get('access_token'));",
              "console.log('access_token collection =', pm.collectionVariables.get('access_token'));"
            ],
            "type": "text/javascript",
            "packages": {},
            "requests": {}
          }
        },
        {
          "listen": "prerequest",
          "script": {
            "exec": [
              ""
            ],
            "type": "text/javascript",
            "packages": {},
            "requests": {}
          }
        }
      ],
      "request": {
        "auth": {
          "type": "noauth"
        },
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/x-www-form-urlencoded"
          },
          {
            "key": "User-Agent",
            "value": "BCSolutions",
            "type": "text"
          }
        ],
        "body": {
          "mode": "urlencoded",
          "urlencoded": [
            {
              "key": "grant_type",
              "value": "client_credentials",
              "type": "text"
            },
            {
              "key": "client_id",
              "value": "{{client_id}}",
              "type": "text"
            },
            {
              "key": "client_secret",
              "value": "{{client_secret}}",
              "type": "text"
            }
          ]
        },
        "url": {
          "raw": "{{oauth_token_url}}",
          "host": [
            "{{oauth_token_url}}"
          ]
        }
      },
      "response": []
    },
    {
      "name": "2.1 - List legal units",
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "// Parse la réponse JSON\r",
              "const response = pm.response.json();\r",
              "\r",
              "// Récupère le legalUnitId\r",
              "const legalUnitId = response.legalUnitId;\r",
              "\r",
              "// Sauvegarde dans une variable de collection\r",
              "pm.collectionVariables.set(\"legalUnitId\", legalUnitId);\r",
              "\r",
              "// Log console (optionnel)\r",
              "console.log(\"legalUnitId enregistré :\", legalUnitId);"
            ],
            "type": "text/javascript",
            "packages": {},
            "requests": {}
          }
        }
      ],
      "protocolProfileBehavior": {
        "disableBodyPruning": true
      },
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{access_token}}",
            "type": "text"
          },
          {
            "key": "X-Tenant",
            "value": "{{tenantSlug}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{tenant_public_api_url}}/v1/onboarding/legal-units",
          "host": [
            "{{tenant_public_api_url}}"
          ],
          "path": [
            "v1",
            "onboarding",
            "legal-units"
          ]
        }
      },
      "response": []
    },
    {
      "name": "2.2 - Create a legal unit - BIDIRECTIONAL (Emission et réception)",
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "// Parse la réponse JSON\r",
              "const response = pm.response.json();\r",
              "\r",
              "// Récupère le legalUnitId\r",
              "const legalUnitId = response.legalUnitId;\r",
              "\r",
              "// Sauvegarde dans une variable de collection\r",
              "pm.collectionVariables.set(\"legalUnitId\", legalUnitId);\r",
              "\r",
              "// Log console (optionnel)\r",
              "console.log(\"legalUnitId enregistré :\", legalUnitId);"
            ],
            "type": "text/javascript",
            "packages": {},
            "requests": {}
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{access_token}}",
            "type": "text"
          },
          {
            "key": "X-Tenant",
            "value": "{{tenantSlug}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\r\n  \"countryCode\": \"FR\",\r\n  \"name\": \"GMF ASSURANCES\",\r\n  \"identifierScheme\": \"0002\",\r\n  \"identifierValue\": \"398972901\",\r\n  \"operatorDirection\": \"BIDIRECTIONAL\"\r\n}\r\n",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{tenant_public_api_url}}/v1/onboarding/legal-units",
          "host": [
            "{{tenant_public_api_url}}"
          ],
          "path": [
            "v1",
            "onboarding",
            "legal-units"
          ]
        }
      },
      "response": []
    },
    {
      "name": "2.2 - Create a legal unit - INBOUND (Réception seulement)",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// Parse la réponse JSON\r\nconst response = pm.response.json();\r\n\r\n// Récupère le legalUnitId\r\nconst legalUnitId = response.legalUnitId;\r\n\r\n// Sauvegarde dans une variable de collection\r\npm.collectionVariables.set(\"legalUnitId\", legalUnitId);\r\n\r\n// Log console (optionnel)\r\nconsole.log(\"legalUnitId enregistré :\", legalUnitId);"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{access_token}}"
          },
          {
            "key": "X-Tenant",
            "value": "{{tenantSlug}}"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\r\n  \"countryCode\": \"FR\",\r\n  \"name\": \"GMF ASSURANCES\",\r\n  \"identifierScheme\": \"0002\",\r\n  \"identifierValue\": \"398972901\",\r\n  \"operatorDirection\": \"INBOUND\"\r\n}\r\n",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{tenant_public_api_url}}/v1/onboarding/legal-units",
          "host": [
            "{{tenant_public_api_url}}"
          ],
          "path": [
            "v1",
            "onboarding",
            "legal-units"
          ]
        }
      },
      "response": []
    },
    {
      "name": "2.2 - Create a legal unit - OUTBOUND (Emission seulement)",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// Parse la réponse JSON\r\nconst response = pm.response.json();\r\n\r\n// Récupère le legalUnitId\r\nconst legalUnitId = response.legalUnitId;\r\n\r\n// Sauvegarde dans une variable de collection\r\npm.collectionVariables.set(\"legalUnitId\", legalUnitId);\r\n\r\n// Log console (optionnel)\r\nconsole.log(\"legalUnitId enregistré :\", legalUnitId);"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{access_token}}"
          },
          {
            "key": "X-Tenant",
            "value": "{{tenantSlug}}"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\r\n  \"countryCode\": \"FR\",\r\n  \"name\": \"GMF ASSURANCES\",\r\n  \"identifierScheme\": \"0002\",\r\n  \"identifierValue\": \"398972901\",\r\n  \"operatorDirection\": \"OUTBOUND\"\r\n}\r\n",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{tenant_public_api_url}}/v1/onboarding/legal-units",
          "host": [
            "{{tenant_public_api_url}}"
          ],
          "path": [
            "v1",
            "onboarding",
            "legal-units"
          ]
        }
      },
      "response": []
    },
    {
      "name": "2.3 - Get legal units details",
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "// Parse la réponse JSON\r",
              "const response = pm.response.json();\r",
              "\r",
              "// Récupère le legalUnitId\r",
              "const legalUnitId = response.legalUnitId;\r",
              "\r",
              "// Sauvegarde dans une variable de collection\r",
              "pm.collectionVariables.set(\"legalUnitId\", legalUnitId);\r",
              "\r",
              "// Log console (optionnel)\r",
              "console.log(\"legalUnitId enregistré :\", legalUnitId);"
            ],
            "type": "text/javascript",
            "packages": {},
            "requests": {}
          }
        }
      ],
      "protocolProfileBehavior": {
        "disableBodyPruning": true
      },
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{access_token}}",
            "type": "text"
          },
          {
            "key": "X-Tenant",
            "value": "{{tenantSlug}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{tenant_public_api_url}}/v1/onboarding/legal-units/{{legalUnitId}}",
          "host": [
            "{{tenant_public_api_url}}"
          ],
          "path": [
            "v1",
            "onboarding",
            "legal-units",
            "{{legalUnitId}}"
          ]
        }
      },
      "response": []
    },
    {
      "name": "3.1 Start onboarding for a legalUnit",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "X-Tenant",
            "value": "{{tenantSlug}}",
            "type": "text"
          },
          {
            "key": "Authorization",
            "value": "Bearer {{access_token}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\r\n  \"registerDomesticFr\": true,\r\n  \"registerPeppolInternational\": true\r\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{tenant_public_api_url}}/v1/onboarding/legal-units/{{legalUnitId}}/start",
          "host": [
            "{{tenant_public_api_url}}"
          ],
          "path": [
            "v1",
            "onboarding",
            "legal-units",
            "{{legalUnitId}}",
            "start"
          ]
        }
      },
      "response": []
    },
    {
      "name": "3.2 Get onboarding state for a legalUnit",
      "protocolProfileBehavior": {
        "disableBodyPruning": true
      },
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{access_token}}",
            "type": "text"
          },
          {
            "key": "Organization-Id",
            "value": "{{tenantSlug}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{tenant_public_api_url}}/v1/onboarding/legal-units/{{legalUnitId}}/state",
          "host": [
            "{{tenant_public_api_url}}"
          ],
          "path": [
            "v1",
            "onboarding",
            "legal-units",
            "{{legalUnitId}}",
            "state"
          ]
        }
      },
      "response": []
    },
    {
      "name": "3.3 Get onboarding progress history for a legalUnit",
      "protocolProfileBehavior": {
        "disableBodyPruning": true
      },
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{access_token}}",
            "type": "text"
          },
          {
            "key": "Organization-Id",
            "value": "{{tenantSlug}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{tenant_public_api_url}}/v1/onboarding/legal-units/{{legalUnitId}}/history",
          "host": [
            "{{tenant_public_api_url}}"
          ],
          "path": [
            "v1",
            "onboarding",
            "legal-units",
            "{{legalUnitId}}",
            "history"
          ]
        }
      },
      "response": []
    },
    {
      "name": "3.4 Restart an expired onboarding",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{access_token}}",
            "type": "text"
          },
          {
            "key": "Organization-Id",
            "value": "{{tenantSlug}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\r\n  \"registerDomesticFr\": true,\r\n  \"registerPeppolInternational\": true\r\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{tenant_public_api_url}}/v1/onboarding/legal-units/{{legalUnitId}}/restart",
          "host": [
            "{{tenant_public_api_url}}"
          ],
          "path": [
            "v1",
            "onboarding",
            "legal-units",
            "{{legalUnitId}}",
            "restart"
          ]
        }
      },
      "response": []
    }
  ],
  "variable": [
    {
      "key": "access_token",
      "value": ""
    },
    {
      "key": "token_type",
      "value": ""
    },
    {
      "key": "token_expires_in",
      "value": ""
    },
    {
      "key": "legalUnitId",
      "value": ""
    }
  ]
}