2022

Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Panel
What is REST API ?

The  REST API provide programmatic access to read and write application data. The REST API identifies the application and its users using OAUTH  ; responses are available in json.  We have used SWAGGER editor for the end users to make the API calls so that they can try out APIs exposed API management platform. 

Click Here for accessing the CW-API management platform for unregistered user.

Checklist Before Getting Started 

...

Checklist before getting started 

There are various API Methods list which are exposed for this release , we will be adding more methods in the upcoming releases . 

  1. User should have the release of 4.2.9 or later .
  2. A valid salesforce Salesforce and FTP credentials 

There are various API Methods list which are exposed for this release , we will be adding more methods in the upcoming releases . 


SalesForceToFileSystem API

The SalesForceToFileSystem Api Code  method is the actual API call used to invoke the Api Method so that the file from passed Salesforce objects gets downloaded  to the assigned file path of the FTP server.

The below tables explains the various model schema and attributes which form the model class 

SaleForceFile params 

...

Parameter

...

Description

...

DataType

...

sfConfig (Optional)

...

The salesforce credentials which are required to connect to the salesforce instance

...

Salesforce

...

fsConfig (optional)

...

The FTP server credentials which are required to connect to FTP server for downloading a file

...

FTP

...

queryToTheAttachment (optional)

...

The salesfoce object to specify a file to be downloaded

...

String

Salesforce Params

...

Parameter

...

Description

...

DataType

...

username(Required)

...

The username of the salesforce instance from which the user wishes to retrieve information from where the file to be downloaded

...

string

...

password(Required)

...

The password of the salesforce instance

...

string 

...

securityToken(Required)

...

A security Token is a case sensitive alpha numeric code that you append to the password or enter in a separate field in client application

...

string

...

sessionID(optional)

...

An Identifier for current user in the current context

...

string

...

endpointURL(Required)

...

The url to access the salesforce application

...

string

FileSystem Params

Parameter

Description

DataType

host(Required)

Hostname of ftp server

string

port(Required)

port number of ftp server

string

filesystemType

The possible supported FTP are Sftp, FTPS and plain FTP

string

username(Required)

ftp server username

string

password(Required)

ftp server password

string

folder(Required)

path within ftp server to place the file

string

Run Properties Params

Below table gives the attribute list of the response class

...

Parameter

...

Description

...

Data type

...

Status

...

The possible values are True and False which sends out the response value

...

String

...

SubmitTime

...

The API submitted time

...

Date

...

CompletionTime

...

The API Completion Time

...

Date

...

ProcessID

...

The process id which is sent by the API to identify the process

...

String

...

callbackURL

...

The url is passed from the API

...

string

Example For UnSucessful Download 
Curl
Code Block
curl -X POST --header 'Content-Type: application/json' --header
'Accept: application/json' -d '{"sfConfig":{"username":"","password":"","securityToken":"","sessionId":"","endpointURL":""},
"fsConfig":{"host":"","port":"","filesystemType":"","username":"","password":"","folder":""},"queryToTheAttachment":""}'
'https://api.mydbsync.com:443/api/appcode/v1/sftofilesystem/upsertFile'

Request URL
Code Block
https://api.mydbsync.com:443/api/appcode/v1/sftofilesystem/upsertFile

Response Body
Code Block
{
  "error": "AppCode:sftofilesystem does not exist, Please check your URL"
}
Response Code
Code Block
 200
Response Header
Code Block
{
"date": "Mon, 20 Feb 2017 18:44:54 GMT",

"server": "Apache/2.4.25 (Amazon) OpenSSL/1.0.1k-fips",

"connection": "Keep-Alive",

"keep-alive": "timeout=5, max=100",

"content-length": "72",

"content-type": "application/json"

}

In order for an unregistered to access this API method.

Click on SFToFTP url  to try out the method 

Title

SalesForceToFileSystem API

URL

The URL Structure (path only, no root url) is v1/sftofilesystem

  1. v1 changes whenever we the method is updated
  2. The user can access the relevant method call by entering appropriate version before the method name.



MethodThe Request type is POST
URL ParamsN/A
Data Params

As the SalesForceToFileSystem is a post request, The body payload should be in below format

{
  "sfConfig":  { 
 "username": "string",
 "password": "string",
 "securityToken": "string",
 "sessionId": "string",
 "endpointURL": "string" 
 },
   "targets": [ { 
    "host": "string", 
    "port": "string", 
    "filesystemType": "string", 
    "username": "string", 
    "password": "string", 
    "folder": "string", 
    "bucket": "string", 
    "targetFileName": "string",
     "region": "string" } 
 ],
  "queryToTheAttachment": "string" }


Example

As the SalesForceToFileSystem is a post request, The body payload should be in below format

{
  "sfConfig":  { 
 "username": "john@avankia.com",
 "password": "123456",
 "securityToken": "00P2800000lT3mq",
 "sessionId": "",
 "endpointURL": "https://ap2.salesforce.com/services/Soap/u/39.0" 
 },
   "targets": [ { 
    "host": "accounting.avankia.com", 
    "port": "21", 
    "filesystemType": "ftp", 
    "username": "anil.b@avankia.com", 
    "password": "123456", 
    "folder": "root", 
    "bucket": "string", 
    "targetFileName": "",
     "region": "" } 
 ],
  "queryToTheAttachment": "select Name,Body from attachment where id = '00P2800000lT3mq'" }


Success Response

The status code on Success reponse should be 200.


Example

Code : 200

Response Body :

[
{
"id": "testFiles/SanAntonio Queries After Trigger.txt",
"newid": "testFiles/SanAntonio Queries After Trigger.txt",
"success": true,
"errors": [null]
}
]

Error Response

Most endpoint will have many ways they can fail. Below are some of the known error reponse code and response body.

Code 401 : Unautorized access

Code 403 : Forbidden error

Example

Code : 403

Response Body :

<!DOCTYPE html><html><head><title>Apache Tomcat/8.0.41 - 
Error report</title><style type="text/css">H1 
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} 
H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} 
H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;}
BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;}
B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} 
P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}
A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;
} </style> </head><body><h1>HTTP Status 403 - Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'.</h1><div class="line"></div><p><b>type</b> Status report</p><p><b>message</b> <u>Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'.</u></p><p><b>description</b> <u>Access to the specified resource has been forbidden.</u></p><hr class="line"><h3>Apache Tomcat/8.0.41</h3></body></html>

Sample Call
The below is the sample call from the endpoint. This would make the API call more predictable for the user.

curl -X POST --header 'Content-Type: application/json' --header 'Accept: text/html' -d '
{"sfConfig":
{"username":"anil.b@avankia.com",
"password":"@Raman123",
"securityToken":"fbEw74CxeC8kcxLK2zUnAlcp3",
"sessionId":"https://ap2.salesforce.com/services/Soap/u/39.0",
"endpointURL":"string"},
"targets":[{"host":"107.180.12.172","port":"21",
"filesystemType":"ftp",
"username":"dbsyncftp@hrnewspad.com",
"password":"AvankiaFTP789()",
"folder":"testFiles",
"bucket":"",
"targetFileName":"",
"region":""}],
"queryToTheAttachment":"select Name,Body  from attachment where id = \u002700P2800000lT3mq\u0027"}'
'https://api.mydbsync.com:443/api/appcode/v1/sftofilesystem/upsertFile'