Attachment not working for REST API call.

Posted by anu31221@gmail.com on 01-May-2014 06:08

Attachment not working for REST API call. We are not able to attach a file in Lead/Contact after record creation.

Is there any change in API. Are we passing correct key value pair

string base64String;
byte[] byteArray = System.IO.File.ReadAllBytes(mypath);
try
{
base64String = System.Convert.ToBase64String(byteArray, 0, byteArray.Length);
}
catch (System.ArgumentNullException)
{
System.Console.WriteLine("Binary data array is null.");
return;
}
string urlattachmen = string.Format("{0}setBinaryData?sessionId={1}&id={2}&fieldName =file&value=base64Strin&contentType="application/pdf"&value={5}", API_Method.Utils.GlobalURL, Globals.ThisAddIn.SessionID, id, file, base64String,"application/pdf ", "Profile.pdf");
System.Net.WebRequest reqs = System.Net.WebRequest.Create(urlattachmen);
//true means no proxy
System.Net.WebResponse resps = reqs.GetResponse();
System.IO.StreamReader srs = new System.IO.StreamReader(resps.GetResponseStream());
string result = srs.ReadToEnd().Trim();/

All Replies

Posted by Laurent on 02-May-2014 09:44

I am not aware of any bug here but let me check.

Posted by Laurent on 02-May-2014 09:51

Also, could you tell me which Rollbase REST API are you using?

Posted by anu31221@gmail.com on 02-May-2014 10:47

Hi

setBinaryData(sessionId, id, "pdfData", "application/pdf",
"invoice.pdf", binData);

It use to see REST API and SOAP API separately. Now I can see only one.
I an trying to make it work since last 1 week but no success.
Can you help?



Regards
Anu



[collapse]
On Fri, May 2, 2014 at 10:51 AM, Laurent <bounce-lpoulain@community.progress.com> wrote:

Also, could you tell me which Rollbase REST API are you using?

Stop receiving emails on this subject.

Flag this post as spam/abuse.


[/collapse]

Posted by RichardWalsh on 02-May-2014 10:49

ok 2 mins


[collapse]
From: "anu31221@gmail.com" <bounce-anu31221gmailcom@community.progress.com>
To: "TU Rollbase" <TU.Rollbase@community.progress.com>
Sent: Friday, 2 May, 2014 4:47:58 PM
Subject: Re: Attachment not working for REST API call.

Reply by anu31221@gmail.com
Hi

setBinaryData(sessionId, id, "pdfData", "application/pdf",
"invoice.pdf", binData);

It use to see REST API and SOAP API separately. Now I can see only one.
I an trying to make it work since last 1 week but no success.
Can you help?



Regards
Anu



[collapse]
On Fri, May 2, 2014 at 10:51 AM, Laurent <bounce-lpoulain@community.progress.com> wrote:

Also, could you tell me which Rollbase REST API are you using?

Stop receiving emails on this subject.

Flag this post as spam/abuse.


Stop receiving emails on this subject.

Flag this post as spam/abuse.


[/collapse][/collapse]

Posted by Laurent on 02-May-2014 11:02

By "only see one" do you mean in the documentation or something else?

Posted by anu31221@gmail.com on 02-May-2014 12:23

In documentation
Page  453(Page 29 of 122 on open browser page)

I want to attach a document to a record in rollbase through SOAP/REST API call.

Regards
Anu



[collapse]
On Fri, May 2, 2014 at 12:02 PM, Laurent <bounce-lpoulain@community.progress.com> wrote:

By "only see one" do you mean in the documentation or something else?

Stop receiving emails on this subject.

Flag this post as spam/abuse.


[/collapse]

Posted by Laurent on 02-May-2014 12:53

I was able to attach a document to a record using the REST API setDataField method (I however did it in Python not Java). However, you should make sure that the content of the LDF file is base 64-encoded. If that is the case, could you tell me what output are you getting?

Posted by Miguel Saez on 02-May-2014 12:55

Hi Laurent,

Could you please send the example?

Thanks in advance,

Miguel Angel

Enviado desde mi iPhone

El 02/05/2014, a las 19:53, "Laurent" <bounce-lpoulain@community.progress.com> escribió:

Reply by Laurent

I was able to attach a document to a record using the REST API setDataField method (I however did it in Python not Java). However, you should make sure that the content of the LDF file is base 64-encoded. If that is the case, could you tell me what output are you getting?

Stop receiving emails on this subject.

Flag this post as spam/abuse.

Posted by Laurent on 02-May-2014 13:02

Here's my code, written in Python 3.x. Note that you need to change the id and fieldName values in the URL:

import requests, sys, getpass, base64
import xml.etree.ElementTree as ET

# Step 1: Login
base_url = 'https://www.rollbase.com/rest/api/'
login = input("Rollbase login: ")
pw = getpass.getpass()

url = base_url + 'login?loginName=' + login + '&password=' + pw

r = requests.get(url)
tree = ET.fromstring(r.content)

session_id = tree[0].text
print('Session ID: ' + session_id)

# Step 2: call setDataField()
url = base_url + 'setDataField?sessionId=' + session_id + \
     '&id=967518&fieldName=myFieldName' + \
     '&contentType=application/pdf&fileName=test.pdf'
data = {'value': base64.b64encode(open('myfile.pdf', 'rb').read())}
r = requests.post(url, data=data)
print(r.content)

Posted by anu31221@gmail.com on 02-May-2014 17:18

Whats the difference between using setDataField and setBinaryField and setBinaryData

My objective is to upload different type(PDF or DOC) of document to a field in object. I have been trying to use setBinaryData and not working.

Which API should be use

Thank a lot for help
Anu




[collapse]
On Fri, May 2, 2014 at 2:03 PM, Laurent <bounce-lpoulain@community.progress.com> wrote:

Here's my code, written in Python 3.x. Note that you need to change the id and fieldName values in the URL:

import requests, sys, getpass, base64
import xml.etree.ElementTree as ET

# Step 1: Login
base_url = 'https://www.rollbase.com/rest/api/'
login = input("Rollbase login: ")
pw = getpass.getpass()

url = base_url + 'login?loginName=' + login + '&password=' + pw

r = requests.get(url)
tree = ET.fromstring(r.content)

session_id = tree[0].text
print('Session ID: ' + session_id)

# Step 2: call setDataField()
url = base_url + 'setDataField?sessionId=' + session_id + \
      '&id=967518&fieldName=myFieldName&contentType=application/pdf&fileName=test.pdf'
files = { 'value': base64.b64encode(open('myfile.pdf', 'rb').read()) }
r = requests.post(url, data=files)
print(r.content)
Stop receiving emails on this subject.

Flag this post as spam/abuse.


[/collapse]

Posted by Laurent on 06-May-2014 13:08

Good point. setBinaryField belongs to the REST API whereas setBinaryData belongs to the SOAP API. setDataField allows to update a field, whether binary or not.

If neither setBinaryField nor setDataField work for you using the REST API, I would need to know what error you are getting.

This thread is closed