Hello,
It’s. my first time to use the momo api. I am trying to create a user in sandbox using firebase authentication trigger function. I subscribed for collections widget and am passing its primary key as the Ocp-Apim-Subscription-Key.
the user is being created successfully when i run in the sandbox but returns access denied when i execute the code.
import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
import { v4 as uuid4 } from "uuid";
export const createUser = functions.auth.user().onCreate(async (user) => {
const uid: string = user?.uid;
const myUUID = uuid4();
const key = functions.config().primarycollection.key;
console.log(myUUID);
try {
await admin.firestore().collection('users').doc().set({
userId: uid,
myUUID,
createdAt: user.metadata.creationTime,
});
const provideUser = await fetch("https://sandbox.momodeveloper.mtn.com/v1_0/apiuser", {
method: "POST",
body: JSON.stringify(
{
"providerCallbackHost": "momocallback.mtn.com",
}
),
headers: {
Accept: "application.json",
"X-Reference-Id": myUUID.toString(),
"Content-Type": "application/json",
"Host": "sandbox.momodeveloper.mtn.com",
"Ocp-Apim-Subscription-Key": key!,
},
cache: 'default'
});
if (provideUser.ok) {
const data = await provideUser.json();
console.log(data);
} else {
console.log('error provisioning user', provideUser.statusText);
}
} catch (error) {
console.log(error);
}
});