{"slug": "testing-mtn-momo-collection-api-in-sandbox-using-postman", "title": "Testing MTN MoMo Collection API in Sandbox using Postman", "summary": "Step-by-step guide on testing the MTN MoMo Collection API in a sandbox environment using Postman. It explains how to create an API User and API Key using a unique X-Reference-Id and subscription key, then generate a Bearer Token that expires hourly. Finally, it details how to configure and send a POST RequestToPay request using the token, a new transaction ID, and the sandbox target environment.", "body_md": "To create an API User, you need the following things in place: X-Reference-Id and Ocp-Apim-Subscription-Key\n1. X-Reference-Id\nThis is used as User ID since the Sandbox is a Mock Environment so we kinda create our own ids and send them over\nto the sandbox so it can uniquely identify the user\nIf all went well, you should get the response with \"Status: 201 Created\"\nYou will not see any other additional content in the response body, just that message is good enough!\nSo this means you have created an API User with an ID:9f92971b-cd2e-4feb-9053-0b14d53ac4f5 (this is the same id you supplied,\nnothing special about it)\nTake note of this ID as it will be used to create the API Key in step 2 and API Bearer Token in step 3\nIf all went well, you should get the response with \"Status: 201 Created\"\nYou will also see additional content in the response body, as shown below:\n{\n\"apiKey\": \"1e89774dabd944b4b112c30aaef5b9c8\"\n}\nSo this means you have created an API Key with value:1e89774dabd944b4b112c30aaef5b9c8\nTake note of this API Key value(1e89774dabd944b4b112c30aaef5b9c8) as it will be used as PASSWORD, while the User ID/X-Reference-Id(9f92971b-cd2e-4feb-9053-0b14d53ac4f5) will be used as USERNAME when creating the Bearer Token in Step 3.\nSo this means you have created a Bearer Token(Access Token) with value:eyJ0eXAiOiJKV1QiLCJhbGciOiJSMjU2In0.eyJjbGllbnRJZCI6ImM0ZjZkMzNkLWVhNzYtNDYwOS1iODE2LWE5OWRjODAxYjUzMiIsImV4cGlyZXMiOiIyMDIwLTA2LTA5VDIwOjMyOjQyLjIwMSIsInNlc3Npb25JZCI6IjZkYjg0MjIxLWM4ZWQtNGZhZC1hMDM5LWYzZDY3YzNjMzMwMiJ9.FUhqzW_HhXlOIsYu3YQMWsfpBujSktAldnnh70De8uKuuPGGlgIEmIrakQ91klV8rNeD2g_tq9nOR748j8O-vp5oNKDmmt5ANo2qUoYZTaiwSthev6DQ2TLvxr45w4QCX0YmPTDtkue_9R7ZpnEhud51XlKfEOEMAZhdWoVDvL08xrwrL-yP2yfLGRZVtZfpaqrx7CxgUO3MT_zXy8QuvHAvlwlgxIvkZhILdTbycyZHAtvRCeoMJ0G7REsQQYHfNNm87aXg9vwcjDu-YZGVaA27jHP2z-l4gbeg-sluoqafcQ8YwqPZ4nGcAMoMCTU6wtUICDMNw-qWpZwlHEixaw\nTake note that this token expires in 1 hour. So it means you will need to send this request every after 1 hour to get a fresh token, if you have to continue testing api calls on the rest of the endpoints.\nTake note of this value as it will be used in subsequent api calls in Step 4 and Step 5\nTo successfully send this POST RequestToPay request, you need the following things in place: X-Reference-Id(Transaction ID), Ocp-Apim-Subscription-Key, X-Target-Environment and the Bearer Token\n1. X-Reference-Id(Transaction ID)\nNote that the X-Reference-id used here should not be the same as one used in Step 1 to 3.\nThe X-Reference-Id used here represents the Transaction ID for our request to pay, in the Mock Environment(Sandbox)\nSo we will need to GENERATE a NEW ID for this transaction\nIn our example we will use b988a090-bbeb-46af-806c-db7fd8aeca7e\nRemember, this is treated as Transaction ID\n2. Ocp-Apim-Subscription-Key\nGet the Primary or Secondary Subscription Key of the Collections Subscription from your Profile\nIn our example we used b44728c249c24d8bb11d8b8592f4f5a7 so we will use this same value here too!\n3. X-Target-Environment\n-Put the value as \"sandbox\"\n4. Bearer Token\nUse the Bearer Token we created in Step 3: Create Bearer Token\nIn our example, the Bearer Token is : eyJ0eXAiOiJKV1QiLCJhbGciOiJSMjU2In0.eyJjbGllbnRJZCI6ImM0ZjZkMzNkLWVhNzYtNDYwOS1iODE2LWE5OWRjODAxYjUzMiIsImV4cGlyZXMiOiIyMDIwLTA2LTA5VDIwOjMyOjQyLjIwMSIsInNlc3Npb25JZCI6IjZkYjg0MjIxLWM4ZWQtNGZhZC1hMDM5LWYzZDY3YzNjMzMwMiJ9.FUhqzW_HhXlOIsYu3YQMWsfpBujSktAldnnh70De8uKuuPGGlgIEmIrakQ91klV8rNeD2g_tq9nOR748j8O-vp5oNKDmmt5ANo2qUoYZTaiwSthev6DQ2TLvxr45w4QCX0YmPTDtkue_9R7ZpnEhud51XlKfEOEMAZhdWoVDvL08xrwrL-yP2yfLGRZVtZfpaqrx7CxgUO3MT_zXy8QuvHAvlwlgxIvkZhILdTbycyZHAtvRCeoMJ0G7REsQQYHfNNm87aXg9vwcjDu-YZGVaA27jHP2z-l4gbeg-sluoqafcQ8YwqPZ4nGcAMoMCTU6wtUICDMNw-qWpZwlHEixaw\nB. Configure Postman\n1. URL\nPOST https://sandbox.momodeveloper.mtn.com/collection/v1_0/requesttopay\n2. Params\nDO NOT PUT ANYTHING HERE\n3. Authorization\nSelect \"Bearer Token\" as Type\nIn the Token field, put the Bearer Token created in Step 3\nIn our example, configuration for this should look like below:\nTo successfully send this GET RequestToPay request, you need the following things in place: X-Reference-Id(Transaction ID), Ocp-Apim-Subscription-Key, X-Target-Environment and the Bearer Token\n1. X-Reference-Id(Transaction ID)\nUse the X-Reference-id used in step 4 when creating the RequestToPay Trasaction\nIn our example we used b988a090-bbeb-46af-806c-db7fd8aeca7e so we will use the same id here too!\nRemember, this is treated as Transaction ID\n2. Ocp-Apim-Subscription-Key\nUse the same Primary or Secondary Subscription Key you used during Step 1: Create API User\nIn our example we used b44728c249c24d8bb11d8b8592f4f5a7 so we will use this same value here too!\n3. X-Target-Environment\nPut the value as \"sandbox\"\n4. Bearer Token\nUse the Bearer Token we created in Step 3: Create Bearer Token\nIn our example, the Bearer Token is :eyJ0eXAiOiJKV1QiLCJhbGciOiJSMjU2In0.eyJjbGllbnRJZCI6ImM0ZjZkMzNkLWVhNzYtNDYwOS1iODE2LWE5OWRjODAxYjUzMiIsImV4cGlyZXMiOiIyMDIwLTA2LTA5VDIwOjMyOjQyLjIwMSIsInNlc3Npb25JZCI6IjZkYjg0MjIxLWM4ZWQtNGZhZC1hMDM5LWYzZDY3YzNjMzMwMiJ9.FUhqzW_HhXlOIsYu3YQMWsfpBujSktAldnnh70De8uKuuPGGlgIEmIrakQ91klV8rNeD2g_tq9nOR748j8O-vp5oNKDmmt5ANo2qUoYZTaiwSthev6DQ2TLvxr45w4QCX0YmPTDtkue_9R7ZpnEhud51XlKfEOEMAZhdWoVDvL08xrwrL-yP2yfLGRZVtZfpaqrx7CxgUO3MT_zXy8QuvHAvlwlgxIvkZhILdTbycyZHAtvRCeoMJ0G7REsQQYHfNNm87aXg9vwcjDu-YZGVaA27jHP2z-l4gbeg-sluoqafcQ8YwqPZ4nGcAMoMCTU6wtUICDMNw-qWpZwlHEixaw\nB. Configure Postman\n1. URL\nGET https://sandbox.momodeveloper.mtn.com/collection/v1_0/requesttopay/b988a090-bbeb-46af-806c-db7fd8aeca7e\n2. Params\nDO NOT PUT ANYTHING HERE\n3. Authorization\nSelect \"Bearer Token\" as Type\nIn the Token field, put the Bearer Token created in Step 3\nIn our example, configuration for this should look like below:\nSo this means your RequestToPay Transaction was approved by the Payer\nNOTE:\n-If the phone number used as PartyId, during the POST requesttopay, is any number other than the ones from the list of test numbers on MTN Documentation( https://momodeveloper.mtn.com/api-documentation/testing/), then the response returned will ALWAYS be SUCCESSFUL! If you want to see a response with Status: PENDING or FAILED, then you need to use a test number from MTN's MoMo Documentation Website: https://momodeveloper.mtn.com/api-documentation/testing/\nYou are expected to have, at least, one Product Subscription before attempting to provision an API User\nOnce you provision an API User(in the Sandbox) and the API Key, the two can then be used to create a Bearer Token(Access Token)\nThe Bearer Token can then be used to make api calls for any of the Product Subscriptions. It will be sent as part of the Authorization Header of every api call.\nNote that each Bearer Token issued has an expiry, usually 3600 seconds\nThe value for Ocp-Apim-Subscription-Key header will ALWAYS be the SAME for ALL Endpoints in a given Product Subscription\nThe value for X-Reference-Id header should ALWAYS be UNIQUE/DIFFERENT for each POST Request where the X-Reference-Id is expected to be in the header\nWhenever the X-Reference-Id is expected to be passed as a Request Parameter (either in a POST or GET request), use an existing X-Reference-Id corresponding to the referenced resource\nHint\nSteps 1 through 5 can be used as the typical flow for implementing a MoMo Payment Integration for your payment solution! After testing the steps in Postman, copy each step logic/flow and write the corresponding code(in your preferred language).", "url": "https://wpnews.pro/news/testing-mtn-momo-collection-api-in-sandbox-using-postman", "canonical_source": "https://gist.github.com/chaiwa-berian/5294fdf1360247cf4561c95c8fa740d4", "published_at": "2020-06-10 10:25:21+00:00", "updated_at": "2026-05-22 09:51:15.294950+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["MTN", "Postman"], "alternates": {"html": "https://wpnews.pro/news/testing-mtn-momo-collection-api-in-sandbox-using-postman", "markdown": "https://wpnews.pro/news/testing-mtn-momo-collection-api-in-sandbox-using-postman.md", "text": "https://wpnews.pro/news/testing-mtn-momo-collection-api-in-sandbox-using-postman.txt", "jsonld": "https://wpnews.pro/news/testing-mtn-momo-collection-api-in-sandbox-using-postman.jsonld"}}