We help IT Professionals succeed at work.
Get Started

API help how to send one per line per the api documents

austinfx
austinfx asked
on
192 Views
Last Modified: 2015-04-22
Hello I am trying to submit URLs to an API.
Their API states:
Links String[] Yes Uploaded to the POSTs Request Body. Every link must be on a new line. Minimum of 10 links without BatchID.
Here is the API Link: API DOCS

When I submit to the API it seems that only the first url is actually making it through.

Here is my code:
  public function linklicious_upload_links($key)
    {
        if ($key == LINKLICIOUS_CRON_KEY)
        {
            $links = Linklicious::whereStatus(false)->get(['url'])->toArray();

            if (!empty($links))
            {
                $links = implode('\n', array_flatten($links));
               //  dd(@$links);

                $batchId = "9b1288b2-08d0-4753-85bb-TEST";
                $batchName = "test";

                $url = LINKLICIOUS_API_UPLOAD_LINKS . "?AppId=" . LINKLICIOUS_APP_ID . "&ApiKey=" . LINKLICIOUS_API_KEY . "&LinksPerDay=" . LINKLICIOUS_LINKS_PER_DAY . "&BatchName=" . $batchName . "&BatchId=". $batchId;
                $params = array('http' => array('method' => 'POST', 'content' => $links));
                $ctx = @stream_context_create($params);
                $fp = @fopen($url, 'rb', false, $ctx);
                $response = @stream_get_contents($fp);

                Log::info("Linklicious : Upload links triggered...");
                Log::info("Response : " . $response);
            } else
                Log::info("Linklicious : No links available to upload...");
        } else
        {
            Log::info("Linklicious : Invalid key...");
        }
    }

Open in new window


so I seem to be doing something wrong. Any ideas?
Comment
Watch Question
Top Expert 2015
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE