Skip to Content
Menu
This question has been flagged
1592 Views

I am using the below code to fetch the invoice pdf from odoo.sh instance, The result is faultcode:3 access denied. Dotnet(c#) is used.


string odooUrl = "youraccount.odoo.com:443"; // Replace with your Odoo instance URL

string db = "youraccount-staging-0000000";

string username = "username​";

string password = "password";

int invoiceId = 123; // Replace with the ID of the invoice you want to retrieve


try

{

// Create an HttpClient instance

using (HttpClient httpClient = new HttpClient())

{

// Construct the XML-RPC request

string xmlRpcRequest = $@"


execute_kw

{db}

1

{password}

sale.report_saleorder


{invoiceId}

";


// Set the content type header

httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));

httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "text/xml; charset=utf-8");


// Send the XML-RPC request to the Odoo API endpoint

HttpResponseMessage response = await httpClient.PostAsync($"{odooUrl}/xmlrpc/2/object", new StringContent(xmlRpcRequest, Encoding.UTF8, "text/xml"));


if (response.IsSuccessStatusCode)

{

// Read the response content, which should contain the PDF data

string pdfData = await response.Content.ReadAsStringAsync();


// You can now process the PDF data or save it to a file as needed

Console.WriteLine("PDF Data Length: " + pdfData.Length);

}

else

{

Console.WriteLine($"HTTP Error: {response.StatusCode}");

}

}

}

catch (Exception ex)

{

Console.WriteLine($"An error occurred: {ex.Message}");

}



Any help or solution is appreciated.



Avatar
Discard

Have you followed the hint on this page: https://www.odoo.com/documentation/16.0/de/developer/reference/external_api.html ?
I mean the part with "For Odoo Online instances (<domain>.odoo.com), users are created without a local password (as a person you are logged in via the Odoo Online authentication system, not by the instance itself).". Maybe that helps...

Author

@Parker D, Thats not giving any change.

Related Posts Replies Views Activity
1
Oct 22
4150
1
Mar 22
5017
0
Dec 16
4324
1
Sep 23
3254
1
Mar 21
5814