Skip to main content

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

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

MoMo API PostMan Collection

 

 


Thank you. I’m looking at it


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

 


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”

 



the request gets forwarded

 


fails after reaching the final endpoint as ‘BAD REQUEST’

 


Fixed now.


Reply