Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Microsoft Navision ODATA JSON Web Service creating records with PHP

(0) ShareShare
ReportReport
Posted on by 5

I have project to create new entries in Microsoft Navision 2017 with ODATA JSON web service by PHP

I found below link and trying to use it in my scenario but getting error null

Link i have used to start

Creating new entities from PHP using the Microsoft Dynamics NAV 2016's Odata web services

my code is

<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "xxxxxx/OData/Company('Company')/ExpenseEntries");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode ([

    'Journal_Template_Name'=> 'PETTY CASH',
    'Journal_Batch_Name'=> 'WEB PETTY',
    'Line_No'=> 20000,
    'Posting_Date'=> '2020-06-23T00:00:00',
    'Document_Type'=> 'Payment',
    'Document_No'=> 'PC000040',
    'Account_Type'=> 'G/L Account',
    'Account_No'=> '522020',
    'Description'=> 'STAFF FOOD EXPENSES',
    'Debit_Amount'=> '50',
    'Credit_Amount'=> '0',
    'Shortcut_Dimension_1_Code'=> '1001',
    'Shortcut_Dimension_2_Code'=> '3002'

]));

curl_setopt($ch, CURLOPT_USERPWD, 'ABC:DCE');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Connection: Keep-Alive',
        'Accept: application/json',
        'Content-Type: application/json; charset=utf-8',
        "Accept: */*"
]);

$response = json_decode(curl_exec($ch), TRUE);

echo json_encode($response, JSON_PRETTY_PRINT);

// Close handle
curl_close($ch);

 ?>



When I enter web api in web browser and enter user and password, below xml result i am getting which might be help in advice, one entry i have created mannually in navision application. now struggling to make enrty with PHP
<?xml version="1.0" encoding="utf-8"?>
<feed xml:base="">xxxxx/.../"
    xmlns="">http://www.w3.org/2005/Atom"
    xmlns:d="">schemas.microsoft.com/.../dataservices"
    xmlns:m="">schemas.microsoft.com/.../metadata">
    <id>xxxxx/.../PettyCashWebAPI</id>
    <title type="text">PettyCashWebAPI</title>
    <updated>2020-06-23T19:39:39Z</updated>
    <link rel="self" title="PettyCashWebAPI" href="PettyCashWebAPI" />
    <entry m:etag="W/&quot;'80%3BUQAAAAJ7%2F1AARQBUAFQAWQAgAEMAQQBTAEgAAAACe%2F9XAEUAQgAgAFAARQBUAFQAWQAAAACHECcAAAAA10%3B43433144440%3B'&quot;">
        <id>xxxx/.../PettyCashWebAPI(Journal_Batch_Name='WEB PETTY',Journal_Template_Name='PETTY CASH',Line_No=10000)</id>
        <category term="NAV.PettyCashWebAPI" scheme="">schemas.microsoft.com/.../scheme" />
        <link rel="edit" title="PettyCashWebAPI" href="Company('Company')/PettyCashWebAPI(Journal_Batch_Name='WEB%20PETTY',Journal_Template_Name='PETTY%20CASH',Line_No=10000)" />
        <title />
        <updated>2020-06-23T19:39:39Z</updated>
        <author>
            <name />
        </author>
        <content type="application/xml">
            <m:properties>
                <d:Journal_Template_Name>PETTY CASH</d:Journal_Template_Name>
                <d:Journal_Batch_Name>WEB PETTY</d:Journal_Batch_Name>
                <d:Line_No m:type="Edm.Int32">10000</d:Line_No>
                <d:Posting_Date m:type="Edm.DateTime">2020-06-23T00:00:00</d:Posting_Date>
                <d:Document_Type>Payment</d:Document_Type>
                <d:Document_No>PC000039</d:Document_No>
                <d:Account_Type>G/L Account</d:Account_Type>
                <d:Account_No>441015</d:Account_No>
                <d:Description>CASH SALES (BAIZA DIFF)</d:Description>
                <d:Debit_Amount m:type="Edm.Decimal">100</d:Debit_Amount>
                <d:Credit_Amount m:type="Edm.Decimal">0</d:Credit_Amount>
                <d:Shortcut_Dimension_1_Code>1001</d:Shortcut_Dimension_1_Code>
                <d:Shortcut_Dimension_2_Code>3002</d:Shortcut_Dimension_2_Code>
                <d:ETag>80;UQAAAAJ7/1AARQBUAFQAWQAgAEMAQQBTAEgAAAACe/9XAEUAQgAgAFAARQBUAFQAWQAAAACHECcAAAAA10;43433144440;</d:ETag>
            </m:properties>
        </content>
    </entry>
</feed>
  • Suggested answer
    Marco Mels Profile Picture
    on at
    RE: Microsoft Navision ODATA JSON Web Service creating records with PHP

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

    Thanks.

  • mnaem Profile Picture
    5 on at
    RE: Microsoft Navision ODATA JSON Web Service creating records with PHP

    now getting below error

    null 

    i have echo $ch; where i am getting this
    Resource id #2

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,865 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,723 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans