How to create purchase orders using API

Hi, I want to check how we can create purchase orders using API request, how can I implement this, I tried some methods but its not working. I am using Laravel and trying cURL.

Updated: I am currently using EPOS along with Manager io to keep records of invoices, purchase orders, sales orders, etc. However, there is no API integration between EPOS and Manager io.

In between these two platforms, I have a Laravel application where I am syncing purchase orders from EPOS. After performing some data manipulation, I want to send these purchase orders to Manager io.

I would like to know how I can implement this functionality using API. Does Manager.io accept data using an access token? If yes, could you please share the endpoint it accepts data on? Also, what are the required parameters that I need to pass?

1 Like

Please do not divert topics see FAQ - Manager Forum.

  • Do not divert or hijack topics. If your question is not closely related to another topic, create a new one. Some of our most expert contributors only read topics interesting to them. Posting your question in the wrong place might mean it is ignored by the person who can answer it.

I moved your post to this new topic.

1 Like

@Zohaib_Saeed

Share what you’ve done, and what problems you’re facing.

So that others understand what you are facing and can give advice on your problems

1 Like

Hi, @Mabaega thank you for you reply, I have updated my post for better understanding.

Yes,
Yes,
Yes,
https://{your-subdomainname}.manager.io/api2
use SwaggerEditor to see all the api paths / endpoint and try them out.

3 Likes

Hi, Thank you for your reply, I can see the end point for a GET request which is: /purchase-orders
but I can not find the end point for POST request. your help is really appreciated .
Following is my domain, can you please check and share the endpoint with me?
https://vitaplustest.manager.io/

Import your URL https://vitaplustest.manager.io/api2 here

Create a single Purchase Order Transaction and edit it to get the UUID Key.

Send a GET request with the key, you will get the Json payload format you need to create a new Purchase Order via POST or PUT Request.

1 Like

This is giving me an error:

following is my code:

Just try in swagger UI,
Then send curl to free AI assistant to generate Code.
I’m assuming that laravel is PHP

<?php
// Function to generate a new GUID
function generateGUID() {
    if (function_exists('com_create_guid')) {
        return trim(com_create_guid(), '{}');
    } else {
        return sprintf(
            '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
            mt_rand(0, 0xffff), mt_rand(0, 0xffff),
            mt_rand(0, 0xffff),
            mt_rand(0, 0x0fff) | 0x4000,
            mt_rand(0, 0x3fff) | 0x8000,
            mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
        );
    }
}

// Define variables for the API
$baseUrl = 'http://127.0.0.1:55667';
$apiPath = '/api2/purchase-order-form';
$apiKey = 'CgdBcGlUZXN0EhIJxOm3d83TuUgRvhBjwLYmeO4aEglOHwkiCH36SRGTmWDvW8sopA==';
$resourceId = '5174ef41-735e-45d3-83a8-085fde12a7e7';

// Build the GET URL
$getUrl = "$baseUrl$apiPath/$resourceId";

// Fetch the JSON template with a GET request
$ch = curl_init($getUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'accept: */*',
    "X-API-KEY: $apiKey",
]);

$response = curl_exec($ch);
if (curl_errno($ch)) {
    die('Error in GET request: ' . curl_error($ch));
}
curl_close($ch);

// Decode the JSON response
$data = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
    die('Error decoding JSON: ' . json_last_error_msg());
}

// Perform 10 POST requests
$postUrl = "$baseUrl$apiPath";
for ($i = 1; $i <= 10; $i++) {
    // Update the 'Key' field with a new GUID for each request
    $data['Key'] = generateGUID();

    // Ensure 'CustomFields' and 'CustomFields2' are objects
    $data['CustomFields'] = (object)[];
    $data['CustomFields2'] = (object)[
        'Strings' => (object)[],
        'Decimals' => (object)[],
        'Dates' => (object)[],
        'Booleans' => (object)[],
        'StringArrays' => (object)[],
    ];

    // For each line in 'Lines', ensure 'CustomFields' and 'CustomFields2' are objects
    foreach ($data['Lines'] as &$line) {
        $line['CustomFields'] = (object)[];
        $line['CustomFields2'] = (object)[
            'Strings' => (object)[],
            'Decimals' => (object)[],
            'Dates' => (object)[],
            'Booleans' => (object)[],
            'StringArrays' => (object)[],
        ];
    }
    unset($line); // Unset reference to avoid side effects

    // Make a POST request
    $ch = curl_init($postUrl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'accept: */*',
        "X-API-KEY: $apiKey",
        'Content-Type: application/json',
    ]);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // Encode JSON correctly

    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    // Log success or failure
    if (curl_errno($ch)) {
        echo "Request #$i failed: " . curl_error($ch) . "\n";
    } elseif ($httpCode >= 200 && $httpCode < 300) {
        echo "Request #$i succeeded: HTTP $httpCode\n";
    } else {
        echo "Request #$i failed: HTTP $httpCode, Response: $response\n";
    }

    curl_close($ch);
}


Result

Request #1 succeeded: HTTP 201
Request #2 succeeded: HTTP 201
Request #3 succeeded: HTTP 201
Request #4 succeeded: HTTP 201
Request #5 succeeded: HTTP 201
Request #6 succeeded: HTTP 201
Request #7 succeeded: HTTP 201
Request #8 succeeded: HTTP 201
Request #9 succeeded: HTTP 201
Request #10 succeeded: HTTP 201
1 Like

Hi, I managed to get uuid, laravel provides built in function to get uuid, but still am facing the same issue, could you please help me with the code for just one post request instead of 10, and also am not familiar with swagger editor.

You can use any other tool you know to try it out.

`for ($i = 1; $i <= 10; $i++) {`

Change 10 to 1, this should submit 1 POST request.

1 Like

I will try it tomorrow. Thanks for keeping in touch.

Are you sure on your end it is creating purchase order on Manager? I was just testing with Postman, I can get the data and when I am trying to send send DELETE request or PUT or PATCH request using the resourcekey then It shows status OK 200 but on manager nothing is changed. please see the example below:

Its working now, Thank you very much for your help. Really Appreciated

2 Likes