Jump to content

virap1

Clients
  • Posts

    110
  • Joined

  • Last visited

 Content Type 

Downloads

Release Notes

IPS4 Guides

IPS4 Developer Documentation

Invision Community Blog

Development Blog

Deprecation Tracker

Providers Directory

Forums

Events

Store

Gallery

Posts posted by virap1

  1. I must be missing something because I can't upload a picture along with the database record. 

    This code works as expected, but fails to add the picture to the featured image field. 

    Any ideas what I am doing wrong? Thank you.

    $zimg="https://content.invisioncic.com/e322713/pages_media/3_1.jpg";
    $image = array();
    $image['article']=file_get_contents($zimg);
    
    $fields = array();
    $fields['18']="title test";
    $fields['19']="desc test";
    $fields['image']=$image;
    
    $data = array(
    	"title" => "title test1",
    	"content" => "content test1",
        "status" => "published", // Or "draft" 
    	"category" => 19,
    	"author" => 191972,
    	"fields" => $fields,
    );
    
          $communityUrl = 'https://www.communityUrl.com/';
          $apiKey = 'apiKey';
    
          $curl = curl_init( $communityUrl . 'api/cms/records/7' );
    	  
          curl_setopt_array( $curl, array(
              CURLOPT_RETURNTRANSFER	=> TRUE,
              CURLOPT_HTTPAUTH	=> CURLAUTH_BASIC,
              CURLOPT_USERPWD		=> "{$apiKey}:",
              CURLOPT_USERAGENT		=> "MyUserAgent/1.0",
    		  CURLOPT_POST	=> 1,
    		  CURLOPT_POSTFIELDS => http_build_query($data),
    		
          ) );
         
    	 $response = curl_exec( $curl );

     

  2. Sound, thank you but I am not sure I understood. 

    49 minutes ago, Nathan Explosion said:

     

    What is the full code of the block? Where is the block placed in Pages? etc.

     

    @Nathan Explosion Here is the full code where cat_id should be the current article (database record) category id

    {{if request.app == 'cms' }}
    
    	{block="articles_related_articles_{$cat_id}"}
    {{endif}}

     

  3. I have database articles with categories.

    I created a block that needs to be obtain the current category id for a given database record being displayed.

    I tried this and number of other things but still unable to get the category id. 

    {{$cat_id=$category->database_id;}}
    

    Does anyone know how to do it? Thanks.

     

  4. @opentype thank you. You were correct, the syntax in the guide still works and I was implementing it in a wrong way.

    The problem I have now is that the ID variable is the topic id, how can I change it so I get the forum id instead.

    so the $id here {block="article_{$id}"} should be the forum id.

    {{if request.app == 'forums' && request.module == 'forums'}}
    	{{$id = \IPS\Request::i()->id;}}
    	{block="article_{$id}"}
    {{endif}}

     

  5. 4 hours ago, Marc Stridgen said:

    If you want this in the immediate term, then opentype probably has your best solutions there. As already mentioned, we do have plans for the pages application, but its not something you are going to see quickly

    Yes, i as basically forced to pay to adopt opentype's solution because my paid invision plan or the upgraded creator pro include no normal presentation solutions at all.

  6. Thank you @Daniel F. The problem is no matter how I try I can't get it to work.

    Setting it directly through title=> "test title" or through the $fields array does not work

    $fields['18']="title test";
    $fields['title']="title z";
    $fields['content']="content z";
    
    $data = array(
    	"title" => "title test1",
    	"content" => "content test1",
        "status" => "published", // Or "draft" 
    	"category" => 19,
    	"author" => 191972,
    	"fields" => $fields,
    );

     

  7. Hello. I hope someone can help me to understand how to include a title while trying to submit a database entry using rest api.

    At the moment this code given an error message saying "errorMessage": "TITLE_CONTENT_REQUIRED"

    Thank you very much.

     

    $fields[18]="title test";
    
    $data = array(
        "status" => "published", // Or "draft"
    "category" => 19,
    "author" => 191972,
    "fields" => $fields,
    );
    
          $communityUrl = 'https://www.mydomain.com/';
          $apiKey = 'my key';
    
          $curl = curl_init( $communityUrl . 'api/cms/records/7' );
     
          curl_setopt_array( $curl, array(
              CURLOPT_RETURNTRANSFER => TRUE,
              CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
              CURLOPT_USERPWD => "{$apiKey}:",
              CURLOPT_USERAGENT => "MyUserAgent/1.0",
     CURLOPT_POST => 1,
     CURLOPT_POSTFIELDS => http_build_query($data),
    
          ) );
         
    $response = curl_exec( $curl );

     

  8. So tried to see if I can use the Rest api to get the blog records and move them to the database, but I am getting "401 Unauthorized" error saying

    "errorCode": "3S290\/9",

    "errorMessage": "INVALID_ACCESS_TOKEN"

    Here is the base php code

    <?php
    
    // IPB REST API settings
    $api_url = 'https://your-forum-url.com/api/rest/';
    $api_key = 'your-api-key';
    
    // Set up the API request
    $request_url = $api_url . 'blog/posts?sortField=date&sortOrder=asc&limit=1';
    $request_headers = [
        'Authorization: Bearer ' . $api_key,
        'Content-Type: application/json',
    ];
    
    // Send the API request
    $ch = curl_init($request_url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    
    // Check for errors
    if (curl_errno($ch)) {
        echo 'Error: ' . curl_error($ch);
    } else {
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($http_code !== 200) {
            echo 'Error: API returned HTTP code ' . $http_code;
        } else {
            // Parse the API response
            $posts = json_decode($response, true);
    
            // Display the oldest post data
            $oldest_post = $posts['results'][0];
            echo '<h1>' . $oldest_post['title'] . '</h1>';
            echo '<p>' . $oldest_post['content'] . '</p>';
        }
    }
    
    // Clean up
    curl_close($ch);

     

×
×
  • Create New...