Skip to main content

Access to Momo OpenAPI Documentation JavaScript

  • January 28, 2024
  • 7 replies
  • 135 views

I just saw a video on how to use the Momo OpenAPI but there is no documentation on the momo page. Can i get access to the implementation in the various languages, especially Javascript

7 replies

Forum|alt.badge.img

From the post man collection, you can generate a js script  

MoMo API PostMan Collection

 

 


  • Author
  • Active
  • January 29, 2024

Thank you. I’m looking at it


  • Author
  • Active
  • January 29, 2024

How do I create the Basic Auth for the createAccessToken function in js?

 


  • Author
  • Active
  • January 29, 2024

async createAccessToken(user_id: string, api_key: string) {

    const endpoint = `${environment.API_BASE2}/collection/token`;

    let my_headers = new Headers();

    my_headers.append("Ocp-Apim-Subscription-Key", this.subscription_key);

    const base64Credentials = Buffer.from(`${user_id}:${api_key}`).toString('base64');

    my_headers.append("Authorization", `Basic ${base64Credentials}`);

    const raw = "";

 

    let request_options = {

      method: 'POST',

      headers: my_headers,

      body: raw,

    };

 

    try {

      const response = await fetch(endpoint, request_options)

 

      if (response.status === 200) {

        const response_data = await  response.json();

        const access_token = response_data.accessToken;

        return access_token;

      }

    } catch (err) {

      console.log(`Error during createAccessToken: ${err}`);

      throw err;

    }

  }

the function above is what i’m using to retrieve the access code

i’m getting err code 400 “Bad request”

 


  • Author
  • Active
  • January 29, 2024


the request gets forwarded

 


  • Author
  • Active
  • January 29, 2024

fails after reaching the final endpoint as ‘BAD REQUEST’

 


  • Author
  • Active
  • January 29, 2024

Fixed now.