AugForums.com

An Acumatica User Group

  • Free
    • Start Here
    • In-Person Gatherings
    • Power BI Workshop
    • Podcast
    • Rolodex
    • Blog
    • Forums
  • Paid
    • AugSQL
    • GI Course
    • GI Library
    • Consulting
  • Register

Acumatica REST API and PHP Curl

September 19, 2017 by Tim Rodman

I wanted a way to push data into an Acumatica REST API using PHP Curl. The challenge was staying logged in. It took some research, but this is how I did it.

This post is totally off topic, but I can’t figure out how to post code as a comment on Sergey’s blog post about working with the REST APIs in Acumatica (click here).

So, I’m posting the code here, then I’ll refer to this post in my comment on Sergey’s blog post.

But, since I’m posting it here, I guess I need to do a little more explaining.

I’m currently working on an integration that is going to make an ODBC call and push the results into Acumatica via the Acumatica REST APIs.

DISCLAIMER: Real developers and programmers will probably critique my method and find all kinds of things wrong with it, but I’m more of a “duct tape” programmer. If I can find something that works, then I’m going to try it. I don’t really care if it takes 5.643 milliseconds longer to run than a better method or if the method I used won’t hold up under the academic scrutiny of a PHD computer science research paper. Just make it work, then, if I need it to work BETTER, I’ll worry about that if (and when) I ever arrive at that problem. The IF is key here because most of the time (in my opinion), the “duct tape” holds just fine and is still in use 10 years from now. That’s why so many spreadsheets last for decades before they get replaced. Ok, that’s my disclaimer.

I asked myself what would be the quickest way to code this integration. I don’t know C# and I don’t want to spin up a Visual Studio environment on my computer. I’ve done that before and it made my computer run really slow even though I tried to uninstall everything when I was done.

I just needed a simple scripting language that could make ODBC calls and work with the Acumatica REST APIs.

That’s when I remembered that I used to use PHP way back in college when I worked on an open source project at UCLA. We used Linux, PHP, Perl, and MySQL to in-house code something we called ClassWeb and used it to run all of the Social Science class sites at UCLA.

It’s been a while, but hey, I thought I would try to dust off some of that PHP knowledge.

First, I had to get PHP working on my local IIS Windows 10 environment. Check.

Second, I had to get the ODBC calls working. Check.

Third, I had to try a test Acumatica REST API call. This one I’ve already done in Postman before thanks to these great sessions (click here, and click here). Check.

Fourth, I had to translate what I did in Postman into PHP.

This is where things got tricky.

There is a cool Code button in Postman that allows you to take the work that you’ve done in Postman and translate it into another language.

Acumatica REST API and PHP Curl

 

I decided to go with the PHP cURL option, so I selected it in the screenshot below.

Acumatica REST API and PHP Curl

 

Then I ran the code, but I got the following error:

{“message”:”You are not logged in.”}

Hmmm, what could be wrong? Let’s think about what is happening here.

There are basically three steps in my Postman logic:

  1. Login
  2. Create a Customer
  3. Logout

I could see that my error message was happening at the second step and the problem had to do with the first step not passing the session information to the second step. That’s why I was getting the “you are not logged in” error.

A little investigating (this is is when I landed on Sergey’s post), and it seemed that I needed a way to pass the cookies generated from the first step to the second step.

Some more investigating and I think I finally found the way to do it in PHP.

So here is the code. I ran it in my local environment and it seems to be working. Let’s see how long the duct tape holds 🙂

<?php

// Add Cookie Jar
$cookie_jar = tempnam(‘/tmp’,’cookie’);

// Initiate Connection
$curl = curl_init();

// Login to Acumatica REST API
curl_setopt_array($curl, array(
CURLOPT_URL => “http://localhost/Acumatica/entity/auth/login”,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => “”,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_COOKIESESSION => 1,
CURLOPT_COOKIEJAR => $cookie_jar,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => “POST”,
CURLOPT_POSTFIELDS => “{\r\n  \”name\”: \”admin\”,\r\n  \”password\”: \”mypassword\”,\r\n  \”company\”: \”Company\”\r\n}”,
CURLOPT_HTTPHEADER => array( “cache-control: no-cache”, “content-type: application/json”, “postman-token: e0a0ff40-8d46-4c5f-106b-960ad1aafba8”
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
if ($err) {
echo “cURL Error #:” . $err;
} else {
echo $response;
}

// Create Sample Customer With Acumatica REST API
curl_setopt_array($curl, array(
CURLOPT_URL => “http://localhost/Acumatica/entity/Default/6.00.001/Customer”,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => “”,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_COOKIESESSION => 1,
CURLOPT_COOKIEFILE => $cookie_jar,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => “PUT”,
CURLOPT_POSTFIELDS => “{\r\n \”CustomerID\” : {value : \”NewOne\” } ,\r\n \”CustomerName\” : {value : \”It Worked\” },\r\n}”,
CURLOPT_HTTPHEADER => array( “cache-control: no-cache”, “content-type: application/json”, “postman-token: 5248821b-91e9-5800-bd9c-b4c9775c6c5a”
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
if ($err) {
echo “cURL Error #:” . $err;
} else {
echo $response;
}

// Logout of Acumatica REST API
curl_setopt_array($curl, array(
CURLOPT_URL => “http://localhost/Acumatica/entity/auth/logout”,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => “”,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_COOKIESESSION => 1,
CURLOPT_COOKIEFILE => $cookie_jar,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => “POST”,
CURLOPT_HTTPHEADER => array( “cache-control: no-cache”, “content-type: application/json”, “postman-token: e4363994-cc86-330c-17d5-0bc9926c6fc2”
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
if ($err) {
echo “cURL Error #:” . $err;
} else {
echo $response;
}

// Close Connection
curl_close($curl);

// Remove Cookie Jar
unlink($cookie_jar) or die(“Can’t unlink $cookie_jar”);
?>

Filed Under: Miscellaneous Tagged With: Acumatica, Acumatica Blog, Acumatica Integrations, Acumatica Learning, Acumatica REST API, Acumatica Training, PHP, PHP Curl

By using this website, you agree to our Terms of Use (click here)
Building Generic Inquiries & Pivot Tables

Online Members

 No online members at the moment

Recent Blog Posts

  • EP 166: Tim uses ChatGPT and Claude to build something cool (Podcast) March 21, 2026
  • EP 165: Jake Wells – EOS Scorecard and Acumatica Dashboards (Podcast) March 12, 2026
  • EP 164: Phil Steichen – Vibe Coding your own Business Intelligence tool (Podcast) February 19, 2026
  • EP 163: Daryl Bowman – Dissecting the new Acumatica Calendar Board (Podcast) February 9, 2026
  • EP 162: Gabriel Michaud – Catching up on new cool stuff in Velixo and Excel (Podcast) February 2, 2026

Recent Forum Posts

  • Ed Dolan

    RE: Limited or no support from Acumatica?

    @jjbotes Good thoughts. We'll endeavor to find a soluti...

    By Ed Dolan , 2 days ago

  • Johan Botes

    RE: Limited or no support from Acumatica?

    The question is "when" in the business process does the...

    By Johan Botes , 2 days ago

  • Ed Dolan

    RE: Limited or no support from Acumatica?

    @jjbotes Thank you for the feedback. I will discuss wit...

    By Ed Dolan , 2 days ago

  • Johan Botes

    RE: Limited or no support from Acumatica?

    Acumatica can have positive units in stock but a negati...

    By Johan Botes , 2 days ago

  • Ed Dolan

    RE: Limited or no support from Acumatica?

    @azeigler I am concerned as well about the lack of s...

    By Ed Dolan , 2 days ago

  • Johan Botes

    RE: Limited or no support from Acumatica?

    Hi Ed - the principle is embedded in standard functiona...

    By Johan Botes , 2 days ago

  • Ed Dolan

    RE: Limited or no support from Acumatica?

    Johan, Thanks for the rely and I hope you are well. ...

    By Ed Dolan , 2 days ago

  • Albert Zeigler

    RE: Limited or no support from Acumatica?

    @edolan I see, I think the context i was looking for wa...

    By Albert Zeigler , 2 days ago

  • Johan Botes

    RE: Limited or no support from Acumatica?

    Acumatica primarily allows negative inventory for stock...

    By Johan Botes , 2 days ago

Terms of Use & Disclaimers :: Privacy Policy

Copyright © 2026 · AUG Forums, LLC. All rights reserved. This website is not owned, affiliated with, or endorsed by Acumatica, Inc.