Create a container for attachments with the field code "Attch".
To attach a file to a record with KINTONE
--Upload file --Join with record
Follow the procedure.
If you write it in Python ↓
#!/usr/bin/python
# coding:utf-8
import requests
import json
URL = "https://xxxxx.cybozu.com:443" #kintone subdomain(xxx.cybozu.com)
APP_ID = "ID" #kintone app ID
API_TOKEN = "APP TOKEN" #kintone API token
KNT_PASS = "xxxxxx" #Login name:Base64 encode password
#KINTONE app field code
#Attachment Attach
class KINTONE:
def UploadToKintone(self, url, knt_pass,path,filename):
img = open(path + filename, 'rb')
files={'file':(filename,img,'image/jpeg')}
headers = {"X-Cybozu-Authorization": knt_pass , 'X-Requested-With': 'XMLHttpRequest'}
resp=requests.post(url+"/k/v1/file.json",files=files,headers=headers)
return resp
def PostToKintone(self,url,appId,apiToken,filekey):
record = {
"Attch":{'type':"FILE","value" :[{'fileKey':filekey}]}
#If you want to insert data in other fields','Separated by
}
data = {'app':appId,'record':record}
headers = {"X-Cybozu-API-Token": apiToken, "Content-Type" : "application/json"}
resp=requests.post(url+'/k/v1/record.json',json=data,headers=headers)
return resp
if __name__ == '__main__':
Path='/tmp/' #File save path
FileName='image.jpg' #file name
knt=KINTONE()
resp=knt.UploadToKintone(URL, KNT_PASS,Path,FileName)
txt=json.loads(resp.text)
FileKey=txt['fileKey']
resp=knt.PostToKintone(URL, APP_ID, API_TOKEN,FileKey)
print resp.text
The output is
{"id":"1","revision":"1"}
I felt happy next to me.
Recommended Posts