Posting data to outgoing http channel

I would like to send the data to an application(where I can schedule my appointment). Is this the proper way to pass the headers?

       ![WhatsApp Image 2020-07-21 at 12.48.44 PM|690x169](upload://t7kf7G0xTUlPShaKBH3DYMUopIu.jpeg) 

I received a response : “<Response [404]>” when the service is tested using postman. Where as I could send the data to the application directly using their API.

Any help would be appreciated.

Hello @Rashmi2719,

please post your full code, rather than its screenshot, and a screenshot of your outgoing connection’s definition.

Hello @dsuch,
Here is the code of my service.


from zato.server.service import Service
from bunch import Bunch
import json
import base64
from base64 import b64encode
from json import dumps
from collections import namedtuple


class GetTourScheduleDetails(Service):
    class SimpleIO:
        input_required = ('appointment_data', 'platform_data')
        input_optional = (
            'phone_1', 'layout', 'price_ceiling', 'move_in_date', 'notes', 'first_name', 'last_name', 'email', 'start', 'token', 'id', 'platform')
        output_required = 'data'

    def load_Form_Data(self):
        data = Bunch()
        data = json.loads(self.request.raw_request)
        return data

    def get_Platform_Object(self, formData):
        # connecting to nestio platform
        if formData['platform_data']['platform'] == 'NESTIO':
            payload = {
                "appointment": {
                    "start": formData['appointment_data']['start'],
                    "tour_type": 'guided'
                },
                "client": {
                    "people": [{
                        "first_name": formData['appointment_data']['first_name'],
                        "last_name": formData['appointment_data']['last_name'],
                        "email": formData['appointment_data']['email'],
                        "phone_1": formData['appointment_data']['phone_1']
                    }],
                    "move_in_date": formData['appointment_data']['move_in_date'],
                    "layout": ["1BHK", "2BHK"],
                    "price_ceiling": formData['appointment_data']['move_in_date'],
                    "notes": formData['appointment_data']['move_in_date']
                }
            }
            return payload
        else:
            payload = {}
            return payload

    def handle(self):
         # data to be sent to schedule an appointment
        formData = self.load_Form_Data()
        self.logger.info('formData: {}'.format(formData))
        self.logger.info('formData Type: {}'.format(type(formData)))
        # Fetch connection to Nestio
        out = self.outgoing.plain_http.get('sendTourDetailsToNestio')
        # convert data format compatible to Nestio API
        request = self.get_Platform_Object(formData)
        params = {'group_id': formData['platform_data']['id']}
        # encoding the authorization username for HTTP Basic Auth
        userAndPass = b64encode(b"MYUSERNAME:").decode("ascii")
        headers = { 'Authorization' : 'Basic %s' %  userAndPass }
        # Adding logger to check request data and its type
        self.logger.info('Request: {}'.format(request))
        self.logger.info('Request Type: {}'.format(type(request)))
        # sending information to Nestio to schedule the appointment
        response = out.conn.post(self.cid, str(request), params, headers = headers)
        self.logger.info('Response: {}'.format(response))
        self.logger.info('Response Type: {}'.format(type(self.response.payload)))
        # return response to the user
        res = str(response)
        self.response.payload.data = json.dumps(res)

The outgoing channel looks like:
OutgoingDefinition

I tried with no security definition also. But I still get the response code: 500 from the External server. I am not exactly sure how to post the details to the external server.

For Instance my security definition (HTTP Basic Auth) looks like:
Name: pin_nestio.basic_auth
Username: MYUSERNAME
Realm: Nestio ping

The JSON data used:


{
  "appointment_data":{
    "first_name": "xyz",
    "last_name": "hdhdhdak",
    "email": "xyz@gmail.com",
    "phone_1": "7890000020101",
    "layout": [ "1bhk", "2bhk", "3bhk" ],
    "price_ceiling": 450.00,
    "move_in_date": "07/17/2020",
    "notes": "I would prefere to have a balcony",
    "start": "2020-07-23T09:15:00"},
 "platform_data":{
   "token": "MY AUTHORIZATION USERNAME",
   "id": GROUP_ID,
   "platform": "NESTIO"}
 }

Can you please let me know the correct procedure to post the details to the external server? Thanks in Advance

Hello @Rashmi2719 ,
Please, can you include the message that Zato shows in the output? Thanks

Hello @anielkis,

Thank you for your reply. I could solve the issue. The issue was not with authorization, it is with the data format I have been sending to the external server. It worked finally.

Hello @Rashmi2719,
Good to hear that you managed to solve it.