2

I've tried to convert the following code

<?php
   // requires PHP cURL http://no.php.net/curl
   $datatopost = array (
      "supplier_id" => "1",
      "token" => "xYRPKcoakMoiRzWgKLV5TqPSdNAaZQT",
      "ci_lineitem_ids" => json_encode ( array (54553919, 54553920) ),
   );
   $ch = curl_init ("https://scm.commerceinterface.com/api/v4/mark_exported");
   curl_setopt ($ch, CURLOPT_POST, true);
   curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
   $response = curl_exec ($ch);
   if( $response ) {
      $response_json = json_decode( $response );
      if( $response_json->success == true ) {
        //Successfully marked as exported (only items which are not already marked exported
      } else {

      }
   }

to work with the HTTP client in C# by using the form url encoded content class as below in place of the $datatopost array in the PHP

FormUrlEncodedContent markExportedContent = new FormUrlEncodedContent(new[] {
    new KeyValuePair<string,string>("supplier_id",country.supplier_id),
    new KeyValuePair<string, string>("token",country.token),
    new KeyValuePair<string, string>("ci_lineitem_id", JsonConvert.SerializeObject(country.ci_lineitem_ids))
});

and then using a http client to post this to the API however i get the below response

{"reason": "Missing Parameters (ci_lineitem_ids).", "reason_code": 400, "success": false}

I assume it has something to do with the JsonConvert.SerializeObject(country.ci_lineitem_ids) from the Newtonsoft Json package I am using to convert from a array of strings to a json encoded array as it shows in the PHP code.

Anyone able to help with some ideas as to why this isn't working as expect as i'm all out of ideas at this now having tried multiple different ways to do this before this one?

cramopy
  • 3,459
  • 6
  • 28
  • 42
J. Scott
  • 23
  • 4

1 Answers1

1

Unless it's a typo, you forgot an s at the end of the third parameter in you c# code.

ci_lineitem_ids is in your php

ci_lineitem_id is in c#

Fran
  • 6,440
  • 1
  • 23
  • 35
  • Simple typos are cause for question closure. I was waiting to make sure this was the case before voting to close. – Crowcoder Oct 17 '17 at 11:05
  • I've accepted the answer as this was a typo in the code. I'll have to wait to actually test this change but no doubt it will work. – J. Scott Oct 17 '17 at 11:18