What are methods?
Methods are the main way to interact with our API. Methods are functions: given arguments (entry parameters) a method will output an object variable and/or accomplish an action.
For instance, one of the simplest methods of our API is theĀ sms.send method (doc).
Given four arguments listed below, it returns a hash (8 characters alphanumeric code) which is the unique identifier of the sent SMS (ex: "I8PSZ8O7") if the message was successfully sent.
- from: SMS Sender Name,
- to: SMS destination number,
- body: the message,
- options: object to specify other options such as encoding or SMS nature, can be none.
Before using methods, you need to initialize the API,Ā check the API Basics article forĀ more details.
How to call methods?
You won't be able to call methods until the API is properly initialized. It's a good practice to create a variable that will store the result returned by your API calls. All PHP, Python and Ruby codes shown here and in the docs are structured this way.
Methods are called using the api.call command. For this example, we will use the sms.send method (doc). It sends an SMS to the target number while returning a 8 digits hash ID of the sent SMS.
It requires four parameters in the following order: the sender name (string), the destination number (string), the message content (string) and the options (object). In the following examples, no options are set; the parameter still needs to be imputed (Null/Nill/None object).
PHP
Python
Ruby
NodeJS
What are objects?
Objects are a format type. Methods return outputs objects such as the SMS hash identifier for the sms.send method (doc).
Objects are also used to store information, such as the SMS.options object (doc) where you can specify the nature of the traffic or force a specific encoding.
What are the different data types?
For each method, the documentation lists the expected parameters and their types. Names specified in parenthesis correspond to the way the data types are referred to in the doc.
Integer (Int)
Integers are whole numbers that can be positive, negative or zero. They cannot have decimal places. 2, 2675, and -74 are all integers. IntegersĀ are used whenever a numeric input is needed, to specify the area code and the desired number amount while using the did/store.reserve method for instance (doc).
String
A string is a chain of characters. There are no restrictions regarding its content which can be of any character types, numeric or text. Strings are used to carry content, such as the body of an SMS message in the sms.send method (doc).
Strings must be delimited using inverted commas, for instance: 'string content' or "string content".
Array
Arrays a list of elements formatted using the same data structure. For instance, the did/areacode.countries method return an array of DID countries objects, that is the country with their label, code and boolean regarding DID availability (Classic and Gold).
Print of an array - the result of the did/areacode.countries method (using Python)
Boolean (Bool)
A boolean is a data type with two possibles values: True or False. On the previous screenshot, the CLASSIC and GOLD availability are booleans.
Formats used, their limits, and regular expression
All specific formats used for values are specified in the doc with a description and their regular expressions. (doc)
Comments
Please sign in to leave a comment.