• Roy_G
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

In my company we are creating an integration between Salesforce and our Product system. We are using the APEX REST to communicate between our system to Salesforce.

 

I’ve built the integration using a recipe I’ve found in Force.com Cookbook (“Interact with the Force.com REST API from PHP” à http://developer.force.com/cookbook/recipe/interact-with-the-forcecom-rest-api-from-php), however the flow implemented in this recipe requires the user to log in to Salesforce.

The integration I’ve built is a server-to-server integration, what is the best-practice of building a server-to-server REST integration?

I’ve found an article in Stack Overflow that mentioned logging-in using SOAP and then calling  REST services using the SOAP session-Id, but it seems like hacking to me, can you please point me to the right direction?

Thank you,

Roy

 

  • October 31, 2011
  • Like
  • 0

Yup, it's me again.

I dunno if I just suck, or if I'm really pushing this parser. I am making a call to facebook to get user data. The user data comes back as JSON. Most of it is simple string data. There are 3 fields that are arrays. Those arrays contain only 2 items (id and name). I have attempted to create the class based on the JSON and deserialize into it. I am receiving another salesforce system error.

 

System.UnexpectedException: Salesforce System Error: 996229906-358 (-433257328) (-433257328) 
An unexpected error has occurred. Your solution provider has been notified. (system)

Here is the json I am attempting to parse (cleaned up a bit)

{
    "id": "XXXXX",
    "name": "XXXXXX XXXXXXX",
    "first_name": "XXXXXX",
    "last_name": "XXXXXX",
    "link": "http://www.facebook.com/XXXXXX",
    "username": "XXXXXX",
    "about": "some data about the person.",
    "birthday": "00/00/0000",
    "hometown": {
        "id": "XXXXXXXXXXXXXXXXXXXXXXXX",
        "name": "Somewhere, New York"
    },
    "location": {
        "id": "XXXXXXXXXXXXXXXXXXXXXXXX",
        "name": "Nowhere, Nevada"
    },
    "bio": "This is some demo text",
    "inspirational_people": [
        {
            "id": "109425469076258",
            "name": "Miyamoto Musashi"
        },
        {
            "id": "112377255503169",
            "name": "Kenshin Himura"
        },
        {
            "id": "135952326470380",
            "name": "Spike Spiegel"
        },
        {
            "id": "146133595436195",
            "name": "Kamina"
        },
        {
            "id": "12534674842",
            "name": "Albert Einstein"
        },
        {
            "id": "184049470633",
            "name": "Bruce Lee"
        }
    ],
    "gender": "male",
    "email": "XXXXXX@XXXXXX.com",
    "timezone": -4,
    "locale": "en_US",
    "verified": true,
    "updated_time": "2011-11-07T21:17:55+0000"
}


OR EASILY PASTEABLE VERSION
{ "id": "XXXXX", "name": "XXXXXX XXXXXXX", "first_name": "XXXXXX", "last_name": "XXXXXX", "link": "http://www.facebook.com/XXXXXX", "username": "XXXXXX", "about": "some data about the person.", "birthday": "00/00/0000", "hometown": { "id": "XXXXXXXXXXXXXXXXXXXXXXXX", "name": "Somewhere, New York" }, "location": { "id": "XXXXXXXXXXXXXXXXXXXXXXXX", "name": "Nowhere, Nevada" }, "bio": "This is some demo text", "inspirational_people": [ { "id": "109425469076258", "name": "Miyamoto Musashi" }, { "id": "112377255503169", "name": "Kenshin Himura" }, { "id": "135952326470380", "name": "Spike Spiegel" }, { "id": "146133595436195", "name": "Kamina" }, { "id": "12534674842", "name": "Albert Einstein" }, { "id": "184049470633", "name": "Bruce Lee" } ], "gender": "male", "email": "XXXXXX@XXXXXX.com", "timezone": -4, "locale": "en_US", "verified": true, "updated_time": "2011-11-07T21:17:55+0000" } 

 

 Here is the code I am trying to run. You should be able to run this in execute anonymous. I have tried running it regular as well (being invoked by the page, which has the class as a controller) and get the same error either way.



string jsonData = '{ "id": "XXXXX", "name": "XXXXXX XXXXXXX", "first_name": "XXXXXX", "last_name": "XXXXXX", "link": "http://www.facebook.com/XXXXXX", "username": "XXXXXX", "about": "some data about the person.", "birthday": "00/00/0000", "hometown": { "id": "XXXXXXXXXXXXXXXXXXXXXXXX", "name": "Somewhere, New York" }, "location": { "id": "XXXXXXXXXXXXXXXXXXXXXXXX", "name": "Nowhere, Nevada" }, "bio": "This is some demo text", "inspirational_people": [ { "id": "109425469076258", "name": "Miyamoto Musashi" }, { "id": "112377255503169", "name": "Kenshin Himura" }, { "id": "135952326470380", "name": "Spike Spiegel" }, { "id": "146133595436195", "name": "Kamina" }, { "id": "12534674842", "name": "Albert Einstein" }, { "id": "184049470633", "name": "Bruce Lee" } ], "gender": "male", "email": "XXXXXX@XXXXXX.com", "timezone": -4, "locale": "en_US", "verified": true, "updated_time": "2011-11-07T21:17:55+0000" }';    
class facebookUser
    {
        public string id;
        public string name;
        public string first_name;
        public string last_name;
        public string link;
        public string username;
        public string about;
        public string birthday;
        public string gender;
        public string email;
        public string timezone;
        public string locale;
        public string verified;
        public string updated_time;
        public list<dataItem> hometown;
        public list<dataItem> location;
        public list<dataItem> inspirational_people;
        
        public facebookUser(string id, string name, string first_name, string last_name, string link, string username, string about, string birthday, string gender, string email, string timeZone, string locale, string verified, string updated_time)
        {
            this.id = id;
            this.name = name;
            this.first_name = first_name;
            this.last_name = last_name;
            this.link = link;
            this.username = username;
            this.about = about;
            this.birthday = birthday;
            this.gender = gender;
            this.email = email;
            this.timeZone = timeZone;
            this.locale = locale;
            this.verified = verified;
            this.updated_time = updated_time;
            this.hometown =  new list<dataItem>();
            this.location =  new list<dataItem>();
            this.inspirational_people = new list<dataItem>();      
        }
    }
    
    class dataItem 
    {
        public string id;
        public string name;
        
        public dataItem(string id, string name)
        {
            this.id = id;
            this.name = name;
        }
    }

//I have tried deserializing to a list, as well as a single object list<facebookUser> d = (list<facebookUser>)JSON.deserialize( jsonData,facebookUser.class);

//This fails too
facebookUser d = (facebookUser)JSON.deserialize( jsonData,facebookUser.class); 

 

Any thoughts would be much appreciated. Thank you.

In my company we are creating an integration between Salesforce and our Product system. We are using the APEX REST to communicate between our system to Salesforce.

 

I’ve built the integration using a recipe I’ve found in Force.com Cookbook (“Interact with the Force.com REST API from PHP” à http://developer.force.com/cookbook/recipe/interact-with-the-forcecom-rest-api-from-php), however the flow implemented in this recipe requires the user to log in to Salesforce.

The integration I’ve built is a server-to-server integration, what is the best-practice of building a server-to-server REST integration?

I’ve found an article in Stack Overflow that mentioned logging-in using SOAP and then calling  REST services using the SOAP session-Id, but it seems like hacking to me, can you please point me to the right direction?

Thank you,

Roy

 

  • October 31, 2011
  • Like
  • 0