Crear URL Corta
URL:https://www.onurix.com/api/v1/url/short
Devuelve estadísticas de la URL a partir de su nombre
Parametros.
Nombre | Tipo | Requerido | Descripción |
---|---|---|---|
client | integer(int64) | true | El Id del cliente |
key | string | true | Key de la cuenta Onurix |
name | string | true | Nombre de la URL corta |
url-long | string | true | URL larga |
alias | string | false | Alias para la URL corta |
is-premium | boolean | false | Es premium por defecto falso |
group-name | string | false | Grupo al que se desea asociar |
domain-name | string | false | Dominio al que se desea asociar |
expiration-time-statistics | string | false | Expiración de la URL en meses valores por defecto enviar 0 |
Respuesta.
Estado | Significado | Descripción | Esquema |
---|---|---|---|
200 | OK | Operación exitosa | JsonResponse |
400 | Client Error | Parametros invalidos | JsonResponse |
520 | Unknown | Error interno del sistema | ErrorResponse |
Code request
curl -X POST "https://www.onurix.com/api/v1/url/short" -d key="AQUI_SU_KEY" -d client="AQUI_SU_CLIENT" -d name="AQUI_NOMBE_DE_URL" -d url-long="AQUI_URL_LARGA" -d alias="OPCIONAL_AQUI_ALIAS" -d is-premium="OPCIONAL_AQUI_TRUE_OR_FALSE_DEFAULT_FALSE" -d group-name="OPCIONAL_AQUI_NOMBRE_DE_GRUPO" -d domain-name="OPCIONAL_AQUI_NOMBRE_DOMINIO_REGISTRADO" -d expiration-time-statistics="OPCIONAL_AQUI_TIEMPO_ALMACENAMIENTO-ESTADITICAS" -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json'
Code request
<?php
// Ejecutar: composer require guzzlehttp/guzzle:*
require'vendor/autoload.php';
$headers=array(
'Content-Type'=>'application/x-www-form-urlencoded',
'Accept'=>'application/json',
);
$client= new \GuzzleHttp\Client();
// Define la matriz del cuerpo de la solicitud.
$request_body = array(
"client"=>"AQUI_SU_CLIENT",
"key"=>"AQUI_SU_KEY",
"name"=>"AQUI_NOMBE_DE_URL",
"url-long"=>"AQUI_URL_LARGA",
"alias"=>"OPCIONAL_AQUI_ALIAS",
"is-premium" => "OPCIONAL_AQUI_TRUE_OR_FALSE_DEFAULT_FALSE",
"group-name" => "OPCIONAL_AQUI_NOMBRE_DE_GRUPO",
"domain-name" => "OPCIONAL_AQUI_NOMBRE_DOMINIO_REGISTRADO",
"expiration-time-statistics" => "OPCIONAL_AQUI_TIEMPO_ALMACENAMIENTO-ESTADITICAS"
);
try{
$response=$client->request('POST','https://www.onurix.com/api/v1/url/short',array(
'headers'=>$headers,
'form_params'=>$request_body,
)
);
print_r($response->getBody()->getContents());
}
catch(\GuzzleHttp\Exception\BadResponseException $e){
// Manejar excepciones o errores de API
print_r($e->getMessage());
}
Code request
import requests
headers ={
'Content-Type':'application/x-www-form-urlencoded',
'Accept':'application/json'
}
data = {
'client':'AQUI_SU_CLIENT',
'key':'AQUI_SU_KEY',
'name':'AQUI_NOMBRE_DE_URL',
'url-long':'AQUI_URL_LARGA',
'alias':'OPCIONAL_AQUI_ALIAS',
'is-premium':'OPCIONAL_AQUI_TRUE_OR_FALSE_DEFAULT_FALSE',
'group-name':'OPCIONAL_AQUI_NOMBRE_DE_GRUPO',
'expiration-time-statistics':'OPCIONAL_AQUI_TIEMPO_ALMACENAMIENTO-ESTADITICAS',
}
r = requests.post('https://www.onurix.com/api/v1/url/short', headers = headers, data = data)
print(r.json())
Code request
//Este codigo fue hecho en .net 6
using System.Net.Http;
namespace PruebaOnurix
{
public class Program
{
public static void Main(string[] args)
{
Dictionary<string, string> parameters = new()
{
{ "client", "AQUI_SU_CLIENT"},
{ "key", "AQUI_SU_KEY"},
{ "name", "AQUI_NOMBRE_DE_URL"},
{ "url-long","AQUI_URL_LARGA"},
{ "alias", "OPCIONAL_AQUI_ALIAS"},
{ "is-premium", "OPCIONAL_AQUI_TRUE_OR_FALSE_DEFAULT_FALSE"},
{ "group-name", "OPCIONAL_AQUI_NOMBRE_DE_GRUPO"},
{ "expiration-time-statistics", "OPCIONAL_AQUI_TIEMPO_ALMACENAMIENTO-ESTADITICAS"}
};
UrlShortener(parameters);
}
public static void UrlShortener(Dictionary<string,string> parameters)
{
using var httpClient = new HttpClient()
{
BaseAddress = new Uri("https://www.onurix.com"),
};
HttpResponseMessage request = httpClient.PostAsync("/api/v1/url/short", new FormUrlEncodedContent(parameters)).Result;
string responseString = request.Content.ReadAsStringAsync().Result;
Console.WriteLine(responseString);
}
}
}
Code request
package main
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
)
func main() {
headers := map[string][]string{
"Content-Type": []string{"application/x-www-form-urlencoded"},
"Accept": []string{"application/json"},
}
data := strings.NewReader("client=AQUI_SU_CLIENT&key=AQUI_SU_KEY&name=AQUI_NOMBRE_DE_URL&url-long=AQUI_URL_LARGA&alias=OPCIONAL_ALIAS_URL&is-premium=OPCIONAL_AQUI_TRUE_OR_FALSE_DEFAULT_FALSE&group-name=OPCIONAL_AQUI_NOMBRE_DE_GRUPO&expiration-time-statistics=OPCIONAL_AQUI_TIEMPO_ALMACENAMIENTO_ESTADITICAS")
req, err := http.NewRequest("POST", "https://www.onurix.com/api/v1/url/short", data)
req.Header = headers
client := &http.Client{}
resp, err := client.Do(req)
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
Code request
// Ejecutar: npm install axios --save
const axios = require('axios').default;
let headers = {headers:
{ 'content-type': 'application/x-www-form-urlencoded'}
};
let data= {
'client':'AQUI_SU_CLIENT',
'key':'AQUI_SU_KEY',
'name':'AQUI_NOMBRE_DE_URL',
'url-long':'AQUI_URL_LARGA',
'alias':'OPCIONAL_AQUI_ALIAS',
'is-premium':'OPCIONAL_AQUI_TRUE_OR_FALSE_DEFAULT_FALSE',
'group-name':'OPCIONAL_AQUI_NOMBRE_DE_GRUPO',
'expiration-time-statistics':'OPCIONAL_AQUI_TIEMPO_ALMACENAMIENTO-ESTADITICAS',
}
axios.post('https://www.onurix.com/api/v1/url/short',data,headers)
.then(resp=>{
console.log(resp.data);
}).catch(error=>{
console.log(error);
});
Code request
//Para este codigo se uso jdk 11
import java.io.IOException;
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class URLShortener {
public static void main(String[] args) throws IOException, InterruptedException {
// TODO Auto-generated method stub
Map<String,String> parameters = new HashMap<>();
parameters.put("client", "AQUI_SU_CLIENT");
parameters.put("key", "AQUI_SU_KEY");
parameters.put("name", "AQUI_NOMBE_DE_URL");
parameters.put("url-long", "AQUI_URL_LARGA");
parameters.put("alias", "OPCIONAL_AQUI_ALIAS");
parameters.put("is-premium", "OPCIONAL_AQUI_TRUE_OR_FALSE_DEFAULT_FALSE");
parameters.put("group-name", "OPCIONAL_AQUI_NOMBRE_DE_GRUPO");
parameters.put("expiration-time-statistics", "OPCIONAL_AQUI_TIEMPO_ALMACENAMIENTO-ESTADITICAS");
var httpClient = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
.version(HttpClient.Version.HTTP_2)
.POST(ofFormData(parameters))
.uri(URI.create("https://www.onurix.com/api/v1/url/short"))
.header("Content-Type", "application/x-www-form-urlencoded")
.build();
var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
//System.out.println(response.body());
}
public static HttpRequest.BodyPublisher ofFormData(Map<String, String> parameters) {
var builder = new StringBuilder();
for (Entry<String, String> entry : parameters.entrySet()) {
if (builder.length() > 0) {
builder.append("&");
}
builder.append(URLEncoder.encode(entry.getKey().toString(), StandardCharsets.UTF_8));
builder.append("=");
builder.append(URLEncoder.encode(entry.getValue().toString(), StandardCharsets.UTF_8));
}
return HttpRequest.BodyPublishers.ofString(builder.toString());
}
}
Body parameters
client: 0,
key: "string",
name: "string",
url-long: "string",
alias: "string",
is-premium: false,
group-name: "string",
domain-name: "string",
expiration-time-statistics: "string"
Respuesta de ejemplo
Response 200
{
"urlShort": "string",
"urlLong": "string",
"msg": "string"
}
Si requiere asistencia o tiene un problema, envienos un mensaje para poder ayudarlo
soporte@onurix.com