
Code-Beispiele für Entwickler
Unsere Code-Beispiele in vielen gängigen Programmiersprachen sollen Ihnen dabei helfen, die API in ihrer Anwendungsumgebung zu implementieren.
Curl
curl -X 'POST' \
  'https://api.berlinsms.de/send/sms/4917012345/Hallo%20world' \
  -H 'apiKey: [apiKey]'    
  
    
  OpenAPI
paths:
  /send/sms/{phonenumber}/{text}:
    post:
      tags:
        - send
      summary: send one single message to a number
      operationId: sendSingleSMS
      security:
        - apikeyAuth: [apiKey]
      parameters:
        - name: phonenumber
          in: path
          description: destination telephon number
          schema:
            type: number
          required: true
        - name: text
          in: path
          description: text to send
          schema:
            type: string
          example: Hallo World
          required: true
      responses:
        '200':
          description: successful operation
          content: {}
components:
  securitySchemes:
    apikeyAuth:
      type: apiKey
      in: header
      name: apiKey
servers:
  - url: 'https://api.berlinsms.de'
    
  
    
  PHP
<?php
$context = stream_context_create(array(
  'http'=>array(
    'method'=>"POST",
    'header'=>"apiKey: $apiKey"
  )
);
$url = 'https://api.berlinsms.de/send/sms/'.$phonenumber.'/'.rawurlencode($message);
$file = file_get_contents( $url, false, $context );
?>    
  
    
  C#
using System.Web;
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add( "apiKey", apiKey );
string url = "https://api.berlinsms.de/send/sms/"+ phonenumber +"/" + Uri.EscapeDataString(message);
httpClient.PostAsync(url, null);    
  
    
  JavaScript
const options = { method: 'POST', headers: { apiKey: apiKey } };
const url = 'https://api.berlinsms.de/send/sms/' + phonenumber + '/' + encodeURIComponent(message);
fetch(url,options)
    .then(console.log);    
  
    
  Perl
use LWP::UserAgent;
use URI::Encode qw(uri_encode);
my $url = 'https://api.berlinsms.de/send/sms/' . $phonenumber + '/' . uri_encode($message);
my $ua = LWP::UserAgent->new();
my $response = $ua->post(
	$url, 
	apiKey=>$apiKey
);    
  
    
  Python
import requests
import urllib.parse 
headers = {'apiKey': apiKey} 
url = "https://api.berlinsms.de/send/sms/"+ str(phonenumber) +"/" + urllib.parse.quote(message); 
requests.post(url, headers=headers)