Skip to main content

Notifications

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

I have a Error IN JSON Port and Send it to API

Posted on by 65
Hi ,,,
I have a question IN JSON Port and Send it to API.

I have these variables:-
SecretKey := 'Gj5nS9wyYHRadaVffz5VKB4v4wlVWyPhcJvrTD4NHtOsmn4WEhkrnJW7zWOmQD7qUDLVWZqNROnJk8ElUkfT38xh/EJq5G6ISXrLBHLNsIPftpZnzpinZWhURwJ/iZVCxvxWI89aqV5fvPThtItXW5iF58GCqaaJWv4ZKTNnk0cF+0vWfrJqS/6yBvnz6CrBNnRxo2AMgRzrvLgx9buDOtlT6wCwzq7VIK/Q8YlxyQPUAr121WPErq7TCHJNikF/ylAfcU1/ac9K9GQyj7AfFQ==';
ClientID := 'a6b5cfcc-ce28-41c4-a1bf-91c8cd347c6b';
EncryptedXMLBase64 := 'PEludm9pY2UgeG1sbnM9InVybjpvYXNpczpuYW1lczpzcGVjaWZpY2F0aW9uOnVibDpzY2hlbWE6eHNkOkludm9pY2UtMiIgeG1sbnM6Y2JjPSJ1cm46b2FzaXM6bmFtZXM6c3BlY2lmaWNhdGlvbjp1Ymw6c2NoZW1hOnhzZDpDb21tb25CYXNpY0NvbXBvbmVudHMtMiIgeG1sbnM6ZXh0PSJ1cm46b2FzaXM6bmFtZXM6c3BlY2lmaWNhdGlvbjp1Ymw6c2NoZW1hOnhzZDpDb21tb25FeHRlbnNpb25Db21wb25lbnRzLTIiIHhtbG5zOmNhYz0idXJuOm9hc2lzOm5hbWVzOnNwZWNpZmljYXRpb246dWJsOnNjaGVtYTp4c2Q6Q29tbW9uQWdncmVnYXRlQ29tcG9uZW50cy0yIj4NCiAgPGNiYzpQcm9maWxlSUQ+cmVwb3J0aW5nOjEuMDwvY2JjOlByb2ZpbGVJRD4NCiAgPGNiYzpJRD5TVERJTlYyMzU2PC9jYmM6SUQ+DQogIDxjYmM6VVVJRD42MjQ8L2NiYzpVVUlEPg0KICA8Y2JjOklzc3VlRGF0ZT4yMDIyLTA0LTEyPC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A1Ij5TPC9jYmM6SUQ+DQogICAgICAgICAgPGNiYzpQZXJjZW50PjY8L2NiYzpQZXJjZW50Pg0KICAgICAgICAgIDxjYWM6VGF4U2NoZW1lPg0KICAgICAgICAgICAgPGNiYzpJRCBzY2hlbWVBZ2VuY3lJRD0iNiIgc2NoZW1lSUQ9IlVOL0VDRSA1MTUzIj5WQVQ8L2NiYzpJRD4NCiAgICAgICAgICA8L2NhYzpUYXhTY2hlbWU+DQogICAgICAgIDwvY2FjOlRheENhdGVnb3J5Pg0KICAgICAgPC9jYWM6VGF4U3VidG90YWw+DQogICAgPC9jYWM6VGF4VG90YWw+DQogICAgPGNhYzpJdGVtPg0KICAgICAgPGNiYzpOYW1lPk11bHRpLUNvcmUgUHJvY2Vzc29yPC9jYmM6TmFtZT4NCiAgICA8L2NhYzpJdGVtPg0KICAgIDxjYWM6UHJpY2U+DQogICAgICA8Y2JjOlByaWNlQW1vdW50IGN1cnJlbmN5SUQ9IkpPIj4yLjUwMDAwPC9jYmM6UHJpY2VBbW91bnQ+DQogICAgICA8Y2FjOkFsbG93YW5jZUNoYXJnZT4NCiAgICAgICAgPGNiYzpDaGFyZ2VJbmRpY2F0b3I+ZmFsc2U8L2NiYzpDaGFyZ2VJbmRpY2F0b3I+DQogICAgICAgIDxjYmM6QWxsb3dhbmNlQ2hhcmdlUmVhc29uPkRJU0NPVU5UPC9jYmM6QWxsb3dhbmNlQ2hhcmdlUmVhc29uPg0KICAgICAgICA8Y2JjOkFtb3VudCBjdXJyZW5jeUlEPSJKTyI+MC4wMDAwMDwvY2JjOkFtb3VudD4NCiAgICAgIDwvY2FjOkFsbG93YW5jZUNoYXJnZT4NCiAgICA8L2NhYzpQcmljZT4NCiAgPC9jYWM6SW52b2ljZUxpbmU+DQo8L0ludm9pY2U+';
//**********************************************************************************************************************************************************************************************************************************************************
procedure SendInvoiceWithAuthentication(EncryptedXMLBase64: Text; ClientID: Text; SecretKey: Text) ResponseText: Text
    var
        HttpClient: HttpClient;
        HttpRequestMessage: HttpRequestMessage;
        HttpResponseMessage: HttpResponseMessage;
        RequestHeaders: HttpHeaders;
        JsonToken: JsonToken;
        JsonObject: JsonObject;
        BodyText: Text;
        BaseUrl: Text;
        ResponseContent: Text;
        JsonContent: Text;
        ContentHeaders: HttpHeaders;
    begin
        BaseUrl := 'https://backend.jofotara.gov.jo/core/invoices/';
        HttpRequestMessage.SetRequestUri(BaseUrl);
        HttpRequestMessage.Method('Get');
 
       
        HttpRequestMessage.GetHeaders(RequestHeaders);
        RequestHeaders.Add('Client-Id', ClientID);
        RequestHeaders.Add('Secret-Key', SecretKey);
 
       
        JsonObject.Add('invoice', EncryptedXMLBase64);
        JsonObject.WriteTo(BodyText);
 
       
        JsonContent := BodyText;
        HttpRequestMessage.Content().WriteFrom(JsonContent);
 
       
        HttpRequestMessage.Content().GetHeaders(ContentHeaders);
        ContentHeaders.Remove('Content-Type');
        ContentHeaders.Add('Content-Type', 'application/json');
 
       
        if HttpClient.Send(HttpRequestMessage, HttpResponseMessage) then begin
            HttpResponseMessage.Content.ReadAs(ResponseContent);
            if HttpResponseMessage.IsSuccessStatusCode then begin
               
                Message('Success: %1', ResponseContent);
            end else begin
               
                Message('Error: %1', ResponseContent);
            end;
        end else begin
            Message('Failed to send request.');
        end;
    end;
//*******************************************************************************************************************************************************************
What the value of the BodyText variable is supposed to be ØŸ
 
It gives me the error in the image : 
Failed to send request.
 
 
How do I make the code work?
 
 
  • Suggested answer
    Shrey Chauhan Profile Picture
    Shrey Chauhan 288 on at
    I have a Error IN JSON Port and Send it to API
    Hello,

    I think the error is causing due to the variable EncryptedXMLBase64  which you are storing in Text datatype which is not feasible because text datatype can only store upto 2048 characters and the EncryptedXMLBase64 value is something 5780 so you might have to change the DataType.

    Here's the reference code to refer :

            Content.WriteFrom('{"user_id": "' + SetupRec."user id" + '","password": "' + SetupRec."password" + '"}');
            Content.GetHeaders(contentHeaders);
            RequestMessageforToken.GetHeaders(RequestHeaderforToken);
            RequestHeaderforToken.Add('x-api-key', SetupRec."x-api-key");
            RequestMessageforToken.SetRequestUri(SetupRec."Authorization URL");
            RequestMessageforToken.Method('GET');
            if ContentHeaders.Contains('Content-Type') then ContentHeaders.Remove('Content-Type');
            ContentHeaders.Add('Content-Type', 'application/json');
            RequestMessageforToken.Content(Content);
            IsSuccessful := HttpClient.Send(RequestMessageforToken, ResponseMessage);
            if not IsSuccessful then
                Error('Status Code: %1\ Reason : %2', ResponseMessage.HttpStatusCode, ResponseMessage.ReasonPhrase)
            else begin
                ResponseMessage.Content.ReadAs(ResponseText);
                JObject.ReadFrom(ResponseText);
     
    Hope this Solution Help's.

    Thank You,
    Shrey Chauhan
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,171 Super User 2024 Season 2 on at
    I have a Error IN JSON Port and Send it to API
    Hi, hope the following can give you some hints.
     
     
    Thanks.
    ZHU
  • Rami Mazrawi Profile Picture
    Rami Mazrawi 65 on at
    I have a Error IN JSON Port and Send it to API
     
    I Never Have a Problem Connecting to the site...my problem is get to send Jason Code
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 9,456 Super User 2024 Season 2 on at
    I have a Error IN JSON Port and Send it to API
    Hi @Rami Mazrawi,
     
    Try to use TryFunction to see the problem exactly.
     
    Best regards,
    Mohamed Amine MAHMOUDI

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,151 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,993 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans