static postPersonaAPI()

in loginconnect_directintegrator/services/graph-api.js [240:282]


  static postPersonaAPI(name, profile_picture_url) {
    let body = [];

    return new Promise(function(resolve, reject) {
      // Send the POST request to the Personas API
      console.log(`Creating a Persona for app ${config.appId}`);

      let requestBody = {
        name: name,
        profile_picture_url: profile_picture_url
      };

      request({
        uri: `${config.mPlatfom}/me/personas`,
        qs: {
          access_token: config.pageAccesToken
        },
        method: "POST",
        json: requestBody
      })
        .on("response", function(response) {
          // console.log(response.statusCode);
          if (response.statusCode !== 200) {
            reject(Error(response.statusCode));
          }
        })
        .on("data", function(chunk) {
          body.push(chunk);
        })
        .on("error", function(error) {
          console.error("Unable to create a persona:", error);
          reject(Error("Network Error"));
        })
        .on("end", () => {
          body = Buffer.concat(body).toString();
          // console.log(JSON.parse(body));

          resolve(JSON.parse(body).id);
        });
    }).catch(error => {
      console.error("Unable to create a persona:", error, body);
    });
  }