Function :ok.body/1 is undefined (module :ok is not available)

Why do I get this error:

function :ok.body/1 is undefined (module :ok is not available)

below is my code:

    def helloworld(conn, %{"url" => url}) do
           conn
           HTTPoison.start()
           response = HTTPoison.get(url)
          {:ok, response} = Poison.decode!(response.body)
           render(conn, "helloworld.html", response: response)
  end

I got it upon {:ok, response} = Poison.decode!(response.body)

I believe the response type of the function HTTPoison.get(url) is {:ok, response}. Try this:

{:ok, response} = HTTPoison.get(url)
1 Like

HTTPoison.get/1 returns {:ok, response} | {:error, reason}.

when you try response.body elixir assumes body is a function, and uses the first element of the return tuple (in this case :ok) as a module name.

On a similar note you probably also want to do response = Poison.decode!(...) or {:ok, response} = Poison.decode(...) (Note the ! point usually mean it returns just the reply or throws an exception/error.

It worked! thank you so much. However I get an incomplete body.

The body should be:

{
  "Table": [
    {
      "Courier": "AIR 21",
      "ARStatus": "FOR APPROVAL",
      "DeliverDate": "06/13/2018",
      "Department": "ADMIN",
      "ReferenceNumber": "A_D2MS000000106",
      "AirWayBillNo": "AAWB000000031",
      "DeliveryFrom": "ARNEL.BALILI",
      "DeliverTo": "SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE",
      "Address": "Delivery AddressDelivery AddressDelivery AddressDelivery AddressDelivery AddressDelivery AddressDelivery AddressDelivery AddressDelivery AddressDelivery AddressDelivery AddressDelivery Address",
      "StreetNo": "HOUSE/BLDG/STREET #HOUSE/BLDG/STREET #HOUSE/BLDG/STREET #HOUSE/BLDG/STREET #HOUSE/BLDG/STREET #HOUSE/BLDG/STREET #HOUSE/BLDG/STREET #HOUSE/BLDG/STREET",
      "Locality": "BARANGAY/LOCALITYBARANGAY/LOCA",
      "City": "PILAR/NANANGDUAN",
      "Province": "ABRA",
      "HomePhone": "",
      "Mobile": "",
      "EmailAddress": "emailaddress",
      "Instruction": "",
      "Contents": "STATEMENT OF ACCOUNT (SOA)",
      "DocumentType": "POUCH-MEDIUM",
      "PackageSize": "MEDIUM",
      "Insured": "          ",
      "EstimateAmount": "0",
      "Lenght": "32.00",
      "Height": "1.00",
      "Width": "25.50",
      "Weight": "2.00",
      "Remarks": "FOR AIR 21 DELIVERY",
      "TransmittalSlipStatus": "RECEIVED BY ADMIN",
      "DelivertoCompany": "CompanyCompanyCompanyCompanyCompanyCompanyCompanyCompanyCompanyCompanyCompanyCompany",
      "OldReferenceNumber": "",
      "CostCode": "EXECUTIVE OFFICES - EXECUTIVE OFFICES",
      "ReceivedByAdminDate": "06/13/2018",
      "ReceivedByAdminBy": "",
      "ReleasedToCouierDate": "",
      "ReleasedToCouierTo": "",
      "DeliveryReferenceNumber": "",
      "DeliveryStatus": "",
      "StatusDate": "1900-01-01T00:00:00",
      "DeliverToAccount": "",
      "DeliveryRemarks": "",
      "DeliveryCategory": "OTD",
      "DocumentOrigin": "MNL",
      "ZipCode": "0"
    }
  ]
}

but I get upon Poison.decode is this:

%{"Table" => [%{"OldReferenceNumber" => "", "DeliveryCategory" => "OTD", "City" => "PILAR/NANANGDUAN", "EstimateAmount" => "0", "Height" => "1.00", "DeliverToAccount" => "", "PackageSize" => "MEDIUM", "ReleasedToCouierDate" => "", "ReleasedToCouierTo" => "", "Province" => "ABRA", "Contents" => "STATEMENT OF ACCOUNT (SOA)", "Insured" => " ", "Lenght" => "32.00", "DelivertoCompany" => "CompanyCompanyCompanyCompanyCompanyCompanyCompanyCompanyCompanyCompanyCompanyCompany", "Courier" => "AIR 21", "Address" => "Delivery AddressDelivery AddressDelivery AddressDelivery AddressDelivery AddressDelivery AddressDelivery AddressDelivery AddressDelivery AddressDelivery AddressDelivery AddressDelivery Address", "DeliveryFrom" => "ARNEL.BALILI", "StatusDate" => "1900-01-01T00:00:00", "CostCode" => "EXECUTIVE OFFICES - EXECUTIVE OFFICES", "DeliverTo" => "SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE", "EmailAddress" => "emailaddress", "ZipCode" => "0", "DocumentOrigin" => "MNL", "Width" => "25.50", "DeliveryRemarks" => "", "Instruction" => "", "HomePhone" => "", "DocumentType" => "POUCH-MEDIUM", "TransmittalSlipStatus" => "RECEIVED BY ADMIN", "ReferenceNumber" => "A_D2MS000000106", "DeliveryReferenceNumber" => "", "ReceivedByAdminBy" => "", "AirWayBillNo" => "AAWB000000031", "Locality" => "BARANGAY/LOCALITYBARANGAY/LOCA", "DeliverDate" => "06/13/2018", "Weight" => "2.00", "ReceivedByAdminDate" => "06/13/2018", "ARStatus" => "FOR APPROVAL", "Department" => "ADMIN", "Mobile" => "", "DeliveryStatus" => "", "Remarks" => "FOR AIR 21 DELIVERY", "StreetNo" => "HOUSE/BLDG/STREET #HOUSE/BLDG/STREET #HOUSE/BLDG/STREET #HOUSE/BLDG/STREET #HOUSE/BLDG/STREET #HOUSE/BLDG/STREET #HOUSE/BLDG/STREET #HOUSE/BLDG/STREET"}]}

below is my code again:

 def helloworld(conn, %{"url" => url}) do
     conn
     HTTPoison.start()
     {:ok, response} = HTTPoison.get(url)
     response = Poison.decode!(response.body)
     render(conn, "reports1.html", response: response)
   
    end

Why do You think it is incomplete? Do You mean keys are not in the same order? Because if so… map does not preserve key’s order.

2 Likes

My bad. I thought it was incomplete. It was just out of order. I was expecting once it gets decoded it would be still in the same order.