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

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?
austinfxAsked:
Who is Participating?
 
F PCommented:
OOOOOhhhhh, I see... change the quotes on your implode. You have single quotes, and need double with the \n

$links = implode('\n', array_flatten($links));

*should be*

$links = implode("\n", array_flatten($links));
0
 
F PCommented:
Did you try making your implode to use "\r\n" instead of just the "\n" ?
0
 
austinfxAuthor Commented:
BLESS YOU BROTHER!!!!!!!!!!! THAT was IT!!
0
 
austinfxAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for austinfx's comment #a40739387
Assisted answer: 500 points for Frank Pennock's comment #a40739249

for the following reason:

Thank you good sir!
0
 
F PCommented:
Very welcome! It happens all the time, and I know I've done it before...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.