Features Documentation

UploadSupplierDocument

Endpoint

Overview

The "UploadSupplierDocument" endpoint is a PUT request. It is used to upload supplier documents. Detailed functionality of how to use this endpoint is explained in the Multiple Suppliers section.

The endpoint on Swagger is UpdateSupplierDoc.

Now, we are going to declare the endpoint and its models along with each accepted parameter and possible value.

📘

Request Header

Add "Authorization": "Bearer {Token}" to request header. Token of demo configuration can be found here.


Request Model

The request is a PUT request with the following parameters:

Input Parameter

Type

Description

FileUpload

HttpFile Model

FileType

integer

    • 1** for Civil Id
    • 2** for Commercial License
    • 3** for Articles of Association
    • 4** for Signature Authorization
    • 5** for Others
    • 6** for Civil Id Back
    • 7** for Instagram
  • *16** for Civil Ids Of All Owners
  • *17** for Civil Id Of Manager
  • *20** for Commercial Register
  • *21** for Bank Account Letter
  • *25** for Website
  • *26** for 3rd Parties
  • *27** for Basic regulations list (For charities only)
  • *28** for Board of Directors Agreement (For charities only)
  • *30** for National address

ExpireDate

string, optional

SupplierCode

integer

HttpFile

Input ParameterTypeDescription
FileNamestring, optional
MediaTypestring, optional
Bufferstring, optional

Response Model

Response FieldTypeDescription
IsSuccessboolean"true" or "false" indicating the status of your request.
MessagestringThe message response associated with the request done.

Sample Message

The request below is an example of the form-data object.

❗️

Accepted Files

Kindly make sure to upload the file according to the following conditions:

  • Maximum File Size: 5 MB
  • File Type is in the following formate: .jpg|.jpeg|.png|.bmp|.gif|.xls|.xlsx|.pdf|.doc|.docx

Sample Code

<?php

/* For simplicity, check the PHP Library here: https://myfatoorah.readme.io/php-library */
/* ------------------------ Configurations ---------------------------------- */
//Test
$apiURL = 'https://apitest.myfatoorah.com';
$apiKey = ''; //Test token value to be placed here: https://myfatoorah.readme.io/docs/test-token

//Live
//$apiURL = 'https://api.myfatoorah.com';
//$apiKey = ''; //Live token value to be placed here: https://myfatoorah.readme.io/docs/live-token


/* ------------------------ Call UploadSupplierDocument Endpoint ------------------- */
//Fill POST fields array, check https://myfatoorah.readme.io/docs/upload-supplier-document#request-model
$file     = ''; //file url
$contents = file_get_contents($file); //read file using upload form or any way you like

$fileName  = basename($file);
$mediaType = mime_content_type($file);
$buffer    = base64_encode($contents);

//optional set expire date
$ExpireDate = new \DateTime('now', new \DateTimeZone('Asia/Kuwait'));
$ExpireDate->modify("+365 day");

$postFields = [
    //Fill required data
    'FileUpload'   => [
        'FileName'  => $fileName,
        'MediaType' => $mediaType,
        'Buffer'    => $buffer
    ],
    'FileType'     => 2, //check FileType values in documentationFileType
    'SupplierCode' => 3,
        //Fill optional data
        //'ExpireDate'   => $ExpireDate->format('Y-m-d\TH:i:s')
];

//Call endpoint
$link = uploadSupplierDocument($apiURL, $apiKey, $postFields);

//Display the result
echo "Click on <a href='$link' target='_blank'>$link</a> to see the uploaded file.";
die;

/* ------------------------ Functions --------------------------------------- */
/*
 * Upload Supplier Document Endpoint Function 
 */

function uploadSupplierDocument($apiURL, $apiKey, $postFields) {

    $json = callAPI("$apiURL/v2/UploadSupplierDocument", $apiKey, $postFields, 'PUT');
    return $json->Message;
}

//------------------------------------------------------------------------------
/*
 * Call API Endpoint Function
 */

function callAPI($endpointURL, $apiKey, $postFields = [], $requestType = 'POST') {

    $curl = curl_init($endpointURL);
    curl_setopt_array($curl, array(
        CURLOPT_CUSTOMREQUEST  => $requestType,
        CURLOPT_POSTFIELDS     => json_encode($postFields),
        CURLOPT_HTTPHEADER     => array("Authorization: Bearer $apiKey", 'Content-Type: application/json'),
        CURLOPT_RETURNTRANSFER => true,
    ));

    $response = curl_exec($curl);
    $curlErr  = curl_error($curl);

    if ($curlErr) {
        //Curl is not working in your server
        die("Curl Error: $curlErr");
    }

    $error = handleError($response);
    if ($error) {
        die("Error: $error");
    }

    return json_decode($response);
}

//------------------------------------------------------------------------------
/*
 * Handle Endpoint Errors Function 
 */

function handleError($response) {

    $json = json_decode($response);
    if (isset($json->IsSuccess) && $json->IsSuccess == true) {
        return null;
    }

    //Check for the errors
    if (isset($json->ValidationErrors) || isset($json->FieldsErrors)) {
        $errorsObj = isset($json->ValidationErrors) ? $json->ValidationErrors : $json->FieldsErrors;
        $blogDatas = array_column($errorsObj, 'Error', 'Name');

        $error = implode(', ', array_map(function ($k, $v) {
                    return "$k: $v";
                }, array_keys($blogDatas), array_values($blogDatas)));
    } else if (isset($json->Data->ErrorMessage)) {
        $error = $json->Data->ErrorMessage;
    }

    if (empty($error)) {
        $error = (isset($json->Message)) ? $json->Message : (!empty($response) ? $response : 'API key or API URL is not correct');
    }

    return $error;
}

/* -------------------------------------------------------------------------- */