How to Create an User in Workplace

Account Management API w/ Java

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;

public class WorkplaceSample {

public static void main(String[] args) {
Client client = ClientBuilder.newClient();

client.target("https://www.facebook.com/scim/v1/Users").request().header("Authorization", "...").post(Entity.json("{ \"schemas\": [ \"urn:scim:schemas:core:1.0\" ], \"userName\": \"sampleEmailAddress\", \"name\": { \"formatted\": \"Sample User\" }, \"active\": true }")); // invites aren't sent automatically by default

client.close();
}

}

Account Management API w/ Go

package main

import "github.com/go-resty/resty/v2"

func main() {
client := resty.New()

client.R().SetHeader("Authorization", "...").SetHeader("Content-Type", "application/json").SetBody(`{ "schemas": [ "urn:scim:schemas:core:1.0" ], "userName": "sampleEmailAddress", "name": { "formatted": "Sample User" }, "active": true }`).Post("https://www.facebook.com/scim/v1/Users") // invites aren't sent automatically by default
}

Account Management API w/ Node.js

const https = require('https')

var req = https.request({ headers: { 'Authorization': '...', 'Content-Type': 'application/json', 'User-Agent': 'Sample Client' }, hostname: 'www.facebook.com', method: 'POST', path: '/scim/v1/Users' })

req.write('{ "schemas": [ "urn:scim:schemas:core:1.0" ], "userName": "sampleEmailAddress", "name": { "formatted": "Sample User" }, "active": true }') // invites aren't sent automatically by default

req.end()

Account Management API w/ Python

import requests

requests.post('https://www.facebook.com/scim/v1/Users', json = { 'schemas': [ 'urn:scim:schemas:core:1.0' ], 'userName': 'sampleEmailAddress', 'name': { 'formatted': 'Sample User' }, 'active': True }, headers = { 'Authorization': '...' }) # invites aren't sent automatically by default

Account Management API w/ Ruby

require 'rest-client'

RestClient.post 'https://www.facebook.com/scim/v1/Users', '{ "schemas": [ "urn:scim:schemas:core:1.0" ], "userName": "sampleEmailAddress", "name": { "formatted": "Sample User" }, "active": true }', :authorization => '...', :content_type => 'application/json' # invites aren't sent automatically by default

Graph API w/ Java

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;

public class WorkplaceSample {

public static void main(String[] args) {
Client client = ClientBuilder.newClient();

MultivaluedMap<String, String> params = new MultivaluedHashMap<>();

params.putSingle("email", "sampleEmailAddress");
params.putSingle("name", "Sample User");

client.target("https://graph.facebook.com/company/accounts").request().header("Authorization", "...").post(Entity.form(params));

client.close();
}

}

Graph API w/ Go

package main

import "github.com/go-resty/resty/v2"

func main() {
client := resty.New()

client.R().SetHeader("Authorization", "...").SetBody("email=sampleEmailAddress&name=Sample%20User").Post("https://graph.facebook.com/company/accounts")
}

Graph API w/ Node.js

const https = require('https')

var req = https.request({ headers: { 'Authorization': '...', 'User-Agent': 'Sample Client' }, hostname: 'graph.facebook.com', method: 'POST', path: '/company/accounts' })

req.write('email=sampleEmailAddress&name=Sample%20User')

req.end()

Graph API w/ Python

import requests

requests.post('https://graph.facebook.com/company/accounts', params = { 'email': 'sampleEmailAddress', 'name': 'Sample User' }, headers = { 'Authorization': '...' })

Graph API w/ Ruby

require 'rest-client'

RestClient.post 'https://graph.facebook.com/company/accounts', { :email => 'sampleEmailAddress', :name => 'Sample User' }, :authorization => '...'

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.