Campaign
This will create new campaign for Ayobantu partner themself.
Create Campaign
POST {base_url}/api/v1/partner/campaign
Create new campaign to partner account in Ayobantu
Headers
Authorization
String
Bearer <api_token>
Content-Type*
String
multipart/form-data; boundary=<calculated when request is sent>
Request Body
title*
String
Marathon Run (Alpha/Numeric Only) and 3-100 characters
category*
Numeric
1=Bencana; 2=Sosial; 3=Pendidikan; 4=Kesehatan; 5=Olahraga; 6=Kerohanian; 7=Kebudayaan; 8=Lainnya; 9=Lingkungan Hidup
campaign_image*
File
Max. 1MB (.jpg/.jpeg/.png/.webp). Image will be resized to 800x800 automatically by system
campaign_banner*
File
Max. 1MB (.jpg/.jpeg/.png/.webp). Image will be resized to 1280x720 automatically by system
signature_key*
String
Signature code generated every time you make a request. See more, click here.
Formula:
hash("sha512", title + category + partner_code + secret_key);
Example Output:
fc4152dcc06f4487b022883d3118b2aa81996e0e697bb1550b9e83beacea4f76fd772c2f9fe4b77974bef1c39e183c9530affb66fbbf5320f3d6df571ed472e2
description (Optional)
String
10-100.000 characters
target_donation (Optional)
Numeric
1.000.000 to 100.000.000 (default 1.000.000)
minimum_donation (Optional)
Numeric
10.000 to 1.000.000 (default 10.000)
expired_at (Optional)
Unix timestamp
Campaign end date. (default 30 days from time submit)
Example: 1732163756
beneficiary_information (Optional)
String
5-100.000 characters
{
"status_code": "200",
"message": "Success",
"data": {
"campaign_id" : 1818,
"campaign_link" : "https://ayobantu.com/marathon-run"
}
}{
"status_code": "404",
"message": "The requested resource is not found",
"erros": [
"Partner not found"
]
}{
"status_code": "500",
"message": "Internal Server Error",
"erros": [
"Registration failed"
]
}{
"status_code": "422",
"message": "Unprocessable Entity",
"erros": [
"Title is required",
"Category is required"
]
}{
"status_code": "429",
"message": "Too Many Attempts",
"erros": [
"Please wait 1 minute for next request"
]
}// Example Generate Signature Key
//secret_key = '353656da-1695-434b-9f61-a3c9ff90894f';
hash("sha512", 'Marathon Run2AYB12345353656da-1695-434b-9f61-a3c9ff90894f')
//Result
01b2eb96f63a74f46ccc2431952b39b6704dce330ad611d9ede62e70c27a954e696a503941ae4cbf0262686825cd004a1afa624d3fe6a1513910dc2b5cd4b81e
curl
--location --request POST {base_url}'/api/v1/partner/campaign' \
--header 'Authorization: Bearer 88A4B7FEADD1667B' \
--form 'title="Marathon Run"' \
--form 'category="3"' \
--form 'campaign_image=@"/Downloads/illustrator/image.jpg"' \
--form 'campaign_banner=@"//Downloads/illustrator/banner.jpg"' \
--form 'partner_code="AYB12345"' \
--form 'signature_key="01b2eb96f63a74f46ccc2431952b39b6704dce330ad611d9ede62e70c27a954e696a503941ae4cbf0262686825cd004a1afa624d3fe6a1513910dc2b5cd4b81e"'
--form 'description="campaign ini merupakan bagian dari contoh"' \
--form 'target_donation="2000000"' \
--form 'minimum_donation="10000"' \
--form 'expired_at="1732163756"' \
--form 'description="campaign ini merupakan bagian dari contoh"'<?php
/*Example Data to process the delimiter*/
$input = [
'title' => 'Marathon Run',
'category' => 2,
'partner_code' => 'AYB12345',
'signature_key' => '01b2eb96f63a74f46ccc2431952b39b6704dce330ad611d9ede62e70c27a954e696a503941ae4cbf0262686825cd004a1afa624d3fe6a1513910dc2b5cd4b81e',
//etc
];
$file['campaign_image'] = [
'filename' => "image.jpg",
'type' => "jpg",
'content' => utf8_decode($filepath)
];
$file['campaign_banner'] = [
'filename' => "banner.jpg",
'type' => "jpg",
'content' => utf8_decode($filepath)
];
$delimiter = '----WebKitFormBoundary'.uniqid();
$data = $this->create_post($delimiter, $input, $file);
/*end of example data*/
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => {base_url}'/api/v1/partner/campaign'tml",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer 88A4B7FEADD1667B',
'Content-Type: multipart/form-data; boundary=' . $delimiter,
'Content-Length: ' . strlen($data)
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
/*Function*/
function create_post($delimiter, $postFields, $fileFields = array()){
// form field separator
$eol = "\r\n";
$data = '';
// populate normal fields first (simpler)
foreach ($postFields as $name => $content) {
$data .= "--$delimiter" . $eol;
$data .= 'Content-Disposition: form-data; name="' . $name . '"';
$data .= $eol.$eol; // note: double endline
$data .= $content;
$data .= $eol;
}
// populate file fields
foreach ($fileFields as $name => $file) {
$data .= "--$delimiter" . $eol;
// fallback on var name for filename
if (!array_key_exists('filename', $file))
{
$file['filename'] = $name;
}
// "filename" attribute is not essential; server-side scripts may use it
$data .= 'Content-Disposition: form-data; name="' . $name . '";' .
' filename="' . $file['filename'] . '"' . $eol;
// this is, again, informative only; good practice to include though
$data .= 'Content-Type: ' . $file['type'] . $eol;
// this endline must be here to indicate end of headers
$data .= $eol;
// the file itself (note: there's no encoding of any kind)
if (is_resource($file['content'])){
// rewind pointer
rewind($file['content']);
// read all data from pointer
while(!feof($file['content'])) {
$data .= fgets($file['content']);
}
$data .= $eol;
}else {
// check if we are loading a file from full path
if (strpos($file['content'], '@') === 0){
$file_path = substr($file['content'], 1);
$fh = fopen(realpath($file_path), 'rb');
if ($fh) {
while (!feof($fh)) {
$data .= fgets($fh);
}
$data .= $eol;
fclose($fh);
}
}else {
// use data as provided
$data .= $file['content'] . $eol;
}
}
}
// last delimiter
$data .= "--" . $delimiter . "--$eol";
return $data;
}package main
import (
"fmt"
"bytes"
"mime/multipart"
"os"
"path/filepath"
"io"
"net/http"
"io/ioutil"
)
func main() {
url := {base_url}"/api/v1/partner/campaign"
method := "POST"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
_ = writer.WriteField("title", "Marathon Run")
_ = writer.WriteField("category", "3")
_ = writer.WriteField("partner_code", "AYB12345")
_ = writer.WriteField("signature_key", "01b2eb96f63a74f46ccc2431952b39b6704dce330ad611d9ede62e70c27a954e696a503941ae4cbf0262686825cd004a1afa624d3fe6a1513910dc2b5cd4b81e")
_ = writer.WriteField("target_donation", "2000000")
_ = writer.WriteField("minimum_donation", "10000")
_ = writer.WriteField("expired_at", "1732163756")
file, errFile7 := os.Open("/Downloads/illustrator/image.jpg")
defer file.Close()
part7,
errFile7 := writer.CreateFormFile("campaign_image",filepath.Base("/Downloads/illustrator/image.jpg"))
_, errFile7 = io.Copy(part7, file)
if errFile7 != nil {
fmt.Println(errFile7)
return
}
file, errFile8 := os.Open("/Downloads/illustrator/banner.jpg")
defer file.Close()
part8,
errFile8 := writer.CreateFormFile("campaign_banner",filepath.Base("/Downloads/illustrator/banner.jpg"))
_, errFile8 = io.Copy(part8, file)
if errFile8 != nil {
fmt.Println(errFile8)
return
}
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "Bearer 88A4B7FEADD1667B")
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}Last updated