SugarCrm:input record with own id. tSugarCrmOutput VS tRest component

One Star

SugarCrm:input record with own id. tSugarCrmOutput VS tRest component

Hi,
Using Talend Integration Suite Enterprise Edition (4.2.1.r60995).
I'm searching a way to insert records in SugarCRM with my own id.
I looked from tSugarOutput and saw that is probably not possible due of limitations of setRecord function : new_with_id flag is not supported...
I have a look about tRest but i did not find any complete example to use it with SugarCrm.
Is anyone always use tRest component to insert record in SugarCrm ?
Thanks for answers.
Moderator

Re: SugarCrm:input record with own id. tSugarCrmOutput VS tRest component

Hi BorisL,
Using Talend Integration Suite Enterprise Edition (4.2.1.r60995).


This is a very  old version. Have you tried it on latest build version Talend studio 5.6.1 to see if it is OK?

Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: SugarCrm:input record with own id. tSugarCrmOutput VS tRest component

Hi,
I have found a simple REST java solution using two tJava component.
(not clean but adequate to my needs and sorry for that, due to my very little experience...)
In a first tJava retrive token by using an adapted code from link to original code
on stackoverflow.com, (thanks to Lisandro and jitter)
(Advanced param)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.URL;
import java.net.URLConnection;
(Simple param)
//token URL
URL url = new URL("https://<myURL>/rest/v10/oauth2/token");
//Insert your JSON query request
String query = "{'grant_type':'password', 'client_id':'<clientid>', 'client_secret':'', 'username':'<login>', 'password':'<pass>', 'platform':'base'}";
//It change the apostrophe char to double colon char, to form a correct JSON string
query=query.replace("'", "\"");
try{
    //make connection
    URLConnection urlc = url.openConnection();
    //It Content Type is so important to support JSON call
    urlc.setRequestProperty("Content-Type", "application/xml");
    //System.out.println("Connexion : " + url.toString());
   
    //use post mode
    urlc.setDoOutput(true);
    urlc.setAllowUserInteraction(false);
    //send query
    PrintStream ps = new PrintStream(urlc.getOutputStream());
    ps.print(query);
    //--> !!!Warning!!! login et password are visibles here : System.out.println("Query : " + query);
    ps.close();
    //get result
    BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
    String l = null;
    while ((l=br.readLine())!=null) {
        System.out.println("Read : "+l);
    }
   
    -- TODO save access_token value --
   
    br.close();
} catch (Exception e){
    System.out.println("Errorr Get Token !");
    System.out.println(e.toString());
}
System.out.println("-");
System.out.println("END GET TOKEN");
System.out.println("-");
//END OF tJava_1 CODE
----
Next step :
Copy tJava_1 to tJava_2
Plug tJava2 from tJava_1
Modify :
URL url = new URL("https://<myURL>/rest/v10/Accounts");
Modify :
String query = "{'new_with_id':1, 'id':'MY_ID', 'name':'toto'}";
Add :
urlc.setRequestProperty("oauth-token", -- saved access_token value (directly without prefixe) -- );
Modify :
System.out.println("Error Create Account !");

----
Best regards.
BorisL
P.S. : how do i indicate ?
One Star

Re: SugarCrm:input record with own id. tSugarCrmOutput VS tRest component

Hi,
the tSugarCrmOutput component you tried is also very old and outdated.
Coudbee has two different output components for SugarCRM integrations: http://cloudbee.com/sugar-crm-talend-component/
Never tested if creating items with specific id's works with our components but if the topic is still hot then please contact to Cloudbee support and we will find out. If it is not supported then may be we can change the components to make it work.
Peter
http://cloudbee.com
Talend Components Provider